refs: use chdir_notify to update cached relative paths
[gitweb.git] / refs / files-backend.c
index f75d960e1982a2db5dc8828c6f1b10ffe64fda48..a92a2aa82137e811e12d1e9d67eb3b4fd85f19fd 100644 (file)
@@ -9,6 +9,7 @@
 #include "../lockfile.h"
 #include "../object.h"
 #include "../dir.h"
+#include "../chdir-notify.h"
 
 /*
  * This backend uses the following flags in `ref_update::flags` for
@@ -106,6 +107,11 @@ static struct ref_store *files_ref_store_create(const char *gitdir,
        refs->packed_ref_store = packed_ref_store_create(sb.buf, flags);
        strbuf_release(&sb);
 
+       chdir_notify_reparent("files-backend $GIT_DIR",
+                             &refs->gitdir);
+       chdir_notify_reparent("files-backend $GIT_COMMONDIR",
+                             &refs->gitcommondir);
+
        return ref_store;
 }
 
@@ -2931,13 +2937,12 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
 
        if (initial_ref_transaction_commit(packed_transaction, err)) {
                ret = TRANSACTION_GENERIC_ERROR;
-               goto cleanup;
        }
 
+       packed_refs_unlock(refs->packed_ref_store);
 cleanup:
        if (packed_transaction)
                ref_transaction_free(packed_transaction);
-       packed_refs_unlock(refs->packed_ref_store);
        transaction->state = REF_TRANSACTION_CLOSED;
        string_list_clear(&affected_refnames, 0);
        return ret;