git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Can `git blame` show the date that each line was merged?
@ 2013-06-04 13:39 Matt McClure
  2013-06-04 15:56 ` Jeff King
  0 siblings, 1 reply; 5+ messages in thread
From: Matt McClure @ 2013-06-04 13:39 UTC (permalink / raw)
  To: git

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

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)
    ...

    $ git help rev-list | grep -F -e --merges
                        [ --merges ]
           --merges
               --min-parents=2 is the same as --merges.
--max-parents=0 gives all


-- 
Matt McClure
http://matthewlmcclure.com
http://www.mapmyfitness.com/profile/matthewlmcclure

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Can `git blame` show the date that each line was merged?
  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
  2013-06-04 17:26   ` Matt McClure
  2013-06-04 17:28   ` Junio C Hamano
  0 siblings, 2 replies; 5+ messages in thread
From: Jeff King @ 2013-06-04 15:56 UTC (permalink / raw)
  To: Matt McClure; +Cc: Junio C Hamano, git

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: Can `git blame` show the date that each line was merged?
  2013-06-04 15:56 ` Jeff King
@ 2013-06-04 17:26   ` Matt McClure
  2013-06-04 17:28   ` Junio C Hamano
  1 sibling, 0 replies; 5+ messages in thread
From: Matt McClure @ 2013-06-04 17:26 UTC (permalink / raw)
  To: Jeff King; +Cc: Junio C Hamano, git

On Tue, Jun 4, 2013 at 11:56 AM, Jeff King <peff@peff.net> wrote:
>> 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".

Oops. Thanks.


-- 
Matt McClure
http://matthewlmcclure.com
http://www.mapmyfitness.com/profile/matthewlmcclure

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Can `git blame` show the date that each line was merged?
  2013-06-04 15:56 ` Jeff King
  2013-06-04 17:26   ` Matt McClure
@ 2013-06-04 17:28   ` Junio C Hamano
  2013-06-04 17:44     ` Jeff King
  1 sibling, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2013-06-04 17:28 UTC (permalink / raw)
  To: Jeff King; +Cc: Matt McClure, git

Jeff King <peff@peff.net> writes:

> 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).

It is entirely unclear who the first child is, so I tend to think
that they have to be mutually exclusive.

>> 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.

What the command does when it "respects" it is unclear to me.
In a history like this:

---A---B---C
    \       \
     E---F---G---H

and starting at H, pretend everything that happened in, B, C, E and
F since A was done by G?  Who gets the blame for what A or H did?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Can `git blame` show the date that each line was merged?
  2013-06-04 17:28   ` Junio C Hamano
@ 2013-06-04 17:44     ` Jeff King
  0 siblings, 0 replies; 5+ messages in thread
From: Jeff King @ 2013-06-04 17:44 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Matt McClure, git

On Tue, Jun 04, 2013 at 10:28:06AM -0700, Junio C Hamano wrote:

> > (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).
> 
> It is entirely unclear who the first child is, so I tend to think
> that they have to be mutually exclusive.

That's my thinking, too, but I didn't want to rule out somebody thinking
of something clever.

> > 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.
> 
> What the command does when it "respects" it is unclear to me.
> In a history like this:
> 
> ---A---B---C
>     \       \
>      E---F---G---H
> 
> and starting at H, pretend everything that happened in, B, C, E and
> F since A was done by G?  Who gets the blame for what A or H did?

In general, I would expect "git blame" with revision arguments to behave
as if it was fed the history graph (including parent rewriting). So in
this case, I would think it would blame everything before G on G
(assuming there are no merges before A), and everything in H would be
"not yet committed".

That being said, we do not seem to rewrite parents for min/max parent
cases even in "git log". I'm not sure why, nor can I seem to provoke it
with simplification options. So maybe I am missing something clever.

-Peff

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-06-04 17:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2013-06-04 17:26   ` Matt McClure
2013-06-04 17:28   ` Junio C Hamano
2013-06-04 17:44     ` Jeff King

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).