git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [feature request] git: tags instead of commit IDs in blame output

From
Jean Delvare <khali@linux-fr.org>
Date
Aug 24, 2010, 12:54 UTC
Message-ID
<20100824145426.38b1fb15@hyperion.delvare>
In-Reply-To
<201008211210.23280.johan@herland.net>
Hi Johan,
On Sat, 21 Aug 2010 12:10:22 +0200, Johan Herland wrote:
Show 29 quoted lines
> On Saturday 21 August 2010, Jean Delvare wrote:
> > Hi there,
> > 
> > I have a feature request for git. In the output of "git blame", I would
> > like to be able to see tags instead of commit IDs in front of each
> > line. Basically, I would like to know the first tag which was added
> > after the last change of every line. Icing on the cake would be the
> > possibility to filter out some tags (for example to ignore release
> > candidate tags) but I could easily live without that.
> > 
> > Does it make sense?
> > Would it be difficult to implement?
> 
> To me, it seems what you want to do is convert the commit ID in front of 
> every blame-line into the result of running 'git name-rev' (or 'git 
> describe') on that line.
> 
> To that effect something like this should work:
> 
>   git blame <file> |
>   while read sha1 rest
>   do
>       tag=$(git name-rev --tags --name-only $sha1) &&
>       echo "$tag $rest"
>   done
> 
> Of course, if you're doing this at a bigger scale, you want to wrap this in 
> a script that (1) caches commitID -> tag mappings, and that (2) runs 'git 
> name-rev in its --stdin mode'.

Thanks for the very valuable suggestion. Obviously, the fact that the above command took over an hour to complete on a 1000-line file as kind of an issue ;) I did suspect this performance issue originally, which is why I thought it would be better if git itself would implement the feature. That being said... git name-rev's --stdin option seems to be doing all the hard caching work already:

git blame -l <file> | git name-rev --tags --name-only --stdin

does almost what I want, and is reasonably fast (13 seconds for the same file.) I'll need to do some reformatting work to extract the tag from the symbolic names (which in turn should almost fix the alignment), but this is nothing a few lines of shell scripting can't do.

So, thanks a lot again!
-- 
Jean Delvare
Previous: Johan HerlandNext: Johan Herland
Message 3 of 5 in “[feature request] git: tags instead of commit IDs in blame output”
  1. Jean DelvareAug 21, 2010
  2. Johan HerlandAug 21, 2010
  3. Jean DelvareAug 24, 2010
  4. Johan HerlandAug 24, 2010
  5. Jean DelvareAug 25, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.