git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Francis Moreau <francis.moro@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	"git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: git-log --cherry-pick gives different results when using tag or tag^{}
Date: Wed, 15 Jan 2014 04:49:45 -0500	[thread overview]
Message-ID: <20140115094945.GD14335@sigill.intra.peff.net> (raw)
In-Reply-To: <52CFF27C.1090108@gmail.com>

[+cc Junio, as the bug blames to him]

On Fri, Jan 10, 2014 at 02:15:40PM +0100, Francis Moreau wrote:

> In mykernel repository, I'm having 2 different behaviours with git-log
> but I don't understand why:
> 
> Doing:
> 
>     $ git log --oneline --cherry-pick --left-right v3.4.71-1^{}...next
> 
> and
> 
>     $ git log --oneline --cherry-pick --left-right v3.4.71-1...next
> 
> give something different (where v3.4.71-1 is a tag).
> 
> The command using ^{} looks the one that gives correct result I think.

Yeah, this looks like a bug. Here's a simple reproduction recipe:

  commit() {
    echo content >$1 &&
    git add $1 &&
    git commit -m $1
  }

  git init repo && cd repo &&
  commit one &&
  commit two &&
  sleep 1 &&
  git tag -m foo mytag &&
  git checkout -b side HEAD^ &&
  git cherry-pick mytag &&
  commit three

The sleep seems to be necessary, to give the commit and its
cherry-picked version different commit times (presumably because it
impacts the order in which we visit them during the traversal).

Running:

  git log --oneline --decorate --cherry-pick --left-right mytag^{}...HEAD

produces the expected:

  > e36cc32 (HEAD, side) three

but running it with the tag, as:

  git log --oneline --decorate --cherry-pick --left-right mytag...HEAD

yields:

  > e36cc32 (HEAD, side) three
  > 5e96f7d two
  > db92fca (tag: mytag, master) two

Not only do we get the cherry-pick wrong (we should omit both "twos"),
but we seem to erroneously count the tagged "two" as being on the
right-hand side, which it clearly is not (and which is probably why we
don't find the match via --cherry-pick).

This worked in v1.8.4, but is broken in v1.8.5. It bisects to Junio's
895c5ba (revision: do not peel tags used in range notation, 2013-09-19),
which sounds promising.

I think what is happening is that we used to apply the SYMMETRIC_LEFT
flag directly to the commit. Now we apply it to the tag, and it does not
seem to get propagated. The patch below fixes it for me, but I have no
idea if we actually need to be setting the other flags, or just
SYMMETRIC_LEFT. I also wonder if the non-symmetric two-dot case needs to
access any pointed-to commit and propagate flags in a similar way.

diff --git a/revision.c b/revision.c
index 7010aff..1d99bfc 100644
--- a/revision.c
+++ b/revision.c
@@ -1197,6 +1197,8 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
 				free_commit_list(exclude);
 
 				a_flags = flags | SYMMETRIC_LEFT;
+				a->object.flags |= a_flags;
+				b->object.flags |= flags;
 			}
 
 			a_obj->flags |= a_flags;

-Peff

  reply	other threads:[~2014-01-15  9:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-10 13:15 git-log --cherry-pick gives different results when using tag or tag^{} Francis Moreau
2014-01-15  9:49 ` Jeff King [this message]
2014-01-15  9:59   ` Francis Moreau
2014-01-15 19:57   ` Junio C Hamano
2014-01-15 20:26     ` revision: propagate flag bits from tags to pointees Junio C Hamano
2014-01-15 21:56       ` Jeff King
2014-01-15 22:25         ` Junio C Hamano
2014-01-15 22:41           ` Junio C Hamano
2014-01-15 21:53     ` git-log --cherry-pick gives different results when using tag or tag^{} Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140115094945.GD14335@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=francis.moro@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).