Merge branch 'maint'
[gitweb.git] / git-svn.perl
index 90f3bc18b959fb38b410c69d14eda30ba084dfd9..4be85768949f037a0a91c2b8a4ff9ce0e220ade3 100755 (executable)
@@ -141,6 +141,8 @@ BEGIN
                          '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');
@@ -1064,7 +1088,10 @@ sub init_remote_config {
 
 sub find_by_url { # repos_root and, path are optional
        my ($class, $full_url, $repos_root, $path) = @_;
+
        return undef unless defined $full_url;
+       remove_username($full_url);
+       remove_username($repos_root) if defined $repos_root;
        my $remotes = read_all_remotes();
        if (defined $full_url && defined $repos_root && !defined $path) {
                $path = $full_url;
@@ -1072,6 +1099,7 @@ sub find_by_url { # repos_root and, path are optional
        }
        foreach my $repo_id (keys %$remotes) {
                my $u = $remotes->{$repo_id}->{url} or next;
+               remove_username($u);
                next if defined $repos_root && $repos_root ne $u;
 
                my $fetch = $remotes->{$repo_id}->{fetch} || {};