Skip to content

Commit be5c3a3

Browse files
ferdinandybgitster
authored andcommitted
set-head: add new variable for readability
Instead of calling get_main_ref_store(the_repository) multiple times, call it once and store in a new refs variable. Although this change probably offers some performance benefits, the main purpose is to shorten the line lengths of function calls using this variable for better readability. Signed-off-by: Bence Ferdinandy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 57cff1a commit be5c3a3

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

builtin/remote.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,7 @@ static int set_head(int argc, const char **argv, const char *prefix)
14041404
int i, opt_a = 0, opt_d = 0, result = 0;
14051405
struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
14061406
char *head_name = NULL;
1407+
struct ref_store *refs = get_main_ref_store(the_repository);
14071408

14081409
struct option options[] = {
14091410
OPT_BOOL('a', "auto", &opt_a,
@@ -1434,17 +1435,17 @@ static int set_head(int argc, const char **argv, const char *prefix)
14341435
head_name = xstrdup(states.heads.items[0].string);
14351436
free_remote_ref_states(&states);
14361437
} else if (opt_d && !opt_a && argc == 1) {
1437-
if (refs_delete_ref(get_main_ref_store(the_repository), NULL, buf.buf, NULL, REF_NO_DEREF))
1438+
if (refs_delete_ref(refs, NULL, buf.buf, NULL, REF_NO_DEREF))
14381439
result |= error(_("Could not delete %s"), buf.buf);
14391440
} else
14401441
usage_with_options(builtin_remote_sethead_usage, options);
14411442

14421443
if (head_name) {
14431444
strbuf_addf(&buf2, "refs/remotes/%s/%s", argv[0], head_name);
14441445
/* make sure it's valid */
1445-
if (!refs_ref_exists(get_main_ref_store(the_repository), buf2.buf))
1446+
if (!refs_ref_exists(refs, buf2.buf))
14461447
result |= error(_("Not a valid ref: %s"), buf2.buf);
1447-
else if (refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, "remote set-head", NULL))
1448+
else if (refs_update_symref(refs, buf.buf, buf2.buf, "remote set-head", NULL))
14481449
result |= error(_("Could not setup %s"), buf.buf);
14491450
else if (opt_a)
14501451
printf("%s/HEAD set to %s\n", argv[0], head_name);

0 commit comments

Comments
 (0)