Skip to content

Commit a3582e2

Browse files
KarthikNayakgitster
authored andcommitted
refs: add index field to struct ref_udpate
The reftable backend, sorts its updates by refname before applying them, this ensures that the references are stored sorted. When migrating reflogs from one backend to another, the order of the reflogs must be maintained. Add a new `index` field to the `ref_update` struct to facilitate this. This field is used in the reftable backend's sort comparison function `transaction_update_cmp`, to ensure that indexed fields maintain their order. Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1a83e26 commit a3582e2

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

refs/refs-internal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ struct ref_update {
115115
char *msg;
116116
char *committer_info;
117117

118+
/*
119+
* The index overrides the default sort algorithm. This is needed
120+
* when migrating reflogs and we want to ensure we carry over the
121+
* same order.
122+
*/
123+
unsigned int index;
124+
118125
/*
119126
* If this ref_update was split off of a symref update via
120127
* split_symref_update(), then this member points at that

refs/reftable-backend.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,8 +1279,17 @@ static int reftable_be_transaction_abort(struct ref_store *ref_store UNUSED,
12791279

12801280
static int transaction_update_cmp(const void *a, const void *b)
12811281
{
1282-
return strcmp(((struct reftable_transaction_update *)a)->update->refname,
1283-
((struct reftable_transaction_update *)b)->update->refname);
1282+
struct reftable_transaction_update *update_a = (struct reftable_transaction_update *)a;
1283+
struct reftable_transaction_update *update_b = (struct reftable_transaction_update *)b;
1284+
1285+
/*
1286+
* If there is an index set, it should take preference (default is 0).
1287+
* This ensures that updates with indexes are sorted amongst themselves.
1288+
*/
1289+
if (update_a->update->index || update_b->update->index)
1290+
return update_a->update->index - update_b->update->index;
1291+
1292+
return strcmp(update_a->update->refname, update_b->update->refname);
12841293
}
12851294

12861295
static int write_transaction_table(struct reftable_writer *writer, void *cb_data)

0 commit comments

Comments
 (0)