{"thread":{"id":"14363","subject":"[PATCH] git-svn: find-rev and rebase for SVN::Mirror repositories","startedAt":"2008-07-09T02:08:27Z","lastAt":"2008-07-15T04:25:19Z","messageCount":5,"participants":["João Abecasis","Eric Wong"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"82669","messageId":"7bf6f1d20807081908kdf9f615taa532ae579b457d7@mail.gmail.com","threadId":"14363","inReplyTo":null,"subject":"[PATCH] git-svn: find-rev and rebase for SVN::Mirror repositories","fromName":"João Abecasis","fromEmail":"joao@abecasis.name","sentAt":"2008-07-09T02:08:27Z","receivedAt":"2008-07-09T02:08:27Z","isPatch":true,"sender":{"key":"joao@abecasis.name","avatar":"https://gravatar.com/avatar/6c28d507fdac73de84e9ea793d82c718ae46c5e96ef25c9171c9b7f697131c4e?d=mp&s=160"},"body":"find-rev and rebase error out on svm because git-svn doesn't trace the original\nsvn revision numbers back to git commits. The updated test case, included in the\npatch, shows the issue and passes with the rest of the patch applied.\n\nThis fixes Git::SVN::find_by_url to find branches based on the svm:source URL,\nwhere useSvmProps is set. Also makes sure cmd_find_rev and working_head_info use\nthe information they have to correctly track the source repository. This is\nenough to get find-rev and rebase working.\n\nSigned-off-by: João Abecasis <joao@abecasis.name>\n---\nIncidentally, I've tried submitting these fixes before, but failed to\nget much attention, so I could be doing something wrong... Any input\non the patch or my approach to this list is appreciated. This time I\nreworded the commit message and added Eric Wong to the CC list, since\nhe seems to be Ack'ing git-svn patches.\n\nAnyway, the patch does get things working for me.\n\nCheers,\n\n\nJoão\n\n git-svn.perl                     |   37 +++++++++++++++++++++++++++++++++----\n t/t9110-git-svn-use-svm-props.sh |    9 +++++++++\n 2 files changed, 42 insertions(+), 4 deletions(-)\n\ndiff --git a/git-svn.perl b/git-svn.perl\nindex a366c89..f5baec1 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@@ -1162,7 +1162,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@@ -1416,11 +1416,17 @@ sub fetch_all {\n\n sub read_all_remotes {\n \tmy $r = {};\n+        my $usesvmprops = eval { command_oneline(qw/config --bool\n+            svn.useSvmProps/) };\n+        $usesvmprops = $usesvmprops eq 'true' if $usesvmprops;\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@@ -1437,6 +1443,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@@ -1563,13 +1584,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.6\n"},{"id":"83241","messageId":"20080714091243.GA27794@untitled","threadId":"14363","inReplyTo":"7bf6f1d20807081908kdf9f615taa532ae579b457d7@mail.gmail.com","subject":"Re: [PATCH] git-svn: find-rev and rebase for SVN::Mirror repositories","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2008-07-14T09:12:43Z","receivedAt":"2008-07-14T09:12:43Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"João Abecasis <joao@abecasis.name> wrote:\n> find-rev and rebase error out on svm because git-svn doesn't trace the original\n> svn revision numbers back to git commits. The updated test case, included in the\n> patch, shows the issue and passes with the rest of the patch applied.\n> \n> This fixes Git::SVN::find_by_url to find branches based on the svm:source URL,\n> where useSvmProps is set. Also makes sure cmd_find_rev and working_head_info use\n> the information they have to correctly track the source repository. This is\n> enough to get find-rev and rebase working.\n> \n> Signed-off-by: João Abecasis <joao@abecasis.name>\n> ---\n> Incidentally, I've tried submitting these fixes before, but failed to\n> get much attention, so I could be doing something wrong... Any input\n> on the patch or my approach to this list is appreciated. This time I\n> reworded the commit message and added Eric Wong to the CC list, since\n> he seems to be Ack'ing git-svn patches.\n\nHi João,\n\nSorry, I haven't been following the mailing list much lately, and\neven keeping up with my inbox is getting to be a chore :(\n\nThe commit message should be wrapped at 72 characters or less.\nSome further notes below (mostly whitespace issues, but one\nregression).\n\n>  sub read_all_remotes {\n>  \tmy $r = {};\n> +        my $usesvmprops = eval { command_oneline(qw/config --bool\n> +            svn.useSvmProps/) };\n> +        $usesvmprops = $usesvmprops eq 'true' if $usesvmprops;\n\nAlways use tabs for indentation (but spaces for alignment is alright).\n\nI'd also rather not propagate the crazy alllowercasewithoutunderscores\nconvention of git-config into code, either.  $uses_svm_props is much\neasier to parse when I'm half-awake :)\n\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> @@ -1437,6 +1443,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\nPlease wrap all code at 80-columns.\n\n> @@ -1563,13 +1584,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\nThis broke t9100 for me at: 'able to dcommit to a subdirectory'\nChanging the ?= back to ?: works.\n\nThanks for the patch, please let us know if that change is OK.\n\n-- \nEric Wong\n"},{"id":"83270","messageId":"7bf6f1d20807140827u56abc74fs4e289384db054a0e@mail.gmail.com","threadId":"14363","inReplyTo":"20080714091243.GA27794@untitled","subject":"Re: [PATCH] git-svn: find-rev and rebase for SVN::Mirror repositories","fromName":"João Abecasis","fromEmail":"joao@abecasis.name","sentAt":"2008-07-14T15:27:21Z","receivedAt":"2008-07-14T15:27:21Z","isPatch":true,"sender":{"key":"joao@abecasis.name","avatar":"https://gravatar.com/avatar/6c28d507fdac73de84e9ea793d82c718ae46c5e96ef25c9171c9b7f697131c4e?d=mp&s=160"},"body":"Hi Eric,\n\nThanks for your reply and comments.\n\nEric Wong <normalperson@yhbt.net> wrote:\n> João Abecasis <joao@abecasis.name> wrote:\n>> find-rev and rebase error out on svm because git-svn doesn't trace the original\n>> svn revision numbers back to git commits. The updated test case, included in the\n>> patch, shows the issue and passes with the rest of the patch applied.\n>>\n>> This fixes Git::SVN::find_by_url to find branches based on the svm:source URL,\n>> where useSvmProps is set. Also makes sure cmd_find_rev and working_head_info use\n>> the information they have to correctly track the source repository. This is\n>> enough to get find-rev and rebase working.\n>>\n>> Signed-off-by: João Abecasis <joao@abecasis.name>\n>> ---\n>> Incidentally, I've tried submitting these fixes before, but failed to\n>> get much attention, so I could be doing something wrong... Any input\n>> on the patch or my approach to this list is appreciated. This time I\n>> reworded the commit message and added Eric Wong to the CC list, since\n>> he seems to be Ack'ing git-svn patches.\n>\n> Hi João,\n>\n> Sorry, I haven't been following the mailing list much lately, and\n> even keeping up with my inbox is getting to be a chore :(\n\nI can relate to that ;-)\n\n> The commit message should be wrapped at 72 characters or less.\n> Some further notes below (mostly whitespace issues, but one\n> regression).\n\nNoted.\n\n>>  sub read_all_remotes {\n>>       my $r = {};\n>> +        my $usesvmprops = eval { command_oneline(qw/config --bool\n>> +            svn.useSvmProps/) };\n>> +        $usesvmprops = $usesvmprops eq 'true' if $usesvmprops;\n>\n> Always use tabs for indentation (but spaces for alignment is alright).\n>\n> I'd also rather not propagate the crazy alllowercasewithoutunderscores\n> convention of git-config into code, either.  $uses_svm_props is much\n> easier to parse when I'm half-awake :)\n\nDone!\n\n>>       foreach (grep { s/^svn-remote\\.// } command(qw/config -l/)) {\n>>               if (m!^(.+)\\.fetch=\\s*(.*)\\s*:\\s*refs/remotes/(.+)\\s*$!) {\n>>                       my ($remote, $local_ref, $remote_ref) = ($1, $2, $3);\n>>                       $local_ref =~ s{^/}{};\n>>                       $r->{$remote}->{fetch}->{$local_ref} = $remote_ref;\n>> +                     $r->{$remote}->{svm} = {} if $usesvmprops;\n>> +             } elsif (m!^(.+)\\.usesvmprops=\\s*(.*)\\s*$!) {\n>> +                     $r->{$1}->{svm} = {};\n>>               } elsif (m!^(.+)\\.url=\\s*(.*)\\s*$!) {\n>>                       $r->{$1}->{url} = $2;\n>>               } elsif (m!^(.+)\\.(branches|tags)=\n>> @@ -1437,6 +1443,21 @@ sub read_all_remotes {\n>>                       }\n>>               }\n>>       }\n>> +\n>> +     map {\n>> +             if (defined $r->{$_}->{svm}) {\n>> +                     my $svm;\n>> +                     eval {\n>> +                             my $section = \"svn-remote.$_\";\n>> +                             $svm = {\n>> +                                     source => tmp_config('--get', \"$section.svm-source\"),\n>> +                                     replace => tmp_config('--get', \"$section.svm-replace\"),\n>> +                             }\n>> +                     };\n>> +                     $r->{$_}->{svm} = $svm;\n>> +             }\n>> +     } keys %$r;\n>> +\n>\n> Please wrap all code at 80-columns.\n\nOkidoki. I just wasn't sure how wide was a tab ;-)\n\n>> @@ -1563,13 +1584,21 @@ sub find_by_url { # repos_root and, path are optional\n>>               }\n>>               my $p = $path;\n>>               my $rwr = rewrite_root({repo_id => $repo_id});\n>> +             my $svm = $remotes->{$repo_id}->{svm}\n>> +                     if defined $remotes->{$repo_id}->{svm};\n>>               unless (defined $p) {\n>>                       $p = $full_url;\n>>                       my $z = $u;\n>> +                     my $prefix = '';\n>>                       if ($rwr) {\n>>                               $z = $rwr;\n>> +                     } elsif (defined $svm) {\n>> +                             $z = $svm->{source};\n>> +                             $prefix = $svm->{replace};\n>> +                             $prefix =~ s#^\\Q$u\\E(?:/|$)##;\n>> +                             $prefix =~ s#/$##;\n>>                       }\n>> -                     $p =~ s#^\\Q$z\\E(?:/|$)## or next;\n>> +                     $p =~ s#^\\Q$z\\E(?=/|$)#$prefix# or next;\n>\n> This broke t9100 for me at: 'able to dcommit to a subdirectory'\n> Changing the ?= back to ?: works.\n\nDuh! Missed that. I had to make a couple of tweaks after the tests\nwere working, because I had some another test case that was breaking\nsomewhere. Anyway, my other test case (which is the one where I need\nit to work) works without that change after all.\n\n> Thanks for the patch, please let us know if that change is OK.\n\nLet's go with that, since it works. If I do find a test case where it\nbreaks we'll fix it later.\n\nUpdated patch coming up.\n\nCheers,\n\n\nJoão\n"},{"id":"83271","messageId":"7bf6f1d20807140828ve04bc16u96d0245209491b2e@mail.gmail.com","threadId":"14363","inReplyTo":"7bf6f1d20807140827u56abc74fs4e289384db054a0e@mail.gmail.com","subject":"Re: [PATCH] git-svn: find-rev and rebase for SVN::Mirror repositories","fromName":"João Abecasis","fromEmail":"joao@abecasis.name","sentAt":"2008-07-14T15:28:04Z","receivedAt":"2008-07-14T15:28:04Z","isPatch":true,"sender":{"key":"joao@abecasis.name","avatar":"https://gravatar.com/avatar/6c28d507fdac73de84e9ea793d82c718ae46c5e96ef25c9171c9b7f697131c4e?d=mp&s=160"},"body":"find-rev and rebase error out on svm because git-svn doesn't trace the\noriginal svn revision numbers back to git commits. The updated test\ncase, included in the patch, shows the issue and passes with the rest of\nthe patch applied.\n\nThis fixes Git::SVN::find_by_url to find branches based on the\nsvm:source URL, where useSvmProps is set. Also makes sure cmd_find_rev\nand working_head_info use the information they have to correctly track\nthe source repository. This is enough to get find-rev and rebase\nworking.\n\nSigned-off-by: João Abecasis <joao@abecasis.name>\n---\n git-svn.perl                     |   39 ++++++++++++++++++++++++++++++++++---\n t/t9110-git-svn-use-svm-props.sh |    9 ++++++++\n 2 files changed, 44 insertions(+), 4 deletions(-)\n\ndiff --git a/git-svn.perl b/git-svn.perl\nindex a366c89..0aa994a 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@@ -1162,7 +1162,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@@ -1416,11 +1416,17 @@ sub fetch_all {\n\n sub read_all_remotes {\n \tmy $r = {};\n+\tmy $use_svm_props = eval { command_oneline(qw/config --bool\n+\t    svn.useSvmProps/) };\n+\t$use_svm_props = $use_svm_props eq 'true' if $use_svm_props;\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 $use_svm_props;\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@@ -1437,6 +1443,23 @@ 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',\n+\t\t\t\t\t    \"$section.svm-source\"),\n+\t\t\t\t\treplace => tmp_config('--get',\n+\t\t\t\t\t    \"$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@@ -1563,13 +1586,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.6\n"},{"id":"83354","messageId":"20080715042519.GA30382@untitled","threadId":"14363","inReplyTo":"7bf6f1d20807140828ve04bc16u96d0245209491b2e@mail.gmail.com","subject":"Re: [PATCH] git-svn: find-rev and rebase for SVN::Mirror repositories","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2008-07-15T04:25:19Z","receivedAt":"2008-07-15T04:25:19Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"João Abecasis <joao@abecasis.name> wrote:\n> find-rev and rebase error out on svm because git-svn doesn't trace the\n> original svn revision numbers back to git commits. The updated test\n> case, included in the patch, shows the issue and passes with the rest of\n> the patch applied.\n> \n> This fixes Git::SVN::find_by_url to find branches based on the\n> svm:source URL, where useSvmProps is set. Also makes sure cmd_find_rev\n> and working_head_info use the information they have to correctly track\n> the source repository. This is enough to get find-rev and rebase\n> working.\n> \n> Signed-off-by: João Abecasis <joao@abecasis.name>\n\nThanks João,\n\nAcked-by: Eric Wong <normalperson@yhbt.net>\n\n> ---\n>  git-svn.perl                     |   39 ++++++++++++++++++++++++++++++++++---\n>  t/t9110-git-svn-use-svm-props.sh |    9 ++++++++\n>  2 files changed, 44 insertions(+), 4 deletions(-)\n> \n> diff --git a/git-svn.perl b/git-svn.perl\n> index a366c89..0aa994a 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> @@ -1162,7 +1162,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> @@ -1416,11 +1416,17 @@ sub fetch_all {\n> \n>  sub read_all_remotes {\n>  \tmy $r = {};\n> +\tmy $use_svm_props = eval { command_oneline(qw/config --bool\n> +\t    svn.useSvmProps/) };\n> +\t$use_svm_props = $use_svm_props eq 'true' if $use_svm_props;\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 $use_svm_props;\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> @@ -1437,6 +1443,23 @@ 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',\n> +\t\t\t\t\t    \"$section.svm-source\"),\n> +\t\t\t\t\treplace => tmp_config('--get',\n> +\t\t\t\t\t    \"$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> @@ -1563,13 +1586,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;\n> diff --git a/t/t9110-git-svn-use-svm-props.sh b/t/t9110-git-svn-use-svm-props.sh\n> index 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> -- \n> 1.5.6\n"}]}