summaryrefslogtreecommitdiffstats
path: root/refs
diff options
context:
space:
mode:
authorKarthik Nayak <karthik.188@gmail.com>2024-12-16 17:44:27 +0100
committerJunio C Hamano <gitster@pobox.com>2024-12-16 18:45:32 +0100
commita3582e2eacfae4328146b5142a0950fffcc05198 (patch)
tree19b3b8cf351fc5a8f8add72b34300f9b93fb4aab /refs
parentrefs: include committer info in `ref_update` struct (diff)
downloadgit-a3582e2eacfae4328146b5142a0950fffcc05198.tar.xz
git-a3582e2eacfae4328146b5142a0950fffcc05198.zip
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>
Diffstat (limited to 'refs')
-rw-r--r--refs/refs-internal.h7
-rw-r--r--refs/reftable-backend.c13
2 files changed, 18 insertions, 2 deletions
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index 0fd95cdacd..f5c733d099 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -116,6 +116,13 @@ struct ref_update {
char *committer_info;
/*
+ * The index overrides the default sort algorithm. This is needed
+ * when migrating reflogs and we want to ensure we carry over the
+ * same order.
+ */
+ unsigned int index;
+
+ /*
* If this ref_update was split off of a symref update via
* split_symref_update(), then this member points at that
* update. This is used for two purposes:
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index e882602487..c008f20be7 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -1279,8 +1279,17 @@ static int reftable_be_transaction_abort(struct ref_store *ref_store UNUSED,
static int transaction_update_cmp(const void *a, const void *b)
{
- return strcmp(((struct reftable_transaction_update *)a)->update->refname,
- ((struct reftable_transaction_update *)b)->update->refname);
+ struct reftable_transaction_update *update_a = (struct reftable_transaction_update *)a;
+ struct reftable_transaction_update *update_b = (struct reftable_transaction_update *)b;
+
+ /*
+ * If there is an index set, it should take preference (default is 0).
+ * This ensures that updates with indexes are sorted amongst themselves.
+ */
+ if (update_a->update->index || update_b->update->index)
+ return update_a->update->index - update_b->update->index;
+
+ return strcmp(update_a->update->refname, update_b->update->refname);
}
static int write_transaction_table(struct reftable_writer *writer, void *cb_data)