Skip to content

Commit 00bd6c3

Browse files
pks-tgitster
authored andcommitted
refs: use "initial" transaction semantics to migrate refs
Until now, we couldn't use "initial" transaction semantics to migrate refs because the "files" backend only supported writing regular refs via the initial transaction because it simply mapped the transaction to a "packed-refs" transaction. But with the preceding commit, the "files" backend has learned to also write symbolic and root refs in the initial transaction by creating a second transaction for all refs that need to be written as loose refs. Adapt the code to migrate refs to commit the transaction as an initial transaction. This results in a signiticant speedup when migrating many refs: Benchmark 1: migrate reftable:files (refcount = 100000, revision = HEAD~) Time (mean ± σ): 3.247 s ± 0.034 s [User: 0.485 s, System: 2.722 s] Range (min … max): 3.216 s … 3.309 s 10 runs Benchmark 2: migrate reftable:files (refcount = 100000, revision = HEAD) Time (mean ± σ): 453.6 ms ± 1.9 ms [User: 214.6 ms, System: 230.5 ms] Range (min … max): 451.5 ms … 456.4 ms 10 runs Summary migrate reftable:files (refcount = 100000, revision = HEAD) ran 7.16 ± 0.08 times faster than migrate reftable:files (refcount = 100000, revision = HEAD~) As the reftable backend doesn't (yet) special-case initial transactions there is no comparable speedup for that backend. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c0b9cf3 commit 00bd6c3

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

refs.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,7 +2827,8 @@ int repo_migrate_ref_storage_format(struct repository *repo,
28272827
if (ret < 0)
28282828
goto done;
28292829

2830-
transaction = ref_store_transaction_begin(new_refs, 0, errbuf);
2830+
transaction = ref_store_transaction_begin(new_refs, REF_TRANSACTION_FLAG_INITIAL,
2831+
errbuf);
28312832
if (!transaction)
28322833
goto done;
28332834

@@ -2852,13 +2853,6 @@ int repo_migrate_ref_storage_format(struct repository *repo,
28522853
if (ret < 0)
28532854
goto done;
28542855

2855-
/*
2856-
* TODO: we might want to migrate to `initial_ref_transaction_commit()`
2857-
* here, which is more efficient for the files backend because it would
2858-
* write new refs into the packed-refs file directly. At this point,
2859-
* the files backend doesn't handle pseudo-refs and symrefs correctly
2860-
* though, so this requires some more work.
2861-
*/
28622856
ret = ref_transaction_commit(transaction, errbuf);
28632857
if (ret < 0)
28642858
goto done;

t/t1460-refs-migrate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ test_expect_success 'migrating from reftable format deletes backend files' '
237237
test_path_is_missing repo/.git/reftable &&
238238
echo "ref: refs/heads/main" >expect &&
239239
test_cmp expect repo/.git/HEAD &&
240-
test_path_is_file repo/.git/refs/heads/main
240+
test_path_is_file repo/.git/packed-refs
241241
'
242242

243243
test_done

0 commit comments

Comments
 (0)