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

log --cherry and merges (was [RFC/PATCH 0/2] merge-base: add --merge-child option)

From
John Keeping <john@keeping.me.uk>
Date
May 19, 2013, 12:40 UTC
Message-ID
<20130519124059.GJ27005@serenity.lan>
In-Reply-To
<5190FC97.6020800@drmicha.warpmail.net>
On Mon, May 13, 2013 at 04:45:43PM +0200, Michael J Gruber wrote:
Show 27 quoted lines
> Kevin Bracey venit, vidit, dixit 13.05.2013 16:26:
> > On 13/05/2013 01:22, Junio C Hamano wrote:
> >> Kevin Bracey <kevin@bracey.fi> writes:
> >>
> >>>     git log --ancestry-path --left-right E...F --not $(git merge-base
> >>> --all E F)
> >>>
> >>> which looks like we're having to repeat ourselves because it's not
> >>> paying attention...
> >> You are half wrong; "--left-right" is about "do we show the </>/=
> >> marker in the output?", so it is true that it does not make sense
> >> without "...", but the reverse is not true: A...B does not and
> >> should not imply --left-right.
> >>
> > The repetition I meant is that by the definition of ancestry-path, the 
> > above would seem to be equivalent to
> > 
> >    git log --ancestry-path --left-right E F --not $(git merge-base --all E F) $(git merge-base --all E F)
> > 
> > Anyway, revised separated-out version of the patch follows.
> > 
> > Kevin
> 
> It is certainly true that "git log --cherry" needs much less information
> than what the merge base machinery provides. I've been experimenting
> with that in order to get the speedup which is necessary for replacing
> the "git cherry" code with calls into the revision walker using "--cherry".

I think the revision machinery is the same speed as the "git cherry" code, it's just that "git cherry" ignores merges and the cherry code in revision.c doesn't.

Since the patch ID of a merge is just being calculated to its first parent, I don't think it's meaningful to consider merges for "log --cherry" but I can't quite convince myself that there's no corner case where it is.

The following patch makes the revision cherry machinery ignore merges unconditionally. With it applied, there's not noticeable difference in speed between "git cherry" and "git log --cherry".

-- >8 --
diff --git a/revision.c b/revision.c
index a67b615..19d0683 100644
--- a/revision.c
+++ b/revision.c
@@ -640,6 +640,11 @@ static void cherry_pick_list(struct commit_list *list, struct rev_info *revs)
 
 		if (flags & BOUNDARY)
 			continue;
+
+		/* Patch ID is meaningless for merges. */
+		if (commit->parents && commit->parents->next)
+			continue;
+
 		/*
 		 * If we have fewer left, left_first is set and we omit
 		 * commits on the right branch in this loop.  If we have
@@ -661,6 +666,11 @@ static void cherry_pick_list(struct commit_list *list, struct rev_info *revs)
 
 		if (flags & BOUNDARY)
 			continue;
+
+		/* Patch ID is meaningless for merges. */
+		if (commit->parents && commit->parents->next)
+			continue;
+
 		/*
 		 * If we have fewer left, left_first is set and we omit
 		 * commits on the left branch in this loop.
-- 
1.8.3.rc3.372.g721bad8
Previous: Michael J GruberNext: Jonathan Nieder
Message 13 of 22 in “merge-base: add --merge-child option”
  1. 0/2 merge-base: add --merge-child optionJohn Keeping, May 11, 2013
  2. 1/2 commit: add commit_list_contains functionJohn Keeping, May 11, 2013
  3. 2/2 merge-base: add --merge-child optionJohn Keeping, May 11, 2013
  4. Junio C HamanoMay 11, 2013
  5. John KeepingMay 11, 2013
  6. Kevin BraceyMay 12, 2013
  7. John KeepingMay 12, 2013
  8. John KeepingMay 12, 2013
  9. Kevin BraceyMay 12, 2013
  10. Junio C HamanoMay 12, 2013
  11. Kevin BraceyMay 13, 2013
  12. Michael J GruberMay 13, 2013
  13. log --cherry and merges (was [RFC/PATCH 0/2] merge-base: add --merge-child option)John Keeping, May 19, 2013
  14. Jonathan NiederMay 20, 2013
  15. 0/2 Make --ancestry-path A...B workKevin Bracey, May 13, 2013
  16. 1/2 t6019: demonstrate --ancestry-path A...B breakageKevin Bracey, May 13, 2013
  17. 2/2 revision.c: treat A...B merge bases as if manually specifiedKevin Bracey, May 13, 2013
  18. Junio C HamanoMay 13, 2013
  19. John KeepingMay 12, 2013
  20. Kevin BraceyMay 12, 2013
  21. Junio C HamanoMay 13, 2013
  22. John KeepingMay 13, 2013

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.