]> git.ipfire.org Git - thirdparty/git.git/blobdiff - refs.c
sha1_name: avoid unnecessary sha1 lookup in find_unique_abbrev
[thirdparty/git.git] / refs.c
diff --git a/refs.c b/refs.c
index 43022066499ffaf828ac31e82b77f53539bc232d..7922261580515859bc89005c4c69e8623c50c728 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -72,10 +72,6 @@ int check_refname_format(const char *refname, int flags)
 {
        int component_len, component_count = 0;
 
-       if (!strcmp(refname, "@"))
-               /* Refname is a single character '@'. */
-               return -1;
-
        while (1) {
                /* We are at the start of a path component. */
                component_len = check_refname_component(refname, flags);
@@ -634,7 +630,9 @@ struct ref_entry_cb {
 static int do_one_ref(struct ref_entry *entry, void *cb_data)
 {
        struct ref_entry_cb *data = cb_data;
+       struct ref_entry *old_current_ref;
        int retval;
+
        if (prefixcmp(entry->name, data->base))
                return 0;
 
@@ -642,10 +640,12 @@ static int do_one_ref(struct ref_entry *entry, void *cb_data)
              !ref_resolves_to_object(entry))
                return 0;
 
+       /* Store the old value, in case this is a recursive call: */
+       old_current_ref = current_ref;
        current_ref = entry;
        retval = data->fn(entry->name + data->trim, entry->u.value.sha1,
                          entry->flag, data->cb_data);
-       current_ref = NULL;
+       current_ref = old_current_ref;
        return retval;
 }
 
@@ -2174,11 +2174,14 @@ int lock_packed_refs(int flags)
 {
        struct packed_ref_cache *packed_ref_cache;
 
-       /* Discard the old cache because it might be invalid: */
-       clear_packed_ref_cache(&ref_cache);
        if (hold_lock_file_for_update(&packlock, git_path("packed-refs"), flags) < 0)
                return -1;
-       /* Read the current packed-refs while holding the lock: */
+       /*
+        * Get the current packed-refs while holding the lock.  If the
+        * packed-refs file has been modified since we last read it,
+        * this will automatically invalidate the cache and re-read
+        * the packed-refs file.
+        */
        packed_ref_cache = get_packed_ref_cache(&ref_cache);
        packed_ref_cache->lock = &packlock;
        /* Increment the reference count to prevent it from being freed: */