Skip to content

Commit 118fd1a

Browse files
pks-tgitster
authored andcommitted
branch: stop modifying log_all_ref_updates variable
In "branch.c" we modify the global `log_all_ref_updates` variable to force creation of a reflog entry. Modifying global state like this is discouraged, as it may have all kinds of consequences in other places of our codebase. Stop modifying the variable and pass the `REF_FORCE_CREATE_REFLOG` flag instead. Setting this flag has a stronger meaning than setting the config to `LOG_REFS_NORMAL`: - `LOG_REFS_NORMAL` will ask us to only create reflog entries for preexisting reflogs or branches, remote refs, note refs and HEAD. - `REF_FORCE_CREATE_REFLOG` will unconditionally create a reflog and is thus equivalent to `LOG_REFS_ALWAYS`. But as we are in `create_branch()` and thus do not have to worry about arbitrary references, but only about branches, `LOG_REFS_NORMAL` and `LOG_REFS_ALWAYS` are indeed equivalent. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f1d3d07 commit 118fd1a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

branch.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ void create_branch(struct repository *r,
601601
int forcing = 0;
602602
struct ref_transaction *transaction;
603603
struct strbuf err = STRBUF_INIT;
604+
int flags = 0;
604605
char *msg;
605606

606607
if (track == BRANCH_TRACK_OVERRIDE)
@@ -619,7 +620,7 @@ void create_branch(struct repository *r,
619620
goto cleanup;
620621

621622
if (reflog)
622-
log_all_ref_updates = LOG_REFS_NORMAL;
623+
flags |= REF_FORCE_CREATE_REFLOG;
623624

624625
if (forcing)
625626
msg = xstrfmt("branch: Reset to %s", start_name);
@@ -630,7 +631,7 @@ void create_branch(struct repository *r,
630631
if (!transaction ||
631632
ref_transaction_update(transaction, ref.buf,
632633
&oid, forcing ? NULL : null_oid(),
633-
NULL, NULL, 0, msg, &err) ||
634+
NULL, NULL, flags, msg, &err) ||
634635
ref_transaction_commit(transaction, &err))
635636
die("%s", err.buf);
636637
ref_transaction_free(transaction);

0 commit comments

Comments
 (0)