@matheusbsbs / matheus-bagliano / commits / 74a81227f9
Fork 0

git-svn: correctly handle globs with a right-hand-side path component

Several bugs were found and fixed while getting this to work: * Remember the 'R'(eplace) case of actions and treat it like we would an 'A'(dd) case. * Fix a small case of follow-parent missing a parent if a subdirectory was modified in the revision where the parent was copied. * dirents returned by get_dir sometimes expire if the data structure is too big and the pool is destroyed, so we cache get_dir (along with check_path and get_revprops) temporarily along with its pool. Signed-off-by: Eric Wong <normalperson@yhbt.net>

Eric Wong committed Feb 10, 2007 at 13:28 UTC 74a81227f95b52b1c3f7ac7ba84ac1a6e1708995
2 files changed +113 -24
git-svn.perl
+60 -24
@@ -1148,7 +1148,8 @@ sub match_paths {
1148 my $c = '';
1149 foreach (split m#/#, $self->{path}) {
1150 $c .= "/$_";
1151 - next unless ($paths->{$c} && ($paths->{$c}->{action} eq 'A'));
1151 + next unless ($paths->{$c} &&
1152 + ($paths->{$c}->{action} =~ /^[AR]$/));
1153 if ($self->ra->check_path($self->{path}, $r) ==
1154 $SVN::Node::dir) {
1155 return 1;
@@ -1176,11 +1177,11 @@ sub find_parent_branch {
1177 my $i;
1178 while (@b_path_components) {
1179 $i = $paths->{'/'.join('/', @b_path_components)};
1179 - last if $i;
1180 + last if $i && defined $i->{copyfrom_path};
1181 unshift(@a_path_components, pop(@b_path_components));
1182 }
1182 - return undef unless defined $i;
1183 - my $branch_from = $i->{copyfrom_path} or return undef;
1183 + return undef unless defined $i && defined $i->{copyfrom_path};
1184 + my $branch_from = $i->{copyfrom_path};
1185 if (@a_path_components) {
1186 print STDERR "branch_from: $branch_from => ";
1187 $branch_from .= '/'.join('/', @a_path_components);
@@ -2309,8 +2310,7 @@ my $RA;
2310 BEGIN {
2311 # enforce temporary pool usage for some simple functions
2312 my $e;
2312 - foreach (qw/get_latest_revnum rev_proplist get_file
2313 - check_path get_dir get_uuid get_repos_root/) {
2313 + foreach (qw/get_latest_revnum get_uuid get_repos_root/) {
2314 $e .= "sub $_ {
2315 my \$self = shift;
2316 my \$pool = SVN::Pool->new;
@@ -2318,7 +2318,30 @@ BEGIN {
2318 \$pool->clear;
2319 wantarray ? \@ret : \$ret[0]; }\n";
2320 }
2321 - eval $e;
2321 +
2322 + # get_dir needs $pool held in cache for dirents to work,
2323 + # check_path is cacheable and rev_proplist is close enough
2324 + # for our purposes.
2325 + foreach (qw/check_path get_dir rev_proplist/) {
2326 + $e .= "my \%${_}_cache; my \$${_}_rev = 0; sub $_ {
2327 + my \$self = shift;
2328 + my \$r = pop;
2329 + my \$k = join(\"\\0\", \@_);
2330 + if (my \$x = \$${_}_cache{\$r}->{\$k}) {
2331 + return wantarray ? \@\$x : \$x->[0];
2332 + }
2333 + my \$pool = SVN::Pool->new;
2334 + my \@ret = \$self->SUPER::$_(\@_, \$r, \$pool);
2335 + if (\$r != \$${_}_rev) {
2336 + \%${_}_cache = ( pool => [] );
2337 + \$${_}_rev = \$r;
2338 + }
2339 + \$${_}_cache{\$r}->{\$k} = \\\@ret;
2340 + push \@{\$${_}_cache{pool}}, \$pool;
2341 + wantarray ? \@ret : \$ret[0]; }\n";
2342 + }
2343 + $e .= "\n1;";
2344 + eval $e or die $@;
2345 }
2346
2347 sub new {
@@ -2564,8 +2587,34 @@ sub gs_fetch_loop_common {
2587
2588 sub match_globs {
2589 my ($self, $exists, $paths, $globs, $r) = @_;
2590 +
2591 + sub get_dir_check {
2592 + my ($self, $exists, $g, $r) = @_;
2593 + my @x = eval { $self->get_dir($g->{path}->{left}, $r) };
2594 + return unless scalar @x == 3;
2595 + my $dirents = $x[0];
2596 + foreach my $de (keys %$dirents) {
2597 + next if $dirents->{$de}->kind != $SVN::Node::dir;
2598 + my $p = $g->{path}->full_path($de);
2599 + next if $exists->{$p};
2600 + next if (length $g->{path}->{right} &&
2601 + ($self->check_path($p, $r) !=
2602 + $SVN::Node::dir));
2603 + $exists->{$p} = Git::SVN->init($self->{url}, $p, undef,
2604 + $g->{ref}->full_path($de), 1);
2605 + }
2606 + }
2607 foreach my $g (@$globs) {
2608 + if (my $path = $paths->{"/$g->{path}->{left}"}) {
2609 + if ($path->{action} =~ /^[AR]$/) {
2610 + get_dir_check($self, $exists, $g, $r);
2611 + }
2612 + }
2613 foreach (keys %$paths) {
2614 + if (/$g->{path}->{left_regex}/) {
2615 + next if $paths->{$_}->{action} !~ /^[AR]$/;
2616 + get_dir_check($self, $exists, $g, $r);
2617 + }
2618 next unless /$g->{path}->{regex}/;
2619 my $p = $1;
2620 my $pathname = $g->{path}->full_path($p);
@@ -2578,22 +2627,8 @@ sub match_globs {
2627 foreach (split m#/#, $g->{path}->{left}) {
2628 $c .= "/$_";
2629 next unless ($paths->{$c} &&
2581 - ($paths->{$c}->{action} eq 'A'));
2582 - my @x = eval { $self->get_dir($g->{path}->{left}, $r) };
2583 - next unless scalar @x == 3;
2584 - my $dirents = $x[0];
2585 - foreach my $de (keys %$dirents) {
2586 - next if $dirents->{$de}->kind !=
2587 - $SVN::Node::dir;
2588 - my $p = $g->{path}->full_path($de);
2589 - next if $exists->{$p};
2590 - next if (length $g->{path}->{right} &&
2591 - ($self->check_path($p, $r) !=
2592 - $SVN::Node::dir));
2593 - $exists->{$p} = Git::SVN->init($self->{url},
2594 - $p, undef,
2595 - $g->{ref}->full_path($de), 1);
2596 - }
2630 + ($paths->{$c}->{action} =~ /^[AR]$/));
2631 + get_dir_check($self, $exists, $g, $r);
2632 }
2633 }
2634 values %$exists;
@@ -3265,7 +3300,8 @@ sub new {
3300 if (length $right && !($right =~ s!^/+!!g)) {
3301 die "Missing leading '/' on right side of: '$glob' ($right)\n";
3302 }
3268 - bless { left => $left, right => $right,
3303 + my $left_re = qr/^\/\Q$left\E(\/|$)/;
3304 + bless { left => $left, right => $right, left_regex => $left_re,
3305 regex => qr/$re/, glob => $glob }, $class;
3306 }
3307
t/t9108-git-svn-glob.sh new
+53
@@ -0,0 +1,53 @@
1 +#!/bin/sh
2 +# Copyright (c) 2007 Eric Wong
3 +test_description='git-svn globbing refspecs'
4 +. ./lib-git-svn.sh
5 +
6 +cat > expect.end <<EOF
7 +the end
8 +hi
9 +start a new branch
10 +initial
11 +EOF
12 +
13 +test_expect_success 'test refspec globbing' "
14 + mkdir -p trunk/src/a trunk/src/b trunk/doc &&
15 + echo 'hello world' > trunk/src/a/readme &&
16 + echo 'goodbye world' > trunk/src/b/readme &&
17 + svn import -m 'initial' trunk $svnrepo/trunk &&
18 + svn co $svnrepo tmp &&
19 + cd tmp &&
20 + mkdir branches tags &&
21 + svn add branches tags &&
22 + svn cp trunk branches/start &&
23 + svn commit -m 'start a new branch' &&
24 + svn up &&
25 + echo 'hi' >> branches/start/src/b/readme &&
26 + echo 'hey' >> branches/start/src/a/readme &&
27 + svn commit -m 'hi' &&
28 + svn up &&
29 + svn cp branches/start tags/end &&
30 + echo 'bye' >> tags/end/src/b/readme &&
31 + echo 'aye' >> tags/end/src/a/readme &&
32 + svn commit -m 'the end' &&
33 + echo 'byebye' >> tags/end/src/b/readme &&
34 + svn commit -m 'nothing to see here'
35 + cd .. &&
36 + git config --add svn-remote.svn.url $svnrepo &&
37 + git config --add svn-remote.svn.fetch \
38 + 'trunk/src/a:refs/remotes/trunk' &&
39 + git config --add svn-remote.svn.branches \
40 + 'branches/*/src/a:refs/remotes/branches/*' &&
41 + git config --add svn-remote.svn.tags\
42 + 'tags/*/src/a:refs/remotes/tags/*' &&
43 + git-svn multi-fetch &&
44 + git log --pretty=oneline refs/remotes/tags/end | \
45 + sed -e 's/^.\{41\}//' > output.end &&
46 + cmp expect.end output.end &&
47 + test \"\`git rev-parse refs/remotes/tags/end~1\`\" = \
48 + \"\`git rev-parse refs/remotes/branches/start\`\" &&
49 + test \"\`git rev-parse refs/remotes/branches/start~2\`\" = \
50 + \"\`git rev-parse refs/remotes/trunk\`\"
51 + "
52 +
53 +test_done