Skip to content

Commit 1a83068

Browse files
bertwesarggitster
authored andcommitted
remote: clean-up by returning early to avoid one indentation
Signed-off-by: Bert Wesarg <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 88f8576 commit 1a83068

File tree

1 file changed

+48
-46
lines changed

1 file changed

+48
-46
lines changed

builtin/remote.c

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -263,54 +263,56 @@ static const char *abbrev_ref(const char *name, const char *prefix)
263263

264264
static int config_read_branches(const char *key, const char *value, void *cb)
265265
{
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;
286272

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);
288315

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-
}
314316
return 0;
315317
}
316318

0 commit comments

Comments
 (0)