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 <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Karthik Nayak committed
Dec 16, 2024 at 17:44 UTC
a3582e2eacfae4328146b5142a0950fffcc05198
2 files changed
+18
-2
refs/refs-internal.h
+7
@@ -115,6 +115,13 @@ struct ref_update {
115
char *msg;
116
char *committer_info;
117
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
+
125
/*
126
* If this ref_update was split off of a symref update via
127
* split_symref_update(), then this member points at that
refs/reftable-backend.c
+11
-2
@@ -1279,8 +1279,17 @@ static int reftable_be_transaction_abort(struct ref_store *ref_store UNUSED,
1279
1280
static int transaction_update_cmp(const void *a, const void *b)
1281
{
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);
1293
}
1294
1295
static int write_transaction_table(struct reftable_writer *writer, void *cb_data)