@matheusbsbs / matheus-bagliano / commits / ceff1a1308
Fork 0

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 <gitster@pobox.com> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Bert Wesarg committed Jan 27, 2020 at 08:04 UTC ceff1a13084bba74b607d738c6c467365aa6a5f7
1 file changed +17 -11
builtin/remote.c
+17 -11
@@ -273,29 +273,29 @@ static int config_read_branches(const char *key, const char *value, void *cb)
273 if (!starts_with(key, "branch."))
274 return 0;
275
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))
278 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))
280 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))
282 type = REBASE;
286 - } else
283 + else
284 return 0;
285 + name = xmemdupz(key, key_len);
286
287 item = string_list_insert(&branch_list, name);
288
289 if (!item->util)
290 item->util = xcalloc(1, sizeof(struct branch_info));
291 info = item->util;
294 - if (type == REMOTE) {
292 + switch (type) {
293 + case REMOTE:
294 if (info->remote_name)
295 warning(_("more than one %s"), orig_key);
296 info->remote_name = xstrdup(value);
298 - } else if (type == MERGE) {
297 + break;
298 + case MERGE: {
299 char *space = strchr(value, ' ');
300 value = abbrev_branch(value);
301 while (space) {
@@ -306,12 +306,18 @@ static int config_read_branches(const char *key, const char *value, void *cb)
306 space = strchr(value, ' ');
307 }
308 string_list_append(&info->merge, xstrdup(value));
309 - } else
309 + break;
310 + }
311 + case REBASE:
312 /*
313 * Consider invalid values as false and check the
314 * truth value with >= REBASE_TRUE.
315 */
316 info->rebase = rebase_parse_value(value);
317 + break;
318 + default:
319 + BUG("unexpected type=%d", type);
320 + }
321
322 return 0;
323 }