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>
Adam Roben committed
Apr 29, 2007 at 01:35 UTC
b3cb7e4582410c7fcaa531a2283b43499eb8fb22
2 files changed
+12
-12
Documentation/git-svn.txt
+3
-2
@@ -161,8 +161,9 @@ Any other arguments are passed directly to `git log'
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.
164
+ corresponding git commit hash (this can optionally be followed by a
165
+ tree-ish to specify which branch should be searched). When given a
166
+ tree-ish, returns the corresponding SVN revision number.
167
168
'set-tree'::
169
You should consider using 'dcommit' instead of this command.
git-svn.perl
+9
-10
@@ -434,17 +434,16 @@ 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
- }
437
+ my $head = shift;
438
+ $head ||= 'HEAD';
439
+ my @refs;
440
+ my (undef, undef, undef, $gs) = working_head_info($head, \@refs);
441
+ unless ($gs) {
442
+ die "Unable to determine upstream SVN information from ",
443
+ "$head history\n";
444
}
447
- command_close_pipe($fh, $ctx);
445
+ my $desired_revision = substr($revision_or_hash, 1);
446
+ $result = $gs->rev_db_get($desired_revision);
447
} else {
448
my (undef, $rev, undef) = cmt_metadata($revision_or_hash);
449
$result = $rev;