git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Matt McClure <matthewlmcclure@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: Can `git blame` show the date that each line was merged?
Date: Tue, 4 Jun 2013 11:56:05 -0400	[thread overview]
Message-ID: <20130604155605.GA15953@sigill.intra.peff.net> (raw)
In-Reply-To: <CAJELnLEiK1C9PeimSwDoJoy=wFbFF0+KoK3jhXSAV4b2DsBKqw@mail.gmail.com>

On Tue, Jun 04, 2013 at 09:39:45AM -0400, Matt McClure wrote:

> Can `git blame` show the date that each line was merged to the current
> branch rather than the date it was committed?

Not exactly. Git does not record when a commit entered a particular
branch (or what the "ours" branch was called during a merge).  If you
follow a topic branch workflow in which an integrator merges each branch
into master, then following the first parent of each merge will show the
commits directly on master.

You can see this in action in git.git, which follows such a workflow, by
doing "git log --first-parent", which shows only the commits created
directly on master (mostly merges of topics, with a few trivial fixups
interspersed).

Similarly, you should be able to do "git blame --first-parent foo.c" to
pass blame only along the first-parent lines. Unfortunately, while
"blame" uses the regular revision code to parse its options, it does its
own traversal and does not respect each option. However, the patch to
teach it about --first-parent is pretty trivial:

diff --git a/builtin/blame.c b/builtin/blame.c
index 57a487e..0fb67af 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -1199,6 +1199,8 @@ static int num_scapegoats(struct rev_info *revs, struct commit *commit)
 {
 	int cnt;
 	struct commit_list *l = first_scapegoat(revs, commit);
+	if (revs->first_parent_only)
+		return l ? 1 : 0;
 	for (cnt = 0; l; l = l->next)
 		cnt++;
 	return cnt;

(though I suspect it would interact oddly with the "--reverse" option,
and we would want to either declare them mutually exclusive or figure
out some sane semantics).

> Aside: in some trial and error I notice this oddity:
> 
>     $ git blame --merges
>     usage: git blame [options] [rev-opts] [rev] [--] file
> 
>         [rev-opts] are documented in git-rev-list(1)
>     ...

Your problem is not the presence of "--merges" here, but that you forgot
the necessary "file" argument. Try "git blame --merges foo.c".

However, this suffers from the same problem as --first-parent, in that
it is accepted but not respected. Doing so would not be impossible, but
it is a little more than the two-liner above.

-Peff

  reply	other threads:[~2013-06-04 15:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-04 13:39 Can `git blame` show the date that each line was merged? Matt McClure
2013-06-04 15:56 ` Jeff King [this message]
2013-06-04 17:26   ` Matt McClure
2013-06-04 17:28   ` Junio C Hamano
2013-06-04 17:44     ` 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=20130604155605.GA15953@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=matthewlmcclure@gmail.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).