git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [feature request] git: tags instead of commit IDs in blame output
@ 2010-08-21  7:53 Jean Delvare
  2010-08-21 10:10 ` Johan Herland
  0 siblings, 1 reply; 5+ messages in thread
From: Jean Delvare @ 2010-08-21  7:53 UTC (permalink / raw)
  To: Git mailing list

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?

At the moment I am using a custom tool when I need to see this output,
but being backed-up by quilt, it's quite slow and disk-consuming. I
would love to be able to get rid of it and use only git.

Thanks,
-- 
Jean Delvare

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

* Re: [feature request] git: tags instead of commit IDs in blame output
  2010-08-21  7:53 [feature request] git: tags instead of commit IDs in blame output Jean Delvare
@ 2010-08-21 10:10 ` Johan Herland
  2010-08-24 12:54   ` Jean Delvare
  0 siblings, 1 reply; 5+ messages in thread
From: Johan Herland @ 2010-08-21 10:10 UTC (permalink / raw)
  To: git; +Cc: Jean Delvare

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


Have fun! :)

...Johan

-- 
Johan Herland, <johan@herland.net>
www.herland.net

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

* Re: [feature request] git: tags instead of commit IDs in blame output
  2010-08-21 10:10 ` Johan Herland
@ 2010-08-24 12:54   ` Jean Delvare
  2010-08-24 14:53     ` Johan Herland
  0 siblings, 1 reply; 5+ messages in thread
From: Jean Delvare @ 2010-08-24 12:54 UTC (permalink / raw)
  To: Johan Herland; +Cc: git

Hi Johan,

On Sat, 21 Aug 2010 12:10:22 +0200, Johan Herland wrote:
> 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

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

* Re: [feature request] git: tags instead of commit IDs in blame output
  2010-08-24 12:54   ` Jean Delvare
@ 2010-08-24 14:53     ` Johan Herland
  2010-08-25  7:32       ` Jean Delvare
  0 siblings, 1 reply; 5+ messages in thread
From: Johan Herland @ 2010-08-24 14:53 UTC (permalink / raw)
  To: Jean Delvare; +Cc: git

On Tuesday 24 August 2010, Jean Delvare wrote:
> On Sat, 21 Aug 2010 12:10:22 +0200, Johan Herland wrote:
> > 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.

Yes, everything would be easier and faster if git itself implemented it. 
Aka. infinite feature creep... This obviously does not scale.

Instead, Git tries to provide the building blocks that you can string 
together to produce the exact result you're looking for.

> 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 did the same experiment on a much larger file (~19000 lines), and got:

  27.94s git blame -l <file>

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

which suggests that the git name-rev process only adds ~1% to the total 
runtime.

> I'll need to do some reformatting work to extract the tag 
> from the symbolic names (which in turn should almost fix the
> alignment),

...only if all the tag names happen to have the same length.

> but this is nothing a few lines of shell scripting can't do.

I don't see why you need to remove the suffix from the tag name. You're 
simply removing information that could be used to look up the exact 
commit resposible for each line. And it's not like the tag name is 
completely unreadable unless you remove the suffix...


...Johan

-- 
Johan Herland, <johan@herland.net>
www.herland.net

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

* Re: [feature request] git: tags instead of commit IDs in blame output
  2010-08-24 14:53     ` Johan Herland
@ 2010-08-25  7:32       ` Jean Delvare
  0 siblings, 0 replies; 5+ messages in thread
From: Jean Delvare @ 2010-08-25  7:32 UTC (permalink / raw)
  To: Johan Herland; +Cc: git

Hi Johan,

On Tue, 24 Aug 2010 16:53:49 +0200, Johan Herland wrote:
> On Tuesday 24 August 2010, Jean Delvare wrote:
> > On Sat, 21 Aug 2010 12:10:22 +0200, Johan Herland wrote:
> > > 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.
> 
> Yes, everything would be easier and faster if git itself implemented it. 
> Aka. infinite feature creep... This obviously does not scale.
> 
> Instead, Git tries to provide the building blocks that you can string 
> together to produce the exact result you're looking for.

Yes, I get the idea now, it makes a lot of sense.

> > 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 did the same experiment on a much larger file (~19000 lines), and got:
> 
>   27.94s git blame -l <file>
> 
>   28.31s git blame -l <file> | git name-rev --tags --name-only --stdin
> 
> which suggests that the git name-rev process only adds ~1% to the total 
> runtime.
> 
> > I'll need to do some reformatting work to extract the tag 
> > from the symbolic names (which in turn should almost fix the
> > alignment),
> 
> ...only if all the tag names happen to have the same length.

Exactly. Which is the case for me at the moment, and if it ever
changes, I'll deal with it. I guess a simple printf will do.

> > but this is nothing a few lines of shell scripting can't do.
> 
> I don't see why you need to remove the suffix from the tag name. You're 
> simply removing information that could be used to look up the exact 
> commit resposible for each line. And it's not like the tag name is 
> completely unreadable unless you remove the suffix...

I'm not claiming that my approach is the universal solution to
anything. It's just what I need in specific cases, and what my old tool
was doing. If my needs evolve in the future, maybe I'll stop stripping
the extra information. But for the time being, I value conciseness over
completeness.

And for the interested, if any, here's the small script I came up with:

#!/bin/sh

if [ -z "$1" ]
then
	echo "File?"
	exit 1
fi

# Replace commit IDs with symbolic names, then strip symbolic names
# to tags, and finally strip the -rc part of tags.
git blame -l "$1" | \
	git name-rev --tags --name-only --stdin | \
	sed -e 's/^\([^~ ]*\)~[^ ]*/\1/' -e 's/^\([^ ]*\)-rc[0-9][0-9]*/\1/'


-- 
Jean Delvare

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

end of thread, other threads:[~2010-08-25  7:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-21  7:53 [feature request] git: tags instead of commit IDs in blame output Jean Delvare
2010-08-21 10:10 ` Johan Herland
2010-08-24 12:54   ` Jean Delvare
2010-08-24 14:53     ` Johan Herland
2010-08-25  7:32       ` Jean Delvare

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).