Subject: Re: [PATCH] Documentation: 'cherry' does not cope well with merges from upstream

From: Michael J Gruber <[email-masked]>
Date: Fri, 02 Jul 2010 09:46:37 +0200

Jonathan Nieder venit, vidit, dixit 01.07.2010 23:09:
> Although ‘git cherry’ is advertised simply to list commits from
> <topic> that have not been merged into <upstream>, internally it
> works by checking for patches in <upstream>..<topic> that do not
> match a patch in <topic>..<upstream>.  This is fast because there

...and it says so in the very first line of the manpage.

> are not many patches to check, and it makes sense semantically
> since even if a new patch patches an old patch from <upstream>,
> it cannot be said to have been merged upstream unless it was
> applied there at some point after the <topic> and <upstream>
> branches diverged.
> 
> But.  If the <topic> branch later merges from <upstream>, it
> throws a spanner in the works and for such a history ‘git cherry’
> is not very useful at all.

I actually think I've reported this before, but I don't mind :)
I keep (topic) branches for my git.git patches. git cherry is helpful
here. When a patch is applied, I merge the corresponding commit (i.e.
Junio's version) to my topic branch to mark it as applied and to have a
nice way of comparing the applied version to the submitted one. At that
point git cherry stops being useful.

> 
> Example:
> 
>  o---o---F---X'---G---U [upstream]
>           \        \
>            X----Y---M---T [topic]
> 
> Suppose the author of the ‘topic’ branch starts from upstream
> commit F and makes a few changes.  One is applied upstream, and
> additionally there is some other useful upstream change, so he
> performs a merge to include the upstream updates into topic.
> The expected output from ‘cherry’ is:
> 
>  + T
>  + Y
>  - X
> 
> Consider the author of a different branch, also called ‘topic’, but
> this one starts from commit G.  Some infrastructure from an existing 
> branch is needed, so first she merges that.  Then she adds her own
> commit.  The expected output from ‘cherry’ is:
> 
>  + T
>  + Y
>  + X
> 
> since none of the new commits have been applied upstream since
> the fork point.
> 
> ‘cherry’ cannot distinguish between these two cases, in part because
> it does not distinguish between parents in a merge commit.
> 
> Add a BUGS section to explain the problem.

This is not a bug. git cherry works exactly as described.

At worst, it is a misfeature.

git cherry would be more useful if you could specify a "limit" which is
an ancestor of "fork-point", not only descendants.

> Thoughts?  Improvements?

Allow general "limit" :)

> 
>  Documentation/git-cherry.txt |   15 +++++++++++++++
>  1 files changed, 15 insertions(+), 0 deletions(-)
> 
> diff --git a/Documentation/git-cherry.txt b/Documentation/git-cherry.txt
> index fed115a..83e3bdc 100644
> --- a/Documentation/git-cherry.txt
> +++ b/Documentation/git-cherry.txt
> @@ -59,6 +59,21 @@ OPTIONS
>  <limit>::
>  	Do not report commits up to (and including) limit.
>  
> +BUGS

+DISCUSSION

> +----
> +'git cherry' does not cope well with merges from upstream on the
> +working branch.  Any commits after the original fork point and

...which is the wrong way round anyways ;)

> +before the latest merge from upstream will be reported as not found
> +in <upstream>.
> +
> +                       ____*____*____*_____*__> <upstream>
> +                      /                     \
> +   original fork point                       \
> +                      \__+__+__+__+__+__+__+__*_> <head>
> +
> +While these commits are part of upstream..head, their upstream
> +counterparts are not in head..upstream.

git-cherry(1) never speaks about upstream..head nor head..upstream. It
uses "fork-point", and a merge creates a new "fork-point", i.e.
merge-base. I think it would be good to keep like that in order to avoid
that very misunderstanding. In fact, git cherry is about left and right
commits in upstream...head.

The second paragraph of "DESCRIPTION" may cause confusion when read
without the first one, though.

Michael