| 3328 | } |
| 3329 | |
| 3330 | int repo_migrate_ref_storage_format(struct repository *repo, |
| 3331 | enum ref_storage_format format, |
| 3332 | unsigned int flags, |
| 3333 | struct strbuf *errbuf) |
| 3334 | { |
| 3335 | struct ref_store *old_refs = NULL, *new_refs = NULL; |
| 3336 | struct refs_for_each_ref_options for_each_ref_opts = { |
| 3337 | .flags = REFS_FOR_EACH_INCLUDE_ROOT_REFS | REFS_FOR_EACH_INCLUDE_BROKEN, |
| 3338 | }; |
| 3339 | struct ref_transaction *transaction = NULL; |
| 3340 | struct strbuf new_gitdir = STRBUF_INIT; |
| 3341 | struct migration_data data = { |
| 3342 | .sb = STRBUF_INIT, |
| 3343 | .name = STRBUF_INIT, |
| 3344 | .mail = STRBUF_INIT, |
| 3345 | }; |
| 3346 | int did_migrate_refs = 0; |
| 3347 | int ret; |
| 3348 | |
| 3349 | if (repo->ref_storage_format == format) { |
| 3350 | strbuf_addstr(errbuf, "current and new ref storage format are equal"); |
| 3351 | ret = -1; |
| 3352 | goto done; |
| 3353 | } |
| 3354 | |
| 3355 | old_refs = get_main_ref_store(repo); |
| 3356 | |
| 3357 | /* |
| 3358 | * Worktrees complicate the migration because every worktree has a |
| 3359 | * separate ref storage. While it should be feasible to implement, this |
| 3360 | * is pushed out to a future iteration. |
| 3361 | * |
| 3362 | * TODO: we should really be passing the caller-provided repository to |
| 3363 | * `has_worktrees()`, but our worktree subsystem doesn't yet support |
| 3364 | * that. |
| 3365 | */ |
| 3366 | if (has_worktrees()) { |
| 3367 | strbuf_addstr(errbuf, "migrating repositories with worktrees is not supported yet"); |
| 3368 | ret = -1; |
| 3369 | goto done; |
| 3370 | } |
| 3371 | |
| 3372 | /* |
| 3373 | * The overall logic looks like this: |
| 3374 | * |
| 3375 | * 1. Set up a new temporary directory and initialize it with the new |
| 3376 | * format. This is where all refs will be migrated into. |
| 3377 | * |
| 3378 | * 2. Enumerate all refs and write them into the new ref storage. |
| 3379 | * This operation is safe as we do not yet modify the main |
| 3380 | * repository. |
| 3381 | * |
| 3382 | * 3. Enumerate all reflogs and write them into the new ref storage. |
| 3383 | * This operation is safe as we do not yet modify the main |
| 3384 | * repository. |
| 3385 | * |
| 3386 | * 4. If we're in dry-run mode then we are done and can hand over the |
| 3387 | * directory to the caller for inspection. If not, we now start |
no test coverage detected