@matheusbsbs / matheus-bagliano / commits / 63c56022f8
Fork 0

git-svn: find-rev and rebase for SVN::Mirror repositories

find-rev and rebase error out on svm because git-svn doesn't trace the original svn revision numbers back to git commits. The updated test case, included in the patch, shows the issue and passes with the rest of the patch applied. This fixes Git::SVN::find_by_url to find branches based on the svm:source URL, where useSvmProps is set. Also makes sure cmd_find_rev and working_head_info use the information they have to correctly track the source repository. This is enough to get find-rev and rebase working. Signed-off-by: João Abecasis <joao@abecasis.name> Acked-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

João Abecasis committed Jul 14, 2008 at 16:28 UTC 63c56022f84ae70dd68763b8eed99bccf58fc98b
2 files changed +44 -4
git-svn.perl
+35 -4
@@ -537,13 +537,13 @@ sub cmd_find_rev {
537 my $head = shift;
538 $head ||= 'HEAD';
539 my @refs;
540 - my (undef, undef, undef, $gs) = working_head_info($head, \@refs);
540 + my (undef, undef, $uuid, $gs) = working_head_info($head, \@refs);
541 unless ($gs) {
542 die "Unable to determine upstream SVN information from ",
543 "$head history\n";
544 }
545 my $desired_revision = substr($revision_or_hash, 1);
546 - $result = $gs->rev_map_get($desired_revision);
546 + $result = $gs->rev_map_get($desired_revision, $uuid);
547 } else {
548 my (undef, $rev, undef) = cmt_metadata($revision_or_hash);
549 $result = $rev;
@@ -1162,7 +1162,7 @@ sub working_head_info {
1162 if (defined $url && defined $rev) {
1163 next if $max{$url} and $max{$url} < $rev;
1164 if (my $gs = Git::SVN->find_by_url($url)) {
1165 - my $c = $gs->rev_map_get($rev);
1165 + my $c = $gs->rev_map_get($rev, $uuid);
1166 if ($c && $c eq $hash) {
1167 close $fh; # break the pipe
1168 return ($url, $rev, $uuid, $gs);
@@ -1416,11 +1416,17 @@ sub fetch_all {
1416
1417 sub read_all_remotes {
1418 my $r = {};
1419 + my $use_svm_props = eval { command_oneline(qw/config --bool
1420 + svn.useSvmProps/) };
1421 + $use_svm_props = $use_svm_props eq 'true' if $use_svm_props;
1422 foreach (grep { s/^svn-remote\.// } command(qw/config -l/)) {
1423 if (m!^(.+)\.fetch=\s*(.*)\s*:\s*refs/remotes/(.+)\s*$!) {
1424 my ($remote, $local_ref, $remote_ref) = ($1, $2, $3);
1425 $local_ref =~ s{^/}{};
1426 $r->{$remote}->{fetch}->{$local_ref} = $remote_ref;
1427 + $r->{$remote}->{svm} = {} if $use_svm_props;
1428 + } elsif (m!^(.+)\.usesvmprops=\s*(.*)\s*$!) {
1429 + $r->{$1}->{svm} = {};
1430 } elsif (m!^(.+)\.url=\s*(.*)\s*$!) {
1431 $r->{$1}->{url} = $2;
1432 } elsif (m!^(.+)\.(branches|tags)=
@@ -1437,6 +1443,23 @@ sub read_all_remotes {
1443 }
1444 }
1445 }
1446 +
1447 + map {
1448 + if (defined $r->{$_}->{svm}) {
1449 + my $svm;
1450 + eval {
1451 + my $section = "svn-remote.$_";
1452 + $svm = {
1453 + source => tmp_config('--get',
1454 + "$section.svm-source"),
1455 + replace => tmp_config('--get',
1456 + "$section.svm-replace"),
1457 + }
1458 + };
1459 + $r->{$_}->{svm} = $svm;
1460 + }
1461 + } keys %$r;
1462 +
1463 $r;
1464 }
1465
@@ -1563,13 +1586,21 @@ sub find_by_url { # repos_root and, path are optional
1586 }
1587 my $p = $path;
1588 my $rwr = rewrite_root({repo_id => $repo_id});
1589 + my $svm = $remotes->{$repo_id}->{svm}
1590 + if defined $remotes->{$repo_id}->{svm};
1591 unless (defined $p) {
1592 $p = $full_url;
1593 my $z = $u;
1594 + my $prefix = '';
1595 if ($rwr) {
1596 $z = $rwr;
1597 + } elsif (defined $svm) {
1598 + $z = $svm->{source};
1599 + $prefix = $svm->{replace};
1600 + $prefix =~ s#^\Q$u\E(?:/|$)##;
1601 + $prefix =~ s#/$##;
1602 }
1572 - $p =~ s#^\Q$z\E(?:/|$)## or next;
1603 + $p =~ s#^\Q$z\E(?:/|$)#$prefix# or next;
1604 }
1605 foreach my $f (keys %$fetch) {
1606 next if $f ne $p;
t/t9110-git-svn-use-svm-props.sh
+9
@@ -49,4 +49,13 @@ test_expect_success 'verify metadata for /dir' "
49 grep '^git-svn-id: $dir_url@1 $uuid$'
50 "
51
52 +test_expect_success 'find commit based on SVN revision number' "
53 + git-svn find-rev r12 |
54 + grep `git rev-parse HEAD`
55 + "
56 +
57 +test_expect_success 'empty rebase' "
58 + git-svn rebase
59 + "
60 +
61 test_done