From: Martin Langhoff <martin@catalyst.net.nz>
To: git@vger.kernel.org
Cc: Martin Langhoff <martin@catalyst.net.nz>
Subject: [PATCH] Add git-findtags
Date: Wed, 12 Oct 2005 16:19:29 +1300 [thread overview]
Message-ID: <1129087169926-git-send-email-martin@catalyst.net.nz> (raw)
In-Reply-To:
A short perl script that will walk the tag refs, tag objects, and even commit
objects in its quest to figure out whether the given SHA1 (for a commit or
tree) was ever tagged.
Usage: git-findtags.perl [ -t ] <commit-or-tree-sha1>
Signed-off-by: Martin Langhoff <martin@catalyst.net.nz>
---
Makefile | 3 ++
git-findtags.perl | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 1 deletions(-)
create mode 100755 git-findtags.perl
applies-to: ef9b5c2cb61cf509adf2f5ef37fa1db517291f48
58597ae99b77a690a788d2f096cecc1b7ae809fd
diff --git a/Makefile b/Makefile
index 8697d52..a5d9cd4 100644
--- a/Makefile
+++ b/Makefile
@@ -93,7 +93,8 @@ SCRIPT_SH = \
SCRIPT_PERL = \
git-archimport.perl git-cvsimport.perl git-relink.perl \
- git-rename.perl git-shortlog.perl git-fmt-merge-msg.perl
+ git-rename.perl git-shortlog.perl git-fmt-merge-msg.perl \
+ git-findtags.perl
SCRIPT_PYTHON = \
git-merge-recursive.py
diff --git a/git-findtags.perl b/git-findtags.perl
new file mode 100755
index 0000000..40eb284
--- /dev/null
+++ b/git-findtags.perl
@@ -0,0 +1,70 @@
+#!/usr/bin/perl -w
+#
+# Copyright (c) 2005 Martin Langhoff
+#
+# Walk the tags and find if they match a commit
+# expects a SHA1 of a commit. Option -t enables
+# searching trees too.
+#
+
+use strict;
+use File::Basename;
+use Getopt::Std;
+
+my $git_dir = $ENV{GIT_DIR} || '.git';
+
+# options
+our $opt_t;
+getopts("t") || usage();
+
+my @tagfiles = `find $git_dir/refs/tags -follow -type f`; # haystack
+my $target = shift @ARGV; # needle
+
+unless ($target) {
+ usage();
+}
+
+
+foreach my $tagfile (@tagfiles) {
+ chomp $tagfile;
+ my $tagid = quickread($tagfile);
+ chomp $tagid;
+
+ # grab the first 2 lines (the whole tag could be large)
+ my $tagobj = `git-cat-file tag $tagid | head -n2 `;
+ if ($tagobj =~ m/^type commit$/m) { # only deal with commits
+
+ if ($tagobj =~ m/^object $target$/m) { # match on the commit
+ print basename($tagfile) . "\n";
+
+ } elsif ( $opt_t && # follow the commit
+ $tagobj =~ m/^object (\S+)$/m) { # and try to match trees
+ my $commitid = $1;
+ my $commitobj = `git-cat-file commit $commitid | head -n1`;
+ chomp $commitobj;
+ $commitobj =~ m/^tree (\S+)$/;
+ my $treeid = $1;
+ if ($target eq $treeid) {
+ print basename($tagfile) . "\n";
+ }
+ }
+ }
+}
+
+sub quickread {
+ my $file = shift;
+ local $/; undef $/; # slurp mode
+ open FILE, "<$file"
+ or die "Cannot open $file : $!";
+ my $content = <FILE>;
+ close FILE;
+ return $content;
+}
+
+sub usage {
+ print STDERR <<END;
+Usage: ${\basename $0} # find tags for a commit or tree
+ [ -t ] <commit-or-tree-sha1>
+END
+ exit(1);
+}
---
0.99.8.GIT
next reply other threads:[~2005-10-12 3:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-12 3:19 Martin Langhoff [this message]
2005-10-12 5:19 ` [PATCH] Add git-findtags Junio C Hamano
[not found] ` <46a038f90510122117mb466722n531dc66bac141ea1@mail.gmail.com>
2005-10-13 5:18 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1129087169926-git-send-email-martin@catalyst.net.nz \
--to=martin@catalyst.net.nz \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).