git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-svn: Add 'find-rev' command

From
Adam Roben <aroben@apple.com>
Date
Apr 29, 2007, 08:35 UTC
Message-ID
<1177835727239-git-send-email-aroben@apple.com>

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>
---
This is an updated version of my previous patch that takes Eric and Junio's
comments into account.
 Documentation/git-svn.txt |    6 ++++++
 git-svn.perl              |   23 +++++++++++++++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt
index a0d34e0..482c862 100644
--- a/Documentation/git-svn.txt
+++ b/Documentation/git-svn.txt
@@ -159,6 +159,12 @@ New features:
 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 (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.
 	Commit specified commit or tree objects to SVN.  This relies on
diff --git a/git-svn.perl b/git-svn.perl
index 7b5f8ab..30e4a41 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -141,6 +141,8 @@ my %cmd = (
 			  'color' => \$Git::SVN::Log::color,
 			  'pager=s' => \$Git::SVN::Log::pager,
 			} ],
+	'find-rev' => [ \&cmd_find_rev, "Translate between SVN revision numbers and tree-ish",
+			{ } ],
 	'rebase' => [ \&cmd_rebase, "Fetch and rebase your working directory",
 			{ 'merge|m|M' => \$_merge,
 			  'verbose|v' => \$_verbose,
@@ -428,6 +430,27 @@ sub cmd_dcommit {
 	command_noisy(@finish, $gs->refname);
 }
 
+sub cmd_find_rev {
+	my $revision_or_hash = shift;
+	my $result;
+	if ($revision_or_hash =~ /^r\d+$/) {
+		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";
+		}
+		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;
+	}
+	print "$result\n" if $result;
+}
+
 sub cmd_rebase {
 	command_noisy(qw/update-index --refresh/);
 	my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
-- 
1.5.2.rc0.75.g959b-dirty
Next: Eric Wong
Message 1 of 4 in “git-svn: Add 'find-rev' command”
  1. git-svn: Add 'find-rev' commandAdam Roben, Apr 29, 2007
  2. Eric WongApr 29, 2007
  3. Adam RobenApr 29, 2007
  4. Eric WongApr 29, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.