Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [PATCH] Add git-findtags

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:08

Martin Langhoff [off-list ref] writes:
On 10/12/05, Junio C Hamano [off-list ref] wrote:
quoted
Martin Langhoff [off-list ref] writes:
I'm preparing a better patch based on your comments, but File::Find is
_not_ my friend, really. I really feel stupid after failing for 1hr to
use it.
Something like this?

    use strict;
    use File::Find qw(find);

    my $git_dir = $ENV{GIT_DIR} || '.git';

    my @tagfiles = ();
    find({
        follow => 1,
        wanted => sub {
            if (-f _) {
                push @tagfiles, $File::Find::name;
            }
        } }, "$git_dir/refs/tags");

    for (@tagfiles) {
        print "$_\n";
    }
quoted
BTW, wouldn't it be easier for this particular script, and more
useful in general, if something like what 'git-rev-parse' does
for commit objects when given "REV^0" is supported for tags?
I don't quite follow...
What I meant is this.

There is an existing notation "^0" which is a postfix
"dereference until you get a commit" operator.

	git-rev-parse --verify refs/tags/v0.99^0
	git-cat-file -t refs/tags/v0.99^0

does:

	1. reads SHA1 from "refs/tags/v0.99", finds the object;

        2. if it is a tag object, find the object pointed by it;
           if the result is still a tag object, then dereference
           it repeatedly;

        3. if the resulting object is a commit, let the caller
           to use it; otherwise barf.

What _might_ be useful for your application is a similar
operator, say, "refs/tags/junio-gpg-pub%", that does:

	1. reads SHA1 from "refs/tags/junio-gpg-pub", finds the
           object;

        2. if it is a tag object, find the object pointed by it;
           if the result is still a tag object, then dereference
           it repeatedly;

	3. do not worry about the type of the result.  Just
           output it.

Instead of reserving yet another letter '%', it might be better
to use something like "refs/tags/junio-gpg-pub^{tag}" as a
notation for this.  If you had something like this, you would
not have to read tag objects yourself and dereference them by
hand.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help