Skip to content

Commit

Permalink
expire_reflog(): return early if the reference has no reflog
Browse files Browse the repository at this point in the history
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 <mhagger@alum.mit.edu>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Michael Haggerty authored and Junio C Hamano committed Dec 12, 2014
1 parent 524127a commit 2e376b3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions builtin/reflog.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,11 @@ static int expire_reflog(const char *refname, const unsigned char *sha1,
lock = lock_any_ref_for_update(refname, sha1, 0, NULL);
if (!lock)
return error("cannot lock ref '%s'", refname);
if (!reflog_exists(refname)) {
unlock_ref(lock);
return 0;
}
log_file = git_pathdup("logs/%s", refname);
if (!reflog_exists(refname))
goto finish;
if (!cmd->dry_run) {
newlog_path = git_pathdup("logs/%s.lock", refname);
cb.newlog = fopen(newlog_path, "w");
Expand Down Expand Up @@ -419,7 +421,7 @@ static int expire_reflog(const char *refname, const unsigned char *sha1,
clear_commit_marks(tip_commit, REACHABLE);
}
}
finish:

if (cb.newlog) {
if (fclose(cb.newlog)) {
status |= error("%s: %s", strerror(errno),
Expand Down

0 comments on commit 2e376b3

Please sign in to comment.