Skip to content

Commit c89facd

Browse files
committed
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
2 parents 6fcd72d + 09c8173 commit c89facd

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

refs.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,6 +2843,14 @@ int repo_migrate_ref_storage_format(struct repository *repo,
28432843
goto done;
28442844
}
28452845

2846+
/*
2847+
* Release the new ref store such that any potentially-open files will
2848+
* be closed. This is required for platforms like Cygwin, where
2849+
* renaming an open file results in EPERM.
2850+
*/
2851+
ref_store_release(new_refs);
2852+
FREE_AND_NULL(new_refs);
2853+
28462854
/*
28472855
* Until now we were in the non-destructive phase, where we only
28482856
* populated the new ref store. From hereon though we are about
@@ -2874,10 +2882,14 @@ int repo_migrate_ref_storage_format(struct repository *repo,
28742882
*/
28752883
initialize_repository_version(hash_algo_by_ptr(repo->hash_algo), format, 1);
28762884

2877-
free(new_refs->gitdir);
2878-
new_refs->gitdir = xstrdup(old_refs->gitdir);
2879-
repo->refs_private = new_refs;
2885+
/*
2886+
* Unset the old ref store and release it. `get_main_ref_store()` will
2887+
* make sure to lazily re-initialize the repository's ref store with
2888+
* the new format.
2889+
*/
28802890
ref_store_release(old_refs);
2891+
FREE_AND_NULL(old_refs);
2892+
repo->refs_private = NULL;
28812893

28822894
ret = 0;
28832895

@@ -2888,8 +2900,10 @@ int repo_migrate_ref_storage_format(struct repository *repo,
28882900
new_gitdir.buf);
28892901
}
28902902

2891-
if (ret && new_refs)
2903+
if (new_refs) {
28922904
ref_store_release(new_refs);
2905+
free(new_refs);
2906+
}
28932907
ref_transaction_free(transaction);
28942908
strbuf_release(&new_gitdir);
28952909
return ret;

0 commit comments

Comments
 (0)