@matheusbsbs / matheus-bagliano / commits / 1a83068c26
Fork 0

remote: clean-up by returning early to avoid one indentation

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 1a83068c26206d2b45718e0896955eb61bef8353
1 file changed +48 -46
builtin/remote.c
+48 -46
@@ -263,54 +263,56 @@ static const char *abbrev_ref(const char *name, const char *prefix)
263
264 static int config_read_branches(const char *key, const char *value, void *cb)
265 {
266 - if (starts_with(key, "branch.")) {
267 - const char *orig_key = key;
268 - char *name;
269 - struct string_list_item *item;
270 - struct branch_info *info;
271 - enum { REMOTE, MERGE, REBASE } type;
272 - size_t key_len;
273 -
274 - key += 7;
275 - if (strip_suffix(key, ".remote", &key_len)) {
276 - name = xmemdupz(key, key_len);
277 - type = REMOTE;
278 - } else if (strip_suffix(key, ".merge", &key_len)) {
279 - name = xmemdupz(key, key_len);
280 - type = MERGE;
281 - } else if (strip_suffix(key, ".rebase", &key_len)) {
282 - name = xmemdupz(key, key_len);
283 - type = REBASE;
284 - } else
285 - return 0;
266 + const char *orig_key = key;
267 + char *name;
268 + struct string_list_item *item;
269 + struct branch_info *info;
270 + enum { REMOTE, MERGE, REBASE } type;
271 + size_t key_len;
272
287 - item = string_list_insert(&branch_list, name);
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);
279 + type = REMOTE;
280 + } else if (strip_suffix(key, ".merge", &key_len)) {
281 + name = xmemdupz(key, key_len);
282 + type = MERGE;
283 + } else if (strip_suffix(key, ".rebase", &key_len)) {
284 + name = xmemdupz(key, key_len);
285 + type = REBASE;
286 + } else
287 + return 0;
288 +
289 + item = string_list_insert(&branch_list, name);
290 +
291 + if (!item->util)
292 + item->util = xcalloc(1, sizeof(struct branch_info));
293 + info = item->util;
294 + if (type == REMOTE) {
295 + if (info->remote_name)
296 + warning(_("more than one %s"), orig_key);
297 + info->remote_name = xstrdup(value);
298 + } else if (type == MERGE) {
299 + char *space = strchr(value, ' ');
300 + value = abbrev_branch(value);
301 + while (space) {
302 + char *merge;
303 + merge = xstrndup(value, space - value);
304 + string_list_append(&info->merge, merge);
305 + value = abbrev_branch(space + 1);
306 + space = strchr(value, ' ');
307 + }
308 + string_list_append(&info->merge, xstrdup(value));
309 + } else
310 + /*
311 + * Consider invalid values as false and check the
312 + * truth value with >= REBASE_TRUE.
313 + */
314 + info->rebase = rebase_parse_value(value);
315
289 - if (!item->util)
290 - item->util = xcalloc(1, sizeof(struct branch_info));
291 - info = item->util;
292 - if (type == REMOTE) {
293 - if (info->remote_name)
294 - warning(_("more than one %s"), orig_key);
295 - info->remote_name = xstrdup(value);
296 - } else if (type == MERGE) {
297 - char *space = strchr(value, ' ');
298 - value = abbrev_branch(value);
299 - while (space) {
300 - char *merge;
301 - merge = xstrndup(value, space - value);
302 - string_list_append(&info->merge, merge);
303 - value = abbrev_branch(space + 1);
304 - space = strchr(value, ' ');
305 - }
306 - string_list_append(&info->merge, xstrdup(value));
307 - } else
308 - /*
309 - * Consider invalid values as false and check the
310 - * truth value with >= REBASE_TRUE.
311 - */
312 - info->rebase = rebase_parse_value(value);
313 - }
316 return 0;
317 }
318