Skip to content

Commit 0f3d8e2

Browse files
committed
Merge branch 'kn/reflog-migration-fix' into kn/reflog-migration-fix-followup
* kn/reflog-migration-fix: reftable: write correct max_update_index to header
2 parents efff4a8 + bc67b4a commit 0f3d8e2

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

refs.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,13 @@ int ref_transaction_update_reflog(struct ref_transaction *transaction,
13451345
update->flags &= ~REF_HAVE_OLD;
13461346
update->index = index;
13471347

1348+
/*
1349+
* Reference backends may need to know the max index to optimize
1350+
* their writes. So we store the max_index on the transaction level.
1351+
*/
1352+
if (index > transaction->max_index)
1353+
transaction->max_index = index;
1354+
13481355
return 0;
13491356
}
13501357

refs/refs-internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ struct ref_transaction {
203203
enum ref_transaction_state state;
204204
void *backend_data;
205205
unsigned int flags;
206+
unsigned int max_index;
206207
};
207208

208209
/*

refs/reftable-backend.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,7 @@ struct write_transaction_table_arg {
942942
size_t updates_nr;
943943
size_t updates_alloc;
944944
size_t updates_expected;
945+
unsigned int max_index;
945946
};
946947

947948
struct reftable_transaction_data {
@@ -1428,7 +1429,6 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data
14281429
struct reftable_log_record *logs = NULL;
14291430
struct ident_split committer_ident = {0};
14301431
size_t logs_nr = 0, logs_alloc = 0, i;
1431-
uint64_t max_update_index = ts;
14321432
const char *committer_info;
14331433
int ret = 0;
14341434

@@ -1438,7 +1438,12 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data
14381438

14391439
QSORT(arg->updates, arg->updates_nr, transaction_update_cmp);
14401440

1441-
reftable_writer_set_limits(writer, ts, ts);
1441+
/*
1442+
* During reflog migration, we add indexes for a single reflog with
1443+
* multiple entries. Each entry will contain a different update_index,
1444+
* so set the limits accordingly.
1445+
*/
1446+
reftable_writer_set_limits(writer, ts, ts + arg->max_index);
14421447

14431448
for (i = 0; i < arg->updates_nr; i++) {
14441449
struct reftable_transaction_update *tx_update = &arg->updates[i];
@@ -1540,12 +1545,6 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data
15401545
*/
15411546
log->update_index = ts + u->index;
15421547

1543-
/*
1544-
* Note the max update_index so the limit can be set later on.
1545-
*/
1546-
if (log->update_index > max_update_index)
1547-
max_update_index = log->update_index;
1548-
15491548
log->refname = xstrdup(u->refname);
15501549
memcpy(log->value.update.new_hash,
15511550
u->new_oid.hash, GIT_MAX_RAWSZ);
@@ -1609,8 +1608,6 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data
16091608
* and log blocks.
16101609
*/
16111610
if (logs) {
1612-
reftable_writer_set_limits(writer, ts, max_update_index);
1613-
16141611
ret = reftable_writer_add_logs(writer, logs, logs_nr);
16151612
if (ret < 0)
16161613
goto done;
@@ -1631,6 +1628,9 @@ static int reftable_be_transaction_finish(struct ref_store *ref_store UNUSED,
16311628
struct reftable_transaction_data *tx_data = transaction->backend_data;
16321629
int ret = 0;
16331630

1631+
if (tx_data->args)
1632+
tx_data->args->max_index = transaction->max_index;
1633+
16341634
for (size_t i = 0; i < tx_data->args_nr; i++) {
16351635
ret = reftable_addition_add(tx_data->args[i].addition,
16361636
write_transaction_table, &tx_data->args[i]);

t/t1460-refs-migrate.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,18 @@ do
227227
done
228228
done
229229

230+
test_expect_success 'multiple reftable blocks with multiple entries' '
231+
test_when_finished "rm -rf repo" &&
232+
git init --ref-format=files repo &&
233+
test_commit -C repo first &&
234+
printf "create refs/heads/ref-%d HEAD\n" $(test_seq 5000) >stdin &&
235+
git -C repo update-ref --stdin <stdin &&
236+
test_commit -C repo second &&
237+
printf "update refs/heads/ref-%d HEAD\n" $(test_seq 3000) >stdin &&
238+
git -C repo update-ref --stdin <stdin &&
239+
test_migration repo reftable
240+
'
241+
230242
test_expect_success 'migrating from files format deletes backend files' '
231243
test_when_finished "rm -rf repo" &&
232244
git init --ref-format=files repo &&

0 commit comments

Comments
 (0)