Skip to content

Commit

Permalink
refs: break out check for reflog autocreation
Browse files Browse the repository at this point in the history
This is just for clarity.

Signed-off-by: David Turner <dturner@twopensource.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
David Turner authored and Junio C Hamano committed Jul 21, 2015
1 parent a4c653d commit 4e2bef5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3053,6 +3053,16 @@ static int copy_msg(char *buf, const char *msg)
return cp - buf;
}

static int should_autocreate_reflog(const char *refname)
{
if (!log_all_ref_updates)
return 0;
return starts_with(refname, "refs/heads/") ||
starts_with(refname, "refs/remotes/") ||
starts_with(refname, "refs/notes/") ||
!strcmp(refname, "HEAD");
}

/* This function will fill in *err and return -1 on failure */
int log_ref_setup(const char *refname, struct strbuf *sb_logfile, struct strbuf *err)
{
Expand All @@ -3063,11 +3073,7 @@ int log_ref_setup(const char *refname, struct strbuf *sb_logfile, struct strbuf
logfile = sb_logfile->buf;
/* make sure the rest of the function can't change "logfile" */
sb_logfile = NULL;
if (log_all_ref_updates &&
(starts_with(refname, "refs/heads/") ||
starts_with(refname, "refs/remotes/") ||
starts_with(refname, "refs/notes/") ||
!strcmp(refname, "HEAD"))) {
if (should_autocreate_reflog(refname)) {
if (safe_create_leading_directories(logfile) < 0) {
strbuf_addf(err, "unable to create directory for %s: "
"%s", logfile, strerror(errno));
Expand Down

0 comments on commit 4e2bef5

Please sign in to comment.