Skip to content

Commit 0360d64

Browse files
committed
Merge branch 'kn/reflog-migration-fix-followup' into seen
* kn/reflog-migration-fix-followup: reftable: prevent 'update_index' changes after header write refs: use 'uint64_t' for 'ref_update.index' refs: mark `ref_transaction_update_reflog()` as static
2 parents ce46d34 + 709af40 commit 0360d64

File tree

5 files changed

+20
-25
lines changed

5 files changed

+20
-25
lines changed

refs.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,13 +1318,15 @@ int ref_transaction_update(struct ref_transaction *transaction,
13181318
return 0;
13191319
}
13201320

1321-
int ref_transaction_update_reflog(struct ref_transaction *transaction,
1322-
const char *refname,
1323-
const struct object_id *new_oid,
1324-
const struct object_id *old_oid,
1325-
const char *committer_info, unsigned int flags,
1326-
const char *msg, unsigned int index,
1327-
struct strbuf *err)
1321+
static int ref_transaction_update_reflog(struct ref_transaction *transaction,
1322+
const char *refname,
1323+
const struct object_id *new_oid,
1324+
const struct object_id *old_oid,
1325+
const char *committer_info,
1326+
unsigned int flags,
1327+
const char *msg,
1328+
uint64_t index,
1329+
struct strbuf *err)
13281330
{
13291331
struct ref_update *update;
13301332

@@ -2805,7 +2807,7 @@ static int migrate_one_ref(const char *refname, const char *referent UNUSED, con
28052807
}
28062808

28072809
struct reflog_migration_data {
2808-
unsigned int index;
2810+
uint64_t index;
28092811
const char *refname;
28102812
struct ref_store *old_refs;
28112813
struct ref_transaction *transaction;

refs.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -771,20 +771,6 @@ int ref_transaction_update(struct ref_transaction *transaction,
771771
unsigned int flags, const char *msg,
772772
struct strbuf *err);
773773

774-
/*
775-
* Similar to`ref_transaction_update`, but this function is only for adding
776-
* a reflog update. Supports providing custom committer information. The index
777-
* field can be utiltized to order updates as desired. When not used, the
778-
* updates default to being ordered by refname.
779-
*/
780-
int ref_transaction_update_reflog(struct ref_transaction *transaction,
781-
const char *refname,
782-
const struct object_id *new_oid,
783-
const struct object_id *old_oid,
784-
const char *committer_info, unsigned int flags,
785-
const char *msg, unsigned int index,
786-
struct strbuf *err);
787-
788774
/*
789775
* Add a reference creation to transaction. new_oid is the value that
790776
* the reference should have after the update; it must not be

refs/refs-internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct ref_update {
120120
* when migrating reflogs and we want to ensure we carry over the
121121
* same order.
122122
*/
123-
unsigned int index;
123+
uint64_t index;
124124

125125
/*
126126
* If this ref_update was split off of a symref update via
@@ -203,7 +203,7 @@ struct ref_transaction {
203203
enum ref_transaction_state state;
204204
void *backend_data;
205205
unsigned int flags;
206-
unsigned int max_index;
206+
uint64_t max_index;
207207
};
208208

209209
/*

refs/reftable-backend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +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;
945+
uint64_t max_index;
946946
};
947947

948948
struct reftable_transaction_data {

reftable/writer.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ int reftable_writer_new(struct reftable_writer **out,
182182
void reftable_writer_set_limits(struct reftable_writer *w, uint64_t min,
183183
uint64_t max)
184184
{
185+
/*
186+
* The limits shouldn't be modified post writing the first block, else
187+
* it would cause a mismatch between the header and the footer.
188+
*/
189+
if (w->next)
190+
BUG("update index modified after writing first block");
191+
185192
w->min_update_index = min;
186193
w->max_update_index = max;
187194
}

0 commit comments

Comments
 (0)