From: Adam Roben <aroben@apple.com>
Date: Sun, 29 Apr 2007 08:35:27 +0000 (-0700)
Subject: git-svn: Add 'find-rev' command
X-Git-Tag: v1.5.1.3~4
X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b3cb7e4582410c7fcaa531a2283b43499eb8fb22;p=git.git

git-svn: Add 'find-rev' command

This patch adds a new 'find-rev' command to git-svn that lets you easily
translate between SVN revision numbers and git tree-ish.

Signed-off-by: Adam Roben <aroben@apple.com>
Acked-by: Eric Wong <normalperson@yhbt.net>
Signed-off-by: Junio C Hamano <junkio@cox.net>
---

diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt
index a35b9de3b..62d7ef8be 100644
--- a/Documentation/git-svn.txt
+++ b/Documentation/git-svn.txt
@@ -161,8 +161,9 @@ Any other arguments are passed directly to `git log'
 --
 'find-rev'::
 	When given an SVN revision number of the form 'rN', returns the
-	corresponding git commit hash.  When given a tree-ish, returns the
-	corresponding SVN revision number.
+	corresponding git commit hash (this can optionally be followed by a
+	tree-ish to specify which branch should be searched).  When given a
+	tree-ish, returns the corresponding SVN revision number.
 
 'set-tree'::
 	You should consider using 'dcommit' instead of this command.
diff --git a/git-svn.perl b/git-svn.perl
index 6f509f85e..6657e100f 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -434,17 +434,16 @@ sub cmd_find_rev {
 	my $revision_or_hash = shift;
 	my $result;
 	if ($revision_or_hash =~ /^r\d+$/) {
-		my $desired_revision = substr($revision_or_hash, 1);
-		my ($fh, $ctx) = command_output_pipe('rev-list', 'HEAD');
-		while (my $hash = <$fh>) {
-			chomp($hash);
-			my (undef, $rev, undef) = cmt_metadata($hash);
-			if ($rev && $rev eq $desired_revision) {
-				$result = $hash;
-				last;
-			}
+		my $head = shift;
+		$head ||= 'HEAD';
+		my @refs;
+		my (undef, undef, undef, $gs) = working_head_info($head, \@refs);
+		unless ($gs) {
+			die "Unable to determine upstream SVN information from ",
+			    "$head history\n";
 		}
-		command_close_pipe($fh, $ctx);
+		my $desired_revision = substr($revision_or_hash, 1);
+		$result = $gs->rev_db_get($desired_revision);
 	} else {
 		my (undef, $rev, undef) = cmt_metadata($revision_or_hash);
 		$result = $rev;