{"thread":{"id":"17855","subject":"Blamming a diff between two commits?","startedAt":"2009-02-17T13:16:17Z","lastAt":"2009-02-22T19:11:38Z","messageCount":10,"participants":["Samuel Lucas Vaz de Mello","Johannes Schindelin","Thomas Rast","Matthieu Moy","Jan Hudec"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"105134","messageId":"499AB8A1.7090909@datacom.ind.br","threadId":"17855","inReplyTo":null,"subject":"Blamming a diff between two commits?","fromName":"Samuel Lucas Vaz de Mello","fromEmail":"samuellucas@datacom.ind.br","sentAt":"2009-02-17T13:16:17Z","receivedAt":"2009-02-17T13:16:17Z","isPatch":false,"sender":{"key":"samuellucas@datacom.ind.br","avatar":null},"body":"Hi,\n\nIs there any way to git blame (or annotate) a diff between two commits?\n\nI'm looking for something that produce something like this:\n\n                              /**\n85a02065 (samuel 2009-01-02) - * \\brief      Define a participacao da porta estatica/dinamica\n85a02065 (samuel 2009-01-02) - * \\param      unit            indice da unidade\ne106303a (arthur 2009-01-17) - * \\param\t     extraparam      extra parameter\n85a02065 (samuel 2009-01-02) - * \\param      port            indice da porta\n50e22e7d (fabian 2009-01-09) - * \\param      deleted         param to be deleted\n85a02065 (samuel 2009-01-02) + * \\brief      Sets port membership on a static / dynamic \n85a02065 (samuel 2009-01-02) + * \\param      unit            unit index\n85a02065 (samuel 2009-01-02) + * \\param      port            port index\ne106303a (arthur 2009-01-17) + * \\param\t     another         another index\n                               * \\return     0 if Ok; -1 in error\n                               */\n\nThis would be useful for code reviews. I can use a diff containing all changes committed to a branch, for example, in the last 10 days to review. Doing this instead of reviewing individual commit patches save us from waste time analyzing code that has already been changed/fixed. \n\nUsing a git-blame in the resulting file give me the commits for the lines added, but not for the deleted ones.\n\nAny suggestion on how to do this?\n\n\nThanks,\n\n - Samuel\n"},{"id":"105137","messageId":"alpine.DEB.1.00.0902171452060.6185@intel-tinevez-2-302","threadId":"17855","inReplyTo":"499AB8A1.7090909@datacom.ind.br","subject":"Re: Blamming a diff between two commits?","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-02-17T13:53:46Z","receivedAt":"2009-02-17T13:53:46Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 17 Feb 2009, Samuel Lucas Vaz de Mello wrote:\n\n> Is there any way to git blame (or annotate) a diff between two commits?\n\nIf you do not mean the diff, but a commit range:\n\n\t$ git blame A..B -- file\n\n\"Unblameable\" lines will be shown with a prefix ^A (not literal, of \ncourse, but the short commit name of A).\n\nHth,\nDscho\n"},{"id":"105151","messageId":"vpqocx1qhwx.fsf@bauges.imag.fr","threadId":"17855","inReplyTo":"499AB8A1.7090909@datacom.ind.br","subject":"Re: Blamming a diff between two commits?","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2009-02-17T14:03:58Z","receivedAt":"2009-02-17T14:03:58Z","isPatch":false,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"Samuel Lucas Vaz de Mello <samuellucas@datacom.ind.br> writes:\n\n> Hi,\n>\n> Is there any way to git blame (or annotate) a diff between two commits?\n\nI don't think this is implemented (but would be nice).\n\n> Using a git-blame in the resulting file give me the commits for the\n> lines added, but not for the deleted ones.\n\nA preliminary implementation of \"git blame --reverse\" was proposed by\nJunio here:\n\n  http://kerneltrap.org/mailarchive/git/2008/4/3/1338234\n\nAnd an approximation of it is proposed in the thread:\n\n  http://kerneltrap.org/mailarchive/git/2008/4/3/1343554\n\nI don't know the status of this patch (dropped?).\n\n-- \nMatthieu\n"},{"id":"105148","messageId":"200902171509.21434.trast@student.ethz.ch","threadId":"17855","inReplyTo":"499AB8A1.7090909@datacom.ind.br","subject":"Re: Blamming a diff between two commits?","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-02-17T14:09:18Z","receivedAt":"2009-02-17T14:09:18Z","isPatch":false,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Samuel Lucas Vaz de Mello wrote:\n> Is there any way to git blame (or annotate) a diff between two\n> commits?\n\nPiecing it together from existing tools isn't really hard, and made\nfor a nice distraction.\n\nCall it as './git-blame-diff.perl HEAD^ HEAD' or so.\n\nThis lacks proper argument checking and a chdir to the repository top\nlevel.  Maybe you could fill in the gaps and shape it as a contrib\npatch?  For bonus points, change it so that the workdir version can be\nused as the new side of the diff, by omitting the second argument.\n\n--- 8< ---\n#!/usr/bin/perl -w\n\nsub parse_hunk_header {\n\tmy ($line) = @_;\n\tmy ($o_ofs, $o_cnt, $n_ofs, $n_cnt) =\n\t    $line =~ /^@@ -(\\d+)(?:,(\\d+))? \\+(\\d+)(?:,(\\d+))? @@/;\n\t$o_cnt = 1 unless defined $o_cnt;\n\t$n_cnt = 1 unless defined $n_cnt;\n\treturn ($o_ofs, $o_cnt, $n_ofs, $n_cnt);\n}\n\nsub get_blame_prefix {\n\tmy ($line) = @_;\n\t$line =~ /^([0-9a-f]+\\s+\\([^\\)]+\\))/ or die \"bad blame output: $line\";\n\treturn $1;\n}\n\nmy ($oldrev, $newrev) = @ARGV;\nopen($diff, '-|', 'git', '--no-pager', 'diff', $oldrev, $newrev) or die;\n\nmy ($pre, $post);\nmy $filename;\nwhile (<$diff>) {\n\tif (m{^diff --git ./(.*) ./\\1$}) {\n\t\t$filename = $1;\n\t} elsif (m{^(\\+\\+\\+|---) ./$filename$}) {\n\t\t# ignore\n\t} elsif (m{^@@ }) {\n\t\tmy ($o_ofs, $o_cnt, $n_ofs, $n_cnt)\n\t\t\t= parse_hunk_header($_);\n\t\tmy $o_end = $o_ofs + $o_cnt;\n\t\tmy $n_end = $n_ofs + $n_cnt;\n\t\topen($pre, '-|', 'git', 'blame', \"-L$o_ofs,$o_end\",\n\t\t     $oldrev, '--', $filename) or die;\n\t\topen($post, '-|', 'git', 'blame', \"-L$n_ofs,$n_end\",\n\t\t     $newrev, '--', $filename) or die;\n\t} elsif (m{^ }) {\n\t\tprint get_blame_prefix(scalar <$pre>), \"\\t\", $_;\n\t\tscalar <$post>; # discard\n\t} elsif (m{^\\-}) {\n\t\tprint get_blame_prefix(scalar <$pre>), \"\\t\", $_;\n\t} elsif (m{^\\+}) {\n\t\tprint get_blame_prefix(scalar <$post>), \"\\t\", $_;\n\t} \n}\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"105149","messageId":"499AC530.7000408@datacom.ind.br","threadId":"17855","inReplyTo":"alpine.DEB.1.00.0902171452060.6185@intel-tinevez-2-302","subject":"Re: Blamming a diff between two commits?","fromName":"Samuel Lucas Vaz de Mello","fromEmail":"samuellucas@datacom.ind.br","sentAt":"2009-02-17T14:09:52Z","receivedAt":"2009-02-17T14:09:52Z","isPatch":false,"sender":{"key":"samuellucas@datacom.ind.br","avatar":null},"body":"Johannes Schindelin wrote:\n> \n>> Is there any way to git blame (or annotate) a diff between two commits?\n> \n> If you do not mean the diff, but a commit range:\n> \n> \t$ git blame A..B -- file\n> \n> \"Unblameable\" lines will be shown with a prefix ^A (not literal, of \n> course, but the short commit name of A).\n> \n\nThis work fine for lines that were added or changed, but not for deleted lines.\n\nIf a commit in the range just delete a couple of lines and adds nothing, the whole file is marked as \"unblameable\" as the deleted lines doesn't exist anymore.\n\n - Samuel\n"},{"id":"105155","messageId":"alpine.DEB.1.00.0902171526470.6185@intel-tinevez-2-302","threadId":"17855","inReplyTo":"499AC530.7000408@datacom.ind.br","subject":"Re: Blamming a diff between two commits?","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-02-17T14:27:22Z","receivedAt":"2009-02-17T14:27:22Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 17 Feb 2009, Samuel Lucas Vaz de Mello wrote:\n\n> Johannes Schindelin wrote:\n> > \n> >> Is there any way to git blame (or annotate) a diff between two commits?\n> > \n> > If you do not mean the diff, but a commit range:\n> > \n> > \t$ git blame A..B -- file\n> > \n> > \"Unblameable\" lines will be shown with a prefix ^A (not literal, of \n> > course, but the short commit name of A).\n> > \n> \n> This work fine for lines that were added or changed, but not for deleted \n> lines.\n> \n> If a commit in the range just delete a couple of lines and adds nothing, \n> the whole file is marked as \"unblameable\" as the deleted lines doesn't \n> exist anymore.\n\nYou might want to add the --reverse option for that.\n\nCiao,\nDscho\n"},{"id":"105647","messageId":"200902202104.37695.trast@student.ethz.ch","threadId":"17855","inReplyTo":"200902171509.21434.trast@student.ethz.ch","subject":"Re: Blamming a diff between two commits?","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-02-20T20:04:31Z","receivedAt":"2009-02-20T20:04:31Z","isPatch":false,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Thomas Rast wrote:\n> Samuel Lucas Vaz de Mello wrote:\n> > Is there any way to git blame (or annotate) a diff between two\n> > commits?\n[...]\n> Call it as './git-blame-diff.perl HEAD^ HEAD' or so.\n\nAny reports from the field?  Does it do what you wanted?  Does it have\nother shortcomings than the ones I mentioned:\n\n> This lacks proper argument checking and a chdir to the repository top\n> level.  Maybe you could fill in the gaps and shape it as a contrib\n> patch?  For bonus points, change it so that the workdir version can be\n> used as the new side of the diff, by omitting the second argument.\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"105765","messageId":"20090222123248.GA6504@efreet.light.src","threadId":"17855","inReplyTo":"499AB8A1.7090909@datacom.ind.br","subject":"Re: Blamming a diff between two commits?","fromName":"Jan Hudec","fromEmail":"bulb@ucw.cz","sentAt":"2009-02-22T12:32:48Z","receivedAt":"2009-02-22T12:32:48Z","isPatch":false,"sender":{"key":"bulb@ucw.cz","avatar":null},"body":"On Tue, Feb 17, 2009 at 10:16:17 -0300, Samuel Lucas Vaz de Mello wrote:\n> Hi,\n> \n> Is there any way to git blame (or annotate) a diff between two commits?\n> \n> I'm looking for something that produce something like this:\n> \n>                               /**\n> 85a02065 (samuel 2009-01-02) - * \\brief      Define a participacao da porta estatica/dinamica\n> 85a02065 (samuel 2009-01-02) - * \\param      unit            indice da unidade\n> e106303a (arthur 2009-01-17) - * \\param\t     extraparam      extra parameter\n> 85a02065 (samuel 2009-01-02) - * \\param      port            indice da porta\n> 50e22e7d (fabian 2009-01-09) - * \\param      deleted         param to be deleted\n> 85a02065 (samuel 2009-01-02) + * \\brief      Sets port membership on a static / dynamic \n> 85a02065 (samuel 2009-01-02) + * \\param      unit            unit index\n> 85a02065 (samuel 2009-01-02) + * \\param      port            port index\n> e106303a (arthur 2009-01-17) + * \\param\t     another         another index\n>                                * \\return     0 if Ok; -1 in error\n>                                */\n> \n> This would be useful for code reviews. I can use a diff containing all changes committed to a branch, for example, in the last 10 days to review. Doing this instead of reviewing individual commit patches save us from waste time analyzing code that has already been changed/fixed. \n> \n> Using a git-blame in the resulting file give me the commits for the lines added, but not for the deleted ones.\n> \n> Any suggestion on how to do this?\n\nWhat about doing a diff of the blames? It should do the same thing (except\nthe +/- would be at the begining of the lines). Well, not exactly, because if\nthere was a change, that was reverted again, blames would change, so it would\nappear here, but that's probably rare enough to ignore (if you don't even\nwant to see it rather than not).\n\n-- \n\t\t\t\t\t\t Jan 'Bulb' Hudec <bulb@ucw.cz>\n"},{"id":"105811","messageId":"vpqtz6mpas3.fsf@bauges.imag.fr","threadId":"17855","inReplyTo":"20090222123248.GA6504@efreet.light.src","subject":"Re: Blamming a diff between two commits?","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2009-02-22T18:49:16Z","receivedAt":"2009-02-22T18:49:16Z","isPatch":false,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"Jan Hudec <bulb@ucw.cz> writes:\n\n> On Tue, Feb 17, 2009 at 10:16:17 -0300, Samuel Lucas Vaz de Mello wrote:\n>> Hi,\n>> \n>> Is there any way to git blame (or annotate) a diff between two commits?\n>> \n>> I'm looking for something that produce something like this:\n>> \n>>                               /**\n>> 85a02065 (samuel 2009-01-02) - * \\brief      Define a participacao da porta estatica/dinamica\n>> 85a02065 (samuel 2009-01-02) - * \\param      unit            indice da unidade\n>> e106303a (arthur 2009-01-17) - * \\param\t     extraparam      extra parameter\n>> 85a02065 (samuel 2009-01-02) - * \\param      port            indice da porta\n>> 50e22e7d (fabian 2009-01-09) - * \\param      deleted         param to be deleted\n>> 85a02065 (samuel 2009-01-02) + * \\brief      Sets port membership on a static / dynamic \n>> 85a02065 (samuel 2009-01-02) + * \\param      unit            unit index\n>> 85a02065 (samuel 2009-01-02) + * \\param      port            port index\n>> e106303a (arthur 2009-01-17) + * \\param\t     another         another index\n>>                                * \\return     0 if Ok; -1 in error\n>>                                */\n>> \n>> This would be useful for code reviews. I can use a diff containing all changes committed to a branch, for example, in the last 10 days to review. Doing this instead of reviewing individual commit patches save us from waste time analyzing code that has already been changed/fixed. \n>> \n>> Using a git-blame in the resulting file give me the commits for the lines added, but not for the deleted ones.\n>> \n>> Any suggestion on how to do this?\n>\n> What about doing a diff of the blames? It should do the same thing (except\n> the +/- would be at the begining of the lines). Well, not exactly, because if\n> there was a change, that was reverted again, blames would change, so it would\n> appear here, but that's probably rare enough to ignore (if you don't even\n> want to see it rather than not).\n\nI don't think that would do it.\n\nSuppose I have the following history (in a one-line file) :\n\nrevision: R1 -> R2 -> R3 -> R4 -> R5 -> R6\ncontent:  A  -> B  -> B  -> C  -> D  -> E \n\nIf I do a blame at revision R3, I'll get\n\nR2 B\n\nThen, at revision R6, I'd get\n\nR6 E\n\nso the diff will be\n\n- R2 B\n+ R6 E\n\nwhile the original poster actually wanted\n\n- R3 B\n+ R6 E\n\nIn the first case, the annotation for - lines tell where the removed\nline had been introduced before, while the second case tells up to\nwhich revision the line has been existing (or, it could show the\nrevision which removed it, R4 here).\n\n\n-- \nMatthieu\n"},{"id":"105814","messageId":"20090222191138.GC6504@efreet.light.src","threadId":"17855","inReplyTo":"vpqtz6mpas3.fsf@bauges.imag.fr","subject":"Re: Blamming a diff between two commits?","fromName":"Jan Hudec","fromEmail":"bulb@ucw.cz","sentAt":"2009-02-22T19:11:38Z","receivedAt":"2009-02-22T19:11:38Z","isPatch":false,"sender":{"key":"bulb@ucw.cz","avatar":null},"body":"On Sun, Feb 22, 2009 at 19:49:16 +0100, Matthieu Moy wrote:\n> Jan Hudec <bulb@ucw.cz> writes:\n> > On Tue, Feb 17, 2009 at 10:16:17 -0300, Samuel Lucas Vaz de Mello wrote:\n> >> Hi,\n> >> \n> >> Is there any way to git blame (or annotate) a diff between two commits?\n> >> [...]\n> >\n> > What about doing a diff of the blames? It should do the same thing (except\n> > the +/- would be at the begining of the lines). Well, not exactly, because if\n> > there was a change, that was reverted again, blames would change, so it would\n> > appear here, but that's probably rare enough to ignore (if you don't even\n> > want to see it rather than not).\n> \n> I don't think that would do it.\n> \n> Suppose I have the following history (in a one-line file) :\n> \n> revision: R1 -> R2 -> R3 -> R4 -> R5 -> R6\n> content:  A  -> B  -> B  -> C  -> D  -> E \n> \n> If I do a blame at revision R3, I'll get\n> \n> R2 B\n> \n> Then, at revision R6, I'd get\n> \n> R6 E\n> \n> so the diff will be\n> \n> - R2 B\n> + R6 E\n> \n> while the original poster actually wanted\n> \n> - R3 B\n> + R6 E\n> \n> In the first case, the annotation for - lines tell where the removed\n> line had been introduced before, while the second case tells up to\n> which revision the line has been existing (or, it could show the\n> revision which removed it, R4 here).\n\nYou are right, it is something different.\n\nBoth are probably useful, though -- knowing where the deleted line was\nintroduced would be useful so you can look up rationale for the old code in\nthe respective commit message and check whether the new version does not miss\nany points mentioned there. Provided you have good descriptions in the\ncomments, of course.\n\n-- \n\t\t\t\t\t\t Jan 'Bulb' Hudec <bulb@ucw.cz>\n"}]}