Make git-svn branch patterns match complete URL

When using the {word,[...]} style of configuration for tags and branches, it appears the intent is to only match whole path parts, since the words in the {} pattern are meta-character quoted. When the pattern word appears in the beginning or middle of the url, it's matched completely, since the left side, pattern, and (non-empty) right side are joined together with path separators. However, when the pattern word appears at the end of the URL, the right side is an empty pattern, and the resulting regex matches more than just the specified pattern. For example, if you specify something along the lines of branches = branches/project/{release_1,release_2} and your repository also contains "branches/project/release_1_2", you will also get the release_1_2 branch. By restricting the match regex with anchors, this is avoided. Signed-off-by: Ammon Riley <ammon.riley@gmail.com> Signed-off-by: Eric Wong <normalperson@yhbt.net>

Ammon Riley committed Aug 30, 2012 at 15:53 UTC 9478b11968d61085bb4c4343395b6f52ce06380f
2 files changed +12 -1
perl/Git/SVN/GlobSpec.pm
+3 -1
@@ -44,7 +44,9 @@ sub new {
44 my $right = join('/', @right);
45 $re = join('/', @patterns);
46 $re = join('\/',
47 - grep(length, quotemeta($left), "($re)", quotemeta($right)));
47 + grep(length, quotemeta($left),
48 + "($re)(?=/|\$)",
49 + quotemeta($right)));
50 my $left_re = qr/^\/\Q$left\E(\/|$)/;
51 bless { left => $left, right => $right, left_regex => $left_re,
52 regex => qr/$re/, glob => $glob, depth => $depth }, $class;
t/t9154-git-svn-fancy-glob.sh
+9
@@ -21,6 +21,15 @@ test_expect_success 'add red branch' "
21 test_must_fail git rev-parse refs/remotes/blue
22 "
23
24 +test_expect_success 'add gre branch' "
25 + GIT_CONFIG=.git/svn/.metadata git config --unset svn-remote.svn.branches-maxRev &&
26 + git config svn-remote.svn.branches 'branches/{red,gre}:refs/remotes/*' &&
27 + git svn fetch &&
28 + git rev-parse refs/remotes/red &&
29 + test_must_fail git rev-parse refs/remotes/green &&
30 + test_must_fail git rev-parse refs/remotes/blue
31 + "
32 +
33 test_expect_success 'add green branch' "
34 GIT_CONFIG=.git/svn/.metadata git config --unset svn-remote.svn.branches-maxRev &&
35 git config svn-remote.svn.branches 'branches/{red,green}:refs/remotes/*' &&