git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/2] revision: Implement `git log --merge` also for rebase/cherry_pick/revert

From
Michael Lohmann <mi.al.lohmann@gmail.com>
Date
Jan 12, 2024, 15:50 UTC
Message-ID
<20240112155033.77204-2-mi.al.lohmann@gmail.com>
In-Reply-To
<20240112155033.77204-1-mi.al.lohmann@gmail.com>
Co-authored-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Michael Lohmann <mi.al.lohmann@gmail.com>
---
> I won't comment on the coding style violations in the patch below in
> this message.

I hope this one is better. The other one was just a proof of the general concept and meant as a starting point for a discussion if this is wanted at all. But I should still have taken more care.

On 12. Jan 2024, at 08:35, Johannes Sixt <j6t@kdbg.org> wrote:
Show 5 quoted lines
> Ha! Very nice patch. For comparison, have a look at my patch to achieve
> the same that I never submitted (in particular, the author date):
> https://github.com/j6t/git/commit/2327526213bc2fc3c109c1d8b4b0d95032346ff0
> 
> This implementation is more complete than mine. I like it.

Ha! Nice one! I took a few of your changes as an inspiration and put you as a co-author.

Cheers Michael

Difference compared to v1: Basically complete rewrite using "refs_resolve_ref_unsafe". Has to be applied after [PATCH v2 1/2] to avoid conflict.

 revision.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/revision.c b/revision.c
index 786e1a3e89..b0b47dd241 100644
--- a/revision.c
+++ b/revision.c
@@ -1961,6 +1961,25 @@ static void add_pending_commit_list(struct rev_info *revs,
 	}
 }
 
+static const char *lookup_other_head(struct object_id *oid)
+{
+	struct ref_store *refs = get_main_ref_store(the_repository);
+	const char *name;
+	int i;
+	static const char *const other_head[] = {
+		"MERGE_HEAD", "REBASE_HEAD", "CHERRY_PICK_HEAD", "REVERT_HEAD"
+	};
+
+	for (i = 0; i < ARRAY_SIZE(other_head); i++) {
+		name = refs_resolve_ref_unsafe(refs, other_head[i],
+					       RESOLVE_REF_READING, oid, NULL);
+		if (name)
+			return name;
+	}
+
+	die("--merge without MERGE_HEAD, REBASE_HEAD, CHERRY_PICK_HEAD or REVERT_HEAD?");
+}
+
 static void prepare_show_merge(struct rev_info *revs)
 {
 	struct commit_list *bases;
@@ -1974,13 +1993,7 @@ static void prepare_show_merge(struct rev_info *revs)
 	if (repo_get_oid(the_repository, "HEAD", &oid))
 		die("--merge without HEAD?");
 	head = lookup_commit_or_die(&oid, "HEAD");
-	other_head = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
-					     "MERGE_HEAD",
-					     RESOLVE_REF_READING,
-					     &oid,
-					     NULL);
-	if (!other_head)
-		die("--merge without MERGE_HEAD?");
+	other_head = lookup_other_head(&oid);
 	other = lookup_commit_or_die(&oid, other_head);
 	add_pending_object(revs, &head->object, "HEAD");
 	add_pending_object(revs, &other->object, other_head);
-- 
2.43.0.284.g6c31128a96
Previous: Michael LohmannNext: Junio C Hamano
Message 4 of 30 in “`log --merge` also for rebase/cherry pick/revert”
  1. `log --merge` also for rebase/cherry pick/revertMichael Lohmann, Jan 11, 2024
  2. Junio C HamanoJan 12, 2024
  3. 1/2 revision: ensure MERGE_HEAD is a ref in prepare_show_mergeMichael Lohmann, Jan 12, 2024
  4. 2/2 revision: Implement `git log --merge` also for rebase/cherry_pick/revertMichael Lohmann, Jan 12, 2024
  5. Junio C HamanoJan 12, 2024
  6. Patrick SteinhardtJan 15, 2024
  7. Junio C HamanoJan 15, 2024
  8. 1/2 revision: ensure MERGE_HEAD is a ref in prepare_show_mergeMichael Lohmann, Jan 17, 2024
  9. 2/2 revision: Implement `git log --merge` also for rebase/cherry_pick/revertMichael Lohmann, Jan 17, 2024
  10. Full disclosureMichael Lohmann, Jan 17, 2024
  11. Christian CouderJan 17, 2024
  12. Full disclosureMichael Lohmann, Jan 17, 2024
  13. Ruben SafirJan 21, 2024
  14. Junio C HamanoJan 17, 2024
  15. Elijah NewrenJan 24, 2024
  16. Junio C HamanoJan 24, 2024
  17. Johannes SixtJan 24, 2024
  18. Junio C HamanoJan 24, 2024
  19. Johannes SixtJan 24, 2024
  20. Junio C HamanoJan 24, 2024
  21. Junio C HamanoFeb 9, 2024
  22. Johannes SixtJan 12, 2024
  23. Johannes SixtJan 12, 2024
  24. Junio C HamanoJan 12, 2024
  25. phillip.wood123@gmail.comJan 12, 2024
  26. Michael LohmannJan 12, 2024
  27. Junio C HamanoJan 12, 2024
  28. Phillip WoodJan 15, 2024
  29. Junio C HamanoJan 12, 2024
  30. Michael LohmannJan 12, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.