Skip to content

Commit ceff1a1

Browse files
bertwesarggitster
authored andcommitted
remote: clean-up config callback
Some minor clean-ups in function `config_read_branches`: * remove hardcoded length in `key += 7` * call `xmemdupz` only once * use a switch to handle the configuration type and add a `BUG()` Suggested-by: Junio C Hamano <[email protected]> Signed-off-by: Bert Wesarg <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1a83068 commit ceff1a1

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

builtin/remote.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,29 +273,29 @@ static int config_read_branches(const char *key, const char *value, void *cb)
273273
if (!starts_with(key, "branch."))
274274
return 0;
275275

276-
key += 7;
277-
if (strip_suffix(key, ".remote", &key_len)) {
278-
name = xmemdupz(key, key_len);
276+
key += strlen("branch.");
277+
if (strip_suffix(key, ".remote", &key_len))
279278
type = REMOTE;
280-
} else if (strip_suffix(key, ".merge", &key_len)) {
281-
name = xmemdupz(key, key_len);
279+
else if (strip_suffix(key, ".merge", &key_len))
282280
type = MERGE;
283-
} else if (strip_suffix(key, ".rebase", &key_len)) {
284-
name = xmemdupz(key, key_len);
281+
else if (strip_suffix(key, ".rebase", &key_len))
285282
type = REBASE;
286-
} else
283+
else
287284
return 0;
285+
name = xmemdupz(key, key_len);
288286

289287
item = string_list_insert(&branch_list, name);
290288

291289
if (!item->util)
292290
item->util = xcalloc(1, sizeof(struct branch_info));
293291
info = item->util;
294-
if (type == REMOTE) {
292+
switch (type) {
293+
case REMOTE:
295294
if (info->remote_name)
296295
warning(_("more than one %s"), orig_key);
297296
info->remote_name = xstrdup(value);
298-
} else if (type == MERGE) {
297+
break;
298+
case MERGE: {
299299
char *space = strchr(value, ' ');
300300
value = abbrev_branch(value);
301301
while (space) {
@@ -306,12 +306,18 @@ static int config_read_branches(const char *key, const char *value, void *cb)
306306
space = strchr(value, ' ');
307307
}
308308
string_list_append(&info->merge, xstrdup(value));
309-
} else
309+
break;
310+
}
311+
case REBASE:
310312
/*
311313
* Consider invalid values as false and check the
312314
* truth value with >= REBASE_TRUE.
313315
*/
314316
info->rebase = rebase_parse_value(value);
317+
break;
318+
default:
319+
BUG("unexpected type=%d", type);
320+
}
315321

316322
return 0;
317323
}

0 commit comments

Comments
 (0)