[PATCH RFC v3 16/18] sequencer: allow callers to provide mappings for the old commit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When executing the "rewritten-hook" we provide a list of commit mappings
that tell the hook the original commit ID as well as the commit ID that
specific commit was rewritten to. Typically, these should always be
different from one another, as otherwise there wouldn't have been a
rewrite of those commits in the first place.

With two upcoming subcommands for git-history(1) that is not the case
though, as we have already written the new commits ahead of time. We
only use the sequencer infrastructure in that case to insert those
commits at the correct position in the graph. This has the consequence
that original and rewritten object IDs will be the exact same, which is
quite unhelpful.

Introduce infrastructure so that the caller can tell us the original
object ID for such already-rewritten objects.

Signed-off-by: Patrick Steinhardt <ps@xxxxxx>
---
 sequencer.c |  7 +++++++
 sequencer.h | 14 ++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/sequencer.c b/sequencer.c
index 61447e5ccf..72d26b0eef 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2214,6 +2214,13 @@ static void record_in_rewritten(struct object_id *oid,
 	const char *path;
 	FILE *out;
 
+	if (opts->old_oid_mappings) {
+		struct replay_oid_mapping *mapping =
+			oidmap_get(opts->old_oid_mappings, oid);
+		if (mapping)
+			oid = &mapping->rewritten_oid;
+	}
+
 	if (opts->action == REPLAY_HISTORY_EDIT)
 		path = git_path_rewritten_pending_file();
 	else
diff --git a/sequencer.h b/sequencer.h
index 0e0e7301b8..e6cc8aeb5d 100644
--- a/sequencer.h
+++ b/sequencer.h
@@ -1,6 +1,7 @@
 #ifndef SEQUENCER_H
 #define SEQUENCER_H
 
+#include "oidmap.h"
 #include "strbuf.h"
 #include "strvec.h"
 #include "wt-status.h"
@@ -35,6 +36,12 @@ enum commit_msg_cleanup_mode {
 struct replay_ctx;
 struct replay_ctx* replay_ctx_new(void);
 
+/* Used as entry for the `original_oid_map`. */
+struct replay_oid_mapping {
+	struct oidmap_entry entry;
+	struct object_id rewritten_oid;
+};
+
 struct replay_opts {
 	enum replay_action action;
 
@@ -83,6 +90,13 @@ struct replay_opts {
 	/* Only used by REPLAY_NONE */
 	struct rev_info *revs;
 
+	/*
+	 * Used by the post-rewrite hook to fix up old object IDs. This can be
+	 * used to rewrite the old object ID to whatever is stored as value in
+	 * this map. The map contains `struct replay_oid_mapping` entries.
+	 */
+	const struct oidmap *old_oid_mappings;
+
 	/* Private use */
 	struct replay_ctx *ctx;
 };

-- 
2.51.0.417.g1ba7204a04.dirty





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux