write_ref_sha1(): only invalidate the loose ref cache
[gitweb.git] / refs.c
diff --git a/refs.c b/refs.c
index 02b1ef0a8911762702ae1647265283c3ef8a4d53..a888cea56eb6c8142f4a31e9214bf349965f3d66 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -158,13 +158,24 @@ static void free_ref_array(struct ref_array *array)
        array->refs = NULL;
 }
 
-static void clear_ref_cache(struct ref_cache *ca)
+static void clear_packed_ref_cache(struct ref_cache *refs)
 {
-       if (ca->did_loose)
-               free_ref_array(&ca->loose);
-       if (ca->did_packed)
-               free_ref_array(&ca->packed);
-       ca->did_loose = ca->did_packed = 0;
+       if (refs->did_packed)
+               free_ref_array(&refs->packed);
+       refs->did_packed = 0;
+}
+
+static void clear_loose_ref_cache(struct ref_cache *refs)
+{
+       if (refs->did_loose)
+               free_ref_array(&refs->loose);
+       refs->did_loose = 0;
+}
+
+static void clear_ref_cache(struct ref_cache *refs)
+{
+       clear_packed_ref_cache(refs);
+       clear_loose_ref_cache(refs);
 }
 
 static struct ref_cache *create_ref_cache(const char *submodule)
@@ -202,13 +213,9 @@ static struct ref_cache *get_ref_cache(const char *submodule)
        return refs;
 }
 
-static void invalidate_ref_cache(void)
+void invalidate_ref_cache(const char *submodule)
 {
-       struct ref_cache *refs = ref_cache;
-       while (refs) {
-               clear_ref_cache(refs);
-               refs = refs->next;
-       }
+       clear_ref_cache(get_ref_cache(submodule));
 }
 
 static void read_packed_refs(FILE *f, struct ref_array *array)
@@ -1228,7 +1235,7 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
        ret |= repack_without_ref(refname);
 
        unlink_or_warn(git_path("logs/%s", lock->ref_name));
-       invalidate_ref_cache();
+       invalidate_ref_cache(NULL);
        unlock_ref(lock);
        return ret;
 }
@@ -1527,7 +1534,7 @@ int write_ref_sha1(struct ref_lock *lock,
                unlock_ref(lock);
                return -1;
        }
-       invalidate_ref_cache();
+       clear_loose_ref_cache(get_ref_cache(NULL));
        if (log_ref_write(lock->ref_name, lock->old_sha1, sha1, logmsg) < 0 ||
            (strcmp(lock->ref_name, lock->orig_ref_name) &&
             log_ref_write(lock->orig_ref_name, lock->old_sha1, sha1, logmsg) < 0)) {