refs: break out check for reflog autocreation
This is just for clarity. Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
David Turner committed
Jul 21, 2015 at 17:04 UTC
4e2bef57c9629ef869091d9ad41dc6d09528a662
1 file changed
+11
-5
refs.c
+11
-5
@@ -3053,6 +3053,16 @@ static int copy_msg(char *buf, const char *msg)
3053
return cp - buf;
3054
}
3055
3056
+static int should_autocreate_reflog(const char *refname)
3057
+{
3058
+ if (!log_all_ref_updates)
3059
+ return 0;
3060
+ return starts_with(refname, "refs/heads/") ||
3061
+ starts_with(refname, "refs/remotes/") ||
3062
+ starts_with(refname, "refs/notes/") ||
3063
+ !strcmp(refname, "HEAD");
3064
+}
3065
+
3066
/* This function will fill in *err and return -1 on failure */
3067
int log_ref_setup(const char *refname, struct strbuf *sb_logfile, struct strbuf *err)
3068
{
@@ -3063,11 +3073,7 @@ int log_ref_setup(const char *refname, struct strbuf *sb_logfile, struct strbuf
3073
logfile = sb_logfile->buf;
3074
/* make sure the rest of the function can't change "logfile" */
3075
sb_logfile = NULL;
3066
- if (log_all_ref_updates &&
3067
- (starts_with(refname, "refs/heads/") ||
3068
- starts_with(refname, "refs/remotes/") ||
3069
- starts_with(refname, "refs/notes/") ||
3070
- !strcmp(refname, "HEAD"))) {
3076
+ if (should_autocreate_reflog(refname)) {
3077
if (safe_create_leading_directories(logfile) < 0) {
3078
strbuf_addf(err, "unable to create directory for %s: "
3079
"%s", logfile, strerror(errno));