Skip to content

Commit 2e376b3

Browse files
mhaggergitster
authored andcommitted
expire_reflog(): return early if the reference has no reflog
There is very little cleanup needed if the reference has no reflog. If we move the initialization of log_file down a bit, there's even less. So instead of jumping to the cleanup code at the end of the function, just do the cleanup and return inline. Signed-off-by: Michael Haggerty <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 524127a commit 2e376b3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

builtin/reflog.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,11 @@ static int expire_reflog(const char *refname, const unsigned char *sha1,
368368
lock = lock_any_ref_for_update(refname, sha1, 0, NULL);
369369
if (!lock)
370370
return error("cannot lock ref '%s'", refname);
371+
if (!reflog_exists(refname)) {
372+
unlock_ref(lock);
373+
return 0;
374+
}
371375
log_file = git_pathdup("logs/%s", refname);
372-
if (!reflog_exists(refname))
373-
goto finish;
374376
if (!cmd->dry_run) {
375377
newlog_path = git_pathdup("logs/%s.lock", refname);
376378
cb.newlog = fopen(newlog_path, "w");
@@ -419,7 +421,7 @@ static int expire_reflog(const char *refname, const unsigned char *sha1,
419421
clear_commit_marks(tip_commit, REACHABLE);
420422
}
421423
}
422-
finish:
424+
423425
if (cb.newlog) {
424426
if (fclose(cb.newlog)) {
425427
status |= error("%s: %s", strerror(errno),

0 commit comments

Comments
 (0)