@@ -2843,6 +2843,14 @@ int repo_migrate_ref_storage_format(struct repository *repo,
2843
2843
goto done ;
2844
2844
}
2845
2845
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
+
2846
2854
/*
2847
2855
* Until now we were in the non-destructive phase, where we only
2848
2856
* populated the new ref store. From hereon though we are about
@@ -2874,10 +2882,14 @@ int repo_migrate_ref_storage_format(struct repository *repo,
2874
2882
*/
2875
2883
initialize_repository_version (hash_algo_by_ptr (repo -> hash_algo ), format , 1 );
2876
2884
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
+ */
2880
2890
ref_store_release (old_refs );
2891
+ FREE_AND_NULL (old_refs );
2892
+ repo -> refs_private = NULL ;
2881
2893
2882
2894
ret = 0 ;
2883
2895
@@ -2888,8 +2900,10 @@ int repo_migrate_ref_storage_format(struct repository *repo,
2888
2900
new_gitdir .buf );
2889
2901
}
2890
2902
2891
- if (ret && new_refs )
2903
+ if (new_refs ) {
2892
2904
ref_store_release (new_refs );
2905
+ free (new_refs );
2906
+ }
2893
2907
ref_transaction_free (transaction );
2894
2908
strbuf_release (& new_gitdir );
2895
2909
return ret ;
0 commit comments