git-svn: add support for prefixed globs in config
PATCH v4 1/1 git-svn: add support for prefixed globs in config
Introduce prefixed globs for branches and tags in git-svn. Globs like 'release_*' allow users to avoid long lines in config like:
branches = branches/{release_20,release_21,release_22,...}
---
Changes from v3:
* Wrapped all test preparations in separate test-cases
Documentation/git-svn.txt | 5 ++ perl/Git/SVN/GlobSpec.pm | 9 ++- t/t9168-git-svn-prefixed-glob.sh | 142 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+), 5 deletions(-) create mode 100755 t/t9168-git-svn-prefixed-glob.sh
Documentation/git-svn.txt +5 -0
@@ -1034,6 +1034,7 @@ listed below are allowed: url = http://server.org/svn fetch = trunk/project-a:refs/remotes/project-a/trunk branches = branches/*/project-a:refs/remotes/project-a/branches/* + branches = branches/release_*:refs/remotes/project-a/branches/release_* tags = tags/*/project-a:refs/remotes/project-a/tags/* ------------------------------------------------------------------------
@@ -1044,6 +1045,10 @@ independent path component (surrounded by '/' or EOL). This type of configuration is not automatically created by 'init' and should be manually entered with a text-editor or using 'git config'. +Also note that prefixed globs (e.g. 'release_*') match everything after prefix +but do not match exact prefix. For example: +'release_*' will match 'release_1' or 'release_v1' but will not match 'release_'. + It is also possible to fetch a subset of branches or tags by using a comma-separated list of names within braces. For example:
perl/Git/SVN/GlobSpec.pm +4 -5
@@ -11,16 +11,15 @@ sub new { my $die_msg = "Only one set of wildcard directories " . "(e.g. '*' or '*/*/*') is supported: '$glob'\n"; for my $part (split(m|/|, $glob)) { - if ($part =~ /\*/ && $part ne "*") { - die "Invalid pattern in '$glob': $part\n"; - } elsif ($pattern_ok && $part =~ /[{}]/ && + if ($pattern_ok && $part =~ /[{}]/ && $part !~ /^\{[^{}]+\}/) { die "Invalid pattern in '$glob': $part\n"; } - if ($part eq "*") { + if ($part =~ /(\w*)\*/) { die $die_msg if $state eq "right"; $state = "pattern"; - push(@patterns, "[^/]*"); + my $pat = $1 ? "${1}[^/]+" : "[^/]*"; + push(@patterns, $pat); } elsif ($pattern_ok && $part =~ /^\{(.*)\}$/) { die $die_msg if $state eq "right"; $state = "pattern";
t/t9168-git-svn-prefixed-glob.sh new file +142 -0
142 lines not on this page · raw message
Signature · 1 line
2.7.0.rc0.21.gb793f61
Quoted 21 lines · Victor Leschuk
Introduce prefixed globs for branches and tags in git-svn. Globs like 'release_*' allow users to avoid long lines in config like:
branches = branches/{release_20,release_21,release_22,...}
Signed-off-by Victor Leschuk <[email protected]>---
Changes from v3:
* Wrapped all test preparations in separate test-casesDocumentation/git-svn.txt | 5 ++ perl/Git/SVN/GlobSpec.pm | 9 ++- t/t9168-git-svn-prefixed-glob.sh | 142 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+), 5 deletions(-) create mode 100755 t/t9168-git-svn-prefixed-glob.shDocumentation/git-svn.txt +0
-0
Documentation/git-svn.txt listed below are allowed: · line 1037
Quoted 4 lines
Documentation/git-svn.txt +1
-0@@ -1034,6 +1034,7 @@ listed below are allowed: url = http://server.org/svn fetch = trunk/project-a:refs/remotes/project-a/trunk branches = branches/*/project-a:refs/remotes/project-a/branches/* + branches = branches/release_*:refs/remotes/project-a/branches/release_*
Hmph, if you are going this route, I wonder if there is a reason to limit yourself only to "prefix". Would allowing something like this:
branches = branches/pre*post:refs/remotes/project-a/branches/*
i.e., loosening the rule to allow at most one asterisk anywhere on the left hand side of the colon, and require the same number of asterisks as the left hand side has on the right hand side of the colon, be too lax and hurt the users?
Quoted 6 lines · Junio C Hamano
Review
Quoted 1 line · Victor Leschuk
(quoted diff) +1
-0+ branches = branches/release_*:refs/remotes/project-a/branches/release_*Hmph, if you are going this route, I wonder if there is a reason to limit yourself only to "prefix". Would allowing something like this:
Quoted 6 lines
branches = branches/pre*post:refs/remotes/project-a/branches/*
i.e., loosening the rule to allow at most one asterisk anywhere on the left hand side of the colon, and require the same number of asterisks as the left hand side has on the right hand side of the colon, be too lax and hurt the users?
Seems doable. Not sure about the consequences, yet...
I also think the $1 truthiness check was unnecessary and even problematic if we need to encounter a "0" as a path component. And using the path component will need to be quoted as we do below with the brace case (showing with diff -U6)
Perhaps this? (untested)
perl/Git/SVN/GlobSpec.pm +3 -2
@@ -12,16 +12,17 @@ sub new { "(e.g. '*' or '*/*/*') is supported: '$glob'\n"; for my $part (split(m|/|, $glob)) { if ($pattern_ok && $part =~ /[{}]/ && $part !~ /^\{[^{}]+\}/) { die "Invalid pattern in '$glob': $part\n"; } - if ($part =~ /(\w*)\*/) { + if ($part =~ /(\w*)\*(\w*)/) { + my ($l, $r) = ($1, $2); die $die_msg if $state eq "right"; $state = "pattern"; - my $pat = $1 ? "${1}[^/]+" : "[^/]*"; + my $pat = quotemeta($l) . '[^/]*'. quotemeta($r); push(@patterns, $pat); } elsif ($pattern_ok && $part =~ /^\{(.*)\}$/) { die $die_msg if $state eq "right"; $state = "pattern"; my $p = quotemeta($1); $p =~ s/\\,/|/g;
Signature · 1 line
EW
Hello Eric and Junio,
Thanks a lot for the comments and sorry for the delay with the response.
I think that's reasonable to widen the applicability of globs, will do it and prepare next patch.
- my $pat = $1 ? "${1}[^/]+" : "[^/]*";
+ my $pat = quotemeta($l) . '[^/]*'. quotemeta($r);
Hm, that differs from the behavior I suggested at first time: in this case the 'test*' pattern will match all of the: "test", "test0", "test1". In my case it wouldn't match "test"...
However I think that's ok.