@matheusbsbs / matheus-bagliano / commits / 4e9f6cc78e
Fork 0

git-svn: fix buggy regular expression usage in several places

I incorrectly used $path/? and $path/* to strip off leading directories, but places where $path = 'branches/0.17' would incorrectly strip changes to 'branches/0.17.1' as well. For globs, we require that our '*' is its own path component (surrounded by '/' or nothing). Enforce this when --prefix= is passed to us, too. Signed-off-by: Eric Wong <normalperson@yhbt.net>

Eric Wong committed Feb 9, 2007 at 12:17 UTC 4e9f6cc78e5d955bd0faffe76ae9aea6590189f1
1 file changed +19 -13
git-svn.perl
+19 -13
@@ -492,6 +492,9 @@ sub complete_url_ls_init {
492 $remote_path =~ s#/+#/#g;
493 $remote_path =~ s#^/##g;
494 my ($n) = ($switch =~ /^--(\w+)/);
495 + if (length $pfx && $pfx !~ m#/$#) {
496 + die "--prefix='$pfx' must have a trailing slash '/'\n";
497 + }
498 command_noisy('config', "svn-remote.$remote_id.$n",
499 "$remote_path:refs/remotes/$pfx*");
500 }
@@ -681,7 +684,7 @@ sub resolve_local_globs {
684 " globbed: refs/remotes/$refname\n";
685 }
686 my $u = (::cmt_metadata("refs/remotes/$refname"))[0];
684 - $u =~ s!^\Q$url\E/?!! or die
687 + $u =~ s!^\Q$url\E(/|$)!! or die
688 "refs/remotes/$refname: '$url' not found in '$u'\n";
689 if ($pathname ne $u) {
690 warn "W: Refspec glob conflict ",
@@ -831,7 +834,7 @@ sub init_remote_config {
834 }
835 my $old_path = $self->{path};
836 $self->{path} = $url;
834 - $self->{path} =~ s!^\Q$min_url\E/*!!;
837 + $self->{path} =~ s!^\Q$min_url\E(/|$)!!;
838 if (length $old_path) {
839 $self->{path} .= "/$old_path";
840 }
@@ -927,10 +930,8 @@ sub rel_path {
930 my ($self) = @_;
931 my $repos_root = $self->ra->{repos_root};
932 return $self->{path} if ($self->{url} eq $repos_root);
930 - my $url = $self->{url} .
931 - (length $self->{path} ? "/$self->{path}" : $self->{path});
932 - $url =~ s!^\Q$repos_root\E/*!!g;
933 - $url;
933 + die "BUG: rel_path failed! repos_root: $repos_root, Ra URL: ",
934 + $self->ra->{url}, " path: $self->{path}, URL: $self->{url}\n";
935 }
936
937 sub traverse_ignore {
@@ -1136,10 +1137,11 @@ sub do_git_commit {
1137
1138 sub match_paths {
1139 my ($self, $paths, $r) = @_;
1140 + return 1 if $self->{path} eq '';
1141 if (my $path = $paths->{"/$self->{path}"}) {
1142 return ($path->{action} eq 'D') ? 0 : 1;
1143 }
1142 - $self->{path_regex} ||= qr/^\/\Q$self->{path}\E\/?/;
1144 + $self->{path_regex} ||= qr/^\/\Q$self->{path}\E\//;
1145 if (grep /$self->{path_regex}/, keys %$paths) {
1146 return 1;
1147 }
@@ -1732,7 +1734,7 @@ sub new {
1734
1735 sub set_path_strip {
1736 my ($self, $path) = @_;
1735 - $self->{path_strip} = qr/^\Q$path\E\/?/;
1737 + $self->{path_strip} = qr/^\Q$path\E(\/|$)/ if length $path;
1738 }
1739
1740 sub open_root {
@@ -2347,7 +2349,7 @@ sub new {
2349 auth_provider_callbacks => $callbacks);
2350 $self->{svn_path} = $url;
2351 $self->{repos_root} = $self->get_repos_root;
2350 - $self->{svn_path} =~ s#^\Q$self->{repos_root}\E/*##;
2352 + $self->{svn_path} =~ s#^\Q$self->{repos_root}\E(/|$)##;
2353 $RA = bless $self, $class;
2354 }
2355
@@ -3136,7 +3138,7 @@ sub minimize_connections {
3138
3139 my $root_ra = Git::SVN::Ra->new($ra->{repos_root});
3140 my $root_path = $ra->{url};
3139 - $root_path =~ s#^\Q$ra->{repos_root}\E/*##;
3141 + $root_path =~ s#^\Q$ra->{repos_root}\E(/|$)##;
3142 foreach my $path (keys %$fetch) {
3143 my $ref_id = $fetch->{$path};
3144 my $gs = Git::SVN->new($ref_id, $repo_id, $path);
@@ -3248,7 +3250,7 @@ sub new {
3250 my ($class, $glob) = @_;
3251 my $re = $glob;
3252 $re =~ s!/+$!!g; # no need for trailing slashes
3251 - my $nr = ($re =~ s!^(.*/?)\*(/?.*)$!\(\[^/\]+\)!g);
3253 + my $nr = ($re =~ s!^(.*)\*(.*)$!\(\[^/\]+\)!g);
3254 my ($left, $right) = ($1, $2);
3255 if ($nr > 1) {
3256 die "Only one '*' wildcard expansion ",
@@ -3257,8 +3259,12 @@ sub new {
3259 die "One '*' is needed for glob: '$glob'\n";
3260 }
3261 $re = quotemeta($left) . $re . quotemeta($right);
3260 - $left =~ s!/+$!!g;
3261 - $right =~ s!^/+!!g;
3262 + if (length $left && !($left =~ s!/+$!!g)) {
3263 + die "Missing trailing '/' on left side of: '$glob' ($left)\n";
3264 + }
3265 + if (length $right && !($right =~ s!^/+!!g)) {
3266 + die "Missing leading '/' on right side of: '$glob' ($right)\n";
3267 + }
3268 bless { left => $left, right => $right,
3269 regex => qr/$re/, glob => $glob }, $class;
3270 }