]> Pileus Git - ~andy/git/commitdiff
git-svn: Added 'find-rev' command
authorAdam Roben <aroben@apple.com>
Fri, 27 Apr 2007 18:57:53 +0000 (11:57 -0700)
committerJunio C Hamano <junkio@cox.net>
Sat, 28 Apr 2007 06:18:15 +0000 (23:18 -0700)
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>
Documentation/git-svn.txt
git-svn.perl

index a0d34e0058d721e655fd23c36415aaaecfa0c666..a35b9de3bfde036391b0ac869bf927361d3d4c67 100644 (file)
@@ -159,6 +159,11 @@ 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.  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
index 7b5f8ab3be6639e682dc6b0d5a53412f1078ba54..4be85768949f037a0a91c2b8a4ff9ce0e220ade3 100755 (executable)
@@ -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,28 @@ 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 $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;
+                       }
+               }
+               command_close_pipe($fh, $ctx);
+       } 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');