git-svn: Added '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>
Adam Roben committed
Apr 27, 2007 at 11:57 UTC
26e60160a074747fbe8866ddac4e0c7660c17ff6
2 files changed
+29
Documentation/git-svn.txt
+5
@@ -159,6 +159,11 @@ New features:
159
Any other arguments are passed directly to `git log'
160
161
--
162
+'find-rev'::
163
+ When given an SVN revision number of the form 'rN', returns the
164
+ corresponding git commit hash. When given a tree-ish, returns the
165
+ corresponding SVN revision number.
166
+
167
'set-tree'::
168
You should consider using 'dcommit' instead of this command.
169
Commit specified commit or tree objects to SVN. This relies on
git-svn.perl
+24
@@ -141,6 +141,8 @@ my %cmd = (
141
'color' => \$Git::SVN::Log::color,
142
'pager=s' => \$Git::SVN::Log::pager,
143
} ],
144
+ 'find-rev' => [ \&cmd_find_rev, "Translate between SVN revision numbers and tree-ish",
145
+ { } ],
146
'rebase' => [ \&cmd_rebase, "Fetch and rebase your working directory",
147
{ 'merge|m|M' => \$_merge,
148
'verbose|v' => \$_verbose,
@@ -428,6 +430,28 @@ sub cmd_dcommit {
430
command_noisy(@finish, $gs->refname);
431
}
432
433
+sub cmd_find_rev {
434
+ my $revision_or_hash = shift;
435
+ my $result;
436
+ if ($revision_or_hash =~ /^r\d+$/) {
437
+ my $desired_revision = substr($revision_or_hash, 1);
438
+ my ($fh, $ctx) = command_output_pipe('rev-list', 'HEAD');
439
+ while (my $hash = <$fh>) {
440
+ chomp($hash);
441
+ my (undef, $rev, undef) = cmt_metadata($hash);
442
+ if ($rev && $rev eq $desired_revision) {
443
+ $result = $hash;
444
+ last;
445
+ }
446
+ }
447
+ command_close_pipe($fh, $ctx);
448
+ } else {
449
+ my (undef, $rev, undef) = cmt_metadata($revision_or_hash);
450
+ $result = $rev;
451
+ }
452
+ print "$result\n" if $result;
453
+}
454
+
455
sub cmd_rebase {
456
command_noisy(qw/update-index --refresh/);
457
my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');