{"thread":{"id":"14166","subject":"[PATCH] git-svn: follow revisions of svm-mirrored repositories","startedAt":"2008-06-26T16:24:12Z","lastAt":"2008-06-26T16:24:12Z","messageCount":1,"participants":["João Abecasis"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"81300","messageId":"7bf6f1d20806260924r68a8ac89i95fad1d5f0c685de@mail.gmail.com","threadId":"14166","inReplyTo":null,"subject":"[PATCH] git-svn: follow revisions of svm-mirrored repositories","fromName":"João Abecasis","fromEmail":"joao@abecasis.name","sentAt":"2008-06-26T16:24:12Z","receivedAt":"2008-06-26T16:24:12Z","isPatch":true,"sender":{"key":"joao@abecasis.name","avatar":"https://gravatar.com/avatar/6c28d507fdac73de84e9ea793d82c718ae46c5e96ef25c9171c9b7f697131c4e?d=mp&s=160"},"body":"From a4cd092cd1aeae954378038d24f93af930610cc8 Mon Sep 17 00:00:00 2001\nFrom: =?utf-8?q?Jo=C3=A3o=20Abecasis?= <joao@abecasis.name>\nDate: Fri, 13 Jun 2008 20:32:57 -0500\nSubject: [PATCH] git-svn: follow revisions of svm-mirrored repositories\nMIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit\n\nAlthough git-svn keeps track of source revisions in svm-mirrored\nrepositories, it doesn't use that information in all places.\n\nThis fixes working_head_info and Git::SVN::find_by_url to work with\nmirrored repositories when useSvmProps is set. At least the commands\nfind-rev and rebase, which didn't work for me with svm-mirrored\nrepositories, are now working.\n\nSigned-off-by: João Abecasis <joao@abecasis.name>\n---\n git-svn.perl                     |   36 ++++++++++++++++++++++++++++++++----\n t/t9110-git-svn-use-svm-props.sh |    9 +++++++++\n 2 files changed, 41 insertions(+), 4 deletions(-)\n\ndiff --git a/git-svn.perl b/git-svn.perl\nindex 4c9c59b..4df6c71 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -537,13 +537,13 @@ sub cmd_find_rev {\n \t\tmy $head = shift;\n \t\t$head ||= 'HEAD';\n \t\tmy @refs;\n-\t\tmy (undef, undef, undef, $gs) = working_head_info($head, \\@refs);\n+\t\tmy (undef, undef, $uuid, $gs) = working_head_info($head, \\@refs);\n \t\tunless ($gs) {\n \t\t\tdie \"Unable to determine upstream SVN information from \",\n \t\t\t    \"$head history\\n\";\n \t\t}\n \t\tmy $desired_revision = substr($revision_or_hash, 1);\n-\t\t$result = $gs->rev_map_get($desired_revision);\n+\t\t$result = $gs->rev_map_get($desired_revision, $uuid);\n \t} else {\n \t\tmy (undef, $rev, undef) = cmt_metadata($revision_or_hash);\n \t\t$result = $rev;\n@@ -1160,7 +1160,7 @@ sub working_head_info {\n \t\tif (defined $url && defined $rev) {\n \t\t\tnext if $max{$url} and $max{$url} < $rev;\n \t\t\tif (my $gs = Git::SVN->find_by_url($url)) {\n-\t\t\t\tmy $c = $gs->rev_map_get($rev);\n+\t\t\t\tmy $c = $gs->rev_map_get($rev, $uuid);\n \t\t\t\tif ($c && $c eq $hash) {\n \t\t\t\t\tclose $fh; # break the pipe\n \t\t\t\t\treturn ($url, $rev, $uuid, $gs);\n@@ -1414,11 +1414,16 @@ sub fetch_all {\n\n sub read_all_remotes {\n \tmy $r = {};\n+        my $usesvmprops = eval {\n+\t\tcommand_oneline(qw/config --bool svn.useSvmProps/) } eq 'true';\n \tforeach (grep { s/^svn-remote\\.// } command(qw/config -l/)) {\n \t\tif (m!^(.+)\\.fetch=\\s*(.*)\\s*:\\s*refs/remotes/(.+)\\s*$!) {\n \t\t\tmy ($remote, $local_ref, $remote_ref) = ($1, $2, $3);\n \t\t\t$local_ref =~ s{^/}{};\n \t\t\t$r->{$remote}->{fetch}->{$local_ref} = $remote_ref;\n+\t\t\t$r->{$remote}->{svm} = {} if $usesvmprops;\n+\t\t} elsif (m!^(.+)\\.usesvmprops=\\s*(.*)\\s*$!) {\n+\t\t\t$r->{$1}->{svm} = {};\n \t\t} elsif (m!^(.+)\\.url=\\s*(.*)\\s*$!) {\n \t\t\t$r->{$1}->{url} = $2;\n \t\t} elsif (m!^(.+)\\.(branches|tags)=\n@@ -1435,6 +1440,21 @@ sub read_all_remotes {\n \t\t\t}\n \t\t}\n \t}\n+\n+\tmap {\n+\t\tif (defined $r->{$_}->{svm}) {\n+\t\t\tmy $svm;\n+\t\t\teval {\n+\t\t\t\tmy $section = \"svn-remote.$_\";\n+\t\t\t\t$svm = {\n+\t\t\t\t\tsource => tmp_config('--get', \"$section.svm-source\"),\n+\t\t\t\t\treplace => tmp_config('--get', \"$section.svm-replace\"),\n+\t\t\t\t}\n+\t\t\t};\n+\t\t\t$r->{$_}->{svm} = $svm;\n+\t\t}\n+\t} keys %$r;\n+\n \t$r;\n }\n\n@@ -1568,13 +1588,21 @@ sub find_by_url { # repos_root and, path are optional\n \t\t}\n \t\tmy $p = $path;\n \t\tmy $rwr = rewrite_root({repo_id => $repo_id});\n+\t\tmy $svm = $remotes->{$repo_id}->{svm}\n+\t\t\tif defined $remotes->{$repo_id}->{svm};\n \t\tunless (defined $p) {\n \t\t\t$p = $full_url;\n \t\t\tmy $z = $u;\n+\t\t\tmy $prefix = '';\n \t\t\tif ($rwr) {\n \t\t\t\t$z = $rwr;\n+\t\t\t} elsif (defined $svm) {\n+\t\t\t\t$z = $svm->{source};\n+\t\t\t\t$prefix = $svm->{replace};\n+\t\t\t\t$prefix =~ s#^\\Q$u\\E(?:/|$)##;\n+\t\t\t\t$prefix =~ s#/$##;\n \t\t\t}\n-\t\t\t$p =~ s#^\\Q$z\\E(?:/|$)## or next;\n+\t\t\t$p =~ s#^\\Q$z\\E(?=/|$)#$prefix# or next;\n \t\t}\n \t\tforeach my $f (keys %$fetch) {\n \t\t\tnext if $f ne $p;\ndiff --git a/t/t9110-git-svn-use-svm-props.sh b/t/t9110-git-svn-use-svm-props.sh\nindex 047659f..04d2a65 100755\n--- a/t/t9110-git-svn-use-svm-props.sh\n+++ b/t/t9110-git-svn-use-svm-props.sh\n@@ -49,4 +49,13 @@ test_expect_success 'verify metadata for /dir' \"\n \t   grep '^git-svn-id: $dir_url@1 $uuid$'\n \t\"\n\n+test_expect_success 'find commit based on SVN revision number' \"\n+        git-svn find-rev r12 |\n+\t    grep `git rev-parse HEAD`\n+        \"\n+\n+test_expect_success 'empty rebase' \"\n+\tgit-svn rebase\n+\t\"\n+\n test_done\n-- \n1.5.5.1\n"}]}