summaryrefslogtreecommitdiffstats
path: root/refs.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-07-24 01:54:34 +0200
committerJunio C Hamano <gitster@pobox.com>2024-07-24 01:54:34 +0200
commitc89facd58e330363b1ce0c3c3cfc24c840f858dd (patch)
treefbf038527eeb1f8121b3de07b320f0f335075518 /refs.c
parentMerge branch 'js/doc-markup-updates-fix' (diff)
parentrefs: fix format migration on Cygwin (diff)
downloadgit-c89facd58e330363b1ce0c3c3cfc24c840f858dd.tar.xz
git-c89facd58e330363b1ce0c3c3cfc24c840f858dd.zip
Merge branch 'ps/ref-storage-migration-fix'
Hotfix for a topic already in -rc. * ps/ref-storage-migration-fix: refs: fix format migration on Cygwin
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/refs.c b/refs.c
index bb90a18875..915aeb4d1d 100644
--- a/refs.c
+++ b/refs.c
@@ -2844,6 +2844,14 @@ int repo_migrate_ref_storage_format(struct repository *repo,
}
/*
+ * Release the new ref store such that any potentially-open files will
+ * be closed. This is required for platforms like Cygwin, where
+ * renaming an open file results in EPERM.
+ */
+ ref_store_release(new_refs);
+ FREE_AND_NULL(new_refs);
+
+ /*
* Until now we were in the non-destructive phase, where we only
* populated the new ref store. From hereon though we are about
* to get hands by deleting the old ref store and then moving
@@ -2874,10 +2882,14 @@ int repo_migrate_ref_storage_format(struct repository *repo,
*/
initialize_repository_version(hash_algo_by_ptr(repo->hash_algo), format, 1);
- free(new_refs->gitdir);
- new_refs->gitdir = xstrdup(old_refs->gitdir);
- repo->refs_private = new_refs;
+ /*
+ * Unset the old ref store and release it. `get_main_ref_store()` will
+ * make sure to lazily re-initialize the repository's ref store with
+ * the new format.
+ */
ref_store_release(old_refs);
+ FREE_AND_NULL(old_refs);
+ repo->refs_private = NULL;
ret = 0;
@@ -2888,8 +2900,10 @@ done:
new_gitdir.buf);
}
- if (ret && new_refs)
+ if (new_refs) {
ref_store_release(new_refs);
+ free(new_refs);
+ }
ref_transaction_free(transaction);
strbuf_release(&new_gitdir);
return ret;