completion: offer ctags symbol names for 'git log -S', '-G' and '-L:'
[gitweb.git] / refs.c
diff --git a/refs.c b/refs.c
index 5ffdd778d9766cad21e251e9020e2be2ce677acf..cd36b64ed93f821936fd7ffb68e60ce384119898 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -419,6 +419,13 @@ static char *substitute_branch_name(const char **string, int *len)
 int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
 {
        char *last_branch = substitute_branch_name(&str, &len);
+       int   refs_found  = expand_ref(str, len, sha1, ref);
+       free(last_branch);
+       return refs_found;
+}
+
+int expand_ref(const char *str, int len, unsigned char *sha1, char **ref)
+{
        const char **p, *r;
        int refs_found = 0;
 
@@ -444,7 +451,6 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
                        warning("ignoring broken ref %s.", fullref);
                }
        }
-       free(last_branch);
        return refs_found;
 }
 
@@ -632,12 +638,17 @@ int copy_reflog_msg(char *buf, const char *msg)
 
 int should_autocreate_reflog(const char *refname)
 {
-       if (!log_all_ref_updates)
+       switch (log_all_ref_updates) {
+       case LOG_REFS_ALWAYS:
+               return 1;
+       case LOG_REFS_NORMAL:
+               return starts_with(refname, "refs/heads/") ||
+                       starts_with(refname, "refs/remotes/") ||
+                       starts_with(refname, "refs/notes/") ||
+                       !strcmp(refname, "HEAD");
+       default:
                return 0;
-       return starts_with(refname, "refs/heads/") ||
-               starts_with(refname, "refs/remotes/") ||
-               starts_with(refname, "refs/notes/") ||
-               !strcmp(refname, "HEAD");
+       }
 }
 
 int is_branch(const char *refname)
@@ -810,8 +821,7 @@ struct ref_update *ref_transaction_add_update(
                hashcpy(update->new_sha1, new_sha1);
        if (flags & REF_HAVE_OLD)
                hashcpy(update->old_sha1, old_sha1);
-       if (msg)
-               update->msg = xstrdup(msg);
+       update->msg = xstrdup_or_null(msg);
        return update;
 }