git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perl/Git.pm: add rev_parse method
@ 2008-05-30  4:43 Lea Wiemann
  2008-05-30  7:03 ` Lea Wiemann
                   ` (2 more replies)
  0 siblings, 3 replies; 32+ messages in thread
From: Lea Wiemann @ 2008-05-30  4:43 UTC (permalink / raw)
  To: git; +Cc: Lea Wiemann

The rev_parse method translates a revision name to a SHA1 hash, like
the git-rev-parse command.

Signed-off-by: Lea Wiemann <LeWiemann@gmail.com>
---

This is part of my work to extend Git.pm to create a usable
repository access abstraction layer for gitweb.

I've tested this method by calling it with a few parameters, but
there's no test suite yet.  I'll probably send a message to the
mailing list about testing Git.pm soon.

This is my first patch to Git.pm, so please let me know if there is
anything wrong with it!

 perl/Git.pm |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/perl/Git.pm b/perl/Git.pm
index d05b633..9ef8cb0 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -716,6 +716,28 @@ sub ident_person {
 	return "$ident[0] <$ident[1]>";
 }
 
+=item rev_parse ( REVISION_NAME )
+
+Look up the specified revision name and return the SHA1 hash, or
+return undef if the lookup failed.  See the git-rev-parse command.
+
+=cut
+
+sub rev_parse {
+    # We could allow for a list of revisions here.
+    my ($self, $rev_name) = @_;
+
+    my $hash;
+    try {
+        # The --default option works around rev-parse's lack of
+        # support for getopt style "--" separators (it would fail for
+        # tags named "--foo" without it).
+        $hash = $self->command_oneline("rev-parse", "--verify", "--default",
+                                       $rev_name);
+    } catch Git::Error::Command with { };
+    return undef unless defined $hash and $hash =~ /^([0-9a-fA-F]{40})$/;
+    $hash;
+}
 
 =item hash_object ( TYPE, FILENAME )
 
-- 
1.5.5.GIT

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

end of thread, other threads:[~2008-06-02 13:52 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-30  4:43 [PATCH] perl/Git.pm: add rev_parse method Lea Wiemann
2008-05-30  7:03 ` Lea Wiemann
2008-05-30  9:59   ` Petr Baudis
2008-05-30 15:15     ` Merging strategy for extending Git.pm (was: [PATCH] perl/Git.pm: add rev_parse method) Lea Wiemann
2008-05-30 23:20       ` Merging strategy for extending Git.pm Junio C Hamano
2008-05-31 11:38       ` Merging strategy for extending Git.pm (was: [PATCH] perl/Git.pm: add rev_parse method) Johannes Schindelin
2008-05-31 12:42         ` Merging strategy for extending Git.pm Lea Wiemann
2008-05-31 12:52           ` Johannes Schindelin
2008-05-30 20:28   ` [PATCH] perl/Git.pm: add rev_parse method Junio C Hamano
2008-05-30  9:50 ` Petr Baudis
2008-05-30 20:27   ` [PATCH] perl/Git.pm: add parse_rev method Lea Wiemann
2008-05-30 21:05     ` Petr Baudis
2008-05-30 21:25       ` Junio C Hamano
2008-05-30 21:44         ` Randal L. Schwartz
2008-05-30 21:59           ` Lea Wiemann
2008-05-30 22:03             ` Randal L. Schwartz
2008-05-30 22:05               ` Lea Wiemann
2008-05-30 22:19             ` Junio C Hamano
2008-05-31 11:50             ` Johannes Schindelin
2008-05-31 12:17               ` Support for old Perl versions Petr Baudis
2008-05-31 12:32                 ` Johannes Schindelin
2008-05-30 21:49         ` [PATCH] perl/Git.pm: add parse_rev method Petr Baudis
2008-05-31 13:52 ` [PATCH v2] " Lea Wiemann
2008-06-01  3:17   ` [PATCH v3] " Lea Wiemann
2008-06-01  3:17     ` Lea Wiemann
2008-06-01 17:38       ` Lea Wiemann
2008-06-01 21:54         ` Miklos Vajna
2008-06-01 22:51           ` Lea Wiemann
2008-06-02  4:59             ` Junio C Hamano
2008-06-02 13:51               ` Lea Wiemann
2008-06-01 23:09       ` [PATCH v4] perl/Git.pm: add get_hash method Lea Wiemann
2008-06-01 23:24         ` Lea Wiemann

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