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
maint
Junio C Hamano 2024-07-23 16:54:34 -07:00
commit c89facd58e
1 changed files with 18 additions and 4 deletions

22
refs.c
View File

@ -2843,6 +2843,14 @@ int repo_migrate_ref_storage_format(struct repository *repo,
goto done; goto done;
} }


/*
* 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 * Until now we were in the non-destructive phase, where we only
* populated the new ref store. From hereon though we are about * populated the new ref store. From hereon though we are about
@ -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); initialize_repository_version(hash_algo_by_ptr(repo->hash_algo), format, 1);


free(new_refs->gitdir); /*
new_refs->gitdir = xstrdup(old_refs->gitdir); * Unset the old ref store and release it. `get_main_ref_store()` will
repo->refs_private = new_refs; * make sure to lazily re-initialize the repository's ref store with
* the new format.
*/
ref_store_release(old_refs); ref_store_release(old_refs);
FREE_AND_NULL(old_refs);
repo->refs_private = NULL;


ret = 0; ret = 0;


@ -2888,8 +2900,10 @@ done:
new_gitdir.buf); new_gitdir.buf);
} }


if (ret && new_refs) if (new_refs) {
ref_store_release(new_refs); ref_store_release(new_refs);
free(new_refs);
}
ref_transaction_free(transaction); ref_transaction_free(transaction);
strbuf_release(&new_gitdir); strbuf_release(&new_gitdir);
return ret; return ret;