git-svn: add support for prefixed globs in config
cover git-svn: add support for prefixed globs in config
There are existing old SVN repos which use patterns in branch (and tag) names to indicate some information. For example: branches/release_01, branches/release_02, etc, however non-patterned branches co-exist with them (like branches/dev).
If someone maintains git mirror of such a repo it is reasonable to mirror only several branches (for example those who match some pattern) and in current situation it leads to messy and error-prone git config like:
branches = branches/{release_20,release_21,release_22,...
It would be useful to have an opportunity to write
branches = branches/release_*
instead of this.
Thus I suggest to add support for such 'prefixed' globs into git-svn.
Victor Leschuk (2):
Introduce prefixed globs for branches and tags in git-svn. Add test for git-svn prefixed globs.
Documentation/git-svn.txt | 5 ++ perl/Git/SVN/GlobSpec.pm | 9 ++- t/t9168-git-svn-prefixed-glob.sh | 136 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+), 5 deletions(-) create mode 100755 t/t9168-git-svn-prefixed-glob.sh
Signature · 1 line
2.7.0.rc0.21.gb793f61
PATCH 1/2 git-svn: support for prefixed globs in config
Introduce prefixed globs for branches and tags in git-svn.
--- Documentation/git-svn.txt | 5 +++++ perl/Git/SVN/GlobSpec.pm | 9 ++++----- 2 files changed, 9 insertions(+), 5 deletions(-)
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";
Signature · 1 line
2.7.0.rc0.21.gb793f61
PATCH 2/2 git-svn: test for git-svn prefixed globs
In reply to Victor LeschukAdd test for git-svn prefixed globs.
--- t/t9168-git-svn-prefixed-glob.sh | 136 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100755 t/t9168-git-svn-prefixed-glob.sh
t/t9168-git-svn-prefixed-glob.sh new file +136 -0
@@ -0,0 +1,136 @@ +#!/bin/sh +test_description='git svn globbing refspecs with prefixed globs' +. ./lib-git-svn.sh + +cat > expect.end <<EOF +the end +hi +start a new branch +initial +EOF + +test_expect_success 'test refspec prefixed globbing' ' + mkdir -p trunk/src/a trunk/src/b trunk/doc && + echo "hello world" > trunk/src/a/readme && + echo "goodbye world" > trunk/src/b/readme && + svn_cmd import -m "initial" trunk "$svnrepo"/trunk && + svn_cmd co "$svnrepo" tmp && + ( + cd tmp && + mkdir branches tags && + svn_cmd add branches tags && + svn_cmd cp trunk branches/b_start && + svn_cmd commit -m "start a new branch" && + svn_cmd up && + echo "hi" >> branches/b_start/src/b/readme && + poke branches/b_start/src/b/readme && + echo "hey" >> branches/b_start/src/a/readme && + poke branches/b_start/src/a/readme && + svn_cmd commit -m "hi" && + svn_cmd up && + svn_cmd cp branches/b_start tags/t_end && + echo "bye" >> tags/t_end/src/b/readme && + poke tags/t_end/src/b/readme && + echo "aye" >> tags/t_end/src/a/readme && + poke tags/t_end/src/a/readme && + svn_cmd commit -m "the end" && + echo "byebye" >> tags/t_end/src/b/readme && + poke tags/t_end/src/b/readme && + svn_cmd commit -m "nothing to see here" + ) && + git config --add svn-remote.svn.url "$svnrepo" && + git config --add svn-remote.svn.fetch \ + "trunk/src/a:refs/remotes/trunk" && + git config --add svn-remote.svn.branches \ + "branches/b_*/src/a:refs/remotes/branches/b_*" && + git config --add svn-remote.svn.tags\ + "tags/t_*/src/a:refs/remotes/tags/t_*" && + git svn multi-fetch && + git log --pretty=oneline refs/remotes/tags/t_end | \ + sed -e "s/^.\{41\}//" > output.end && + test_cmp expect.end output.end && + test "`git rev-parse refs/remotes/tags/t_end~1`" = \ + "`git rev-parse refs/remotes/branches/b_start`" && + test "`git rev-parse refs/remotes/branches/b_start~2`" = \ + "`git rev-parse refs/remotes/trunk`" && + test_must_fail git rev-parse refs/remotes/tags/t_end@3 + ' + +echo try to try > expect.two +echo nothing to see here >> expect.two +cat expect.end >> expect.two + +test_expect_success 'test left-hand-side only prefixed globbing' ' + git config --add svn-remote.two.url "$svnrepo" && + git config --add svn-remote.two.fetch trunk:refs/remotes/two/trunk && + git config --add svn-remote.two.branches \ + "branches/b_*:refs/remotes/two/branches/*" && + git config --add svn-remote.two.tags \ + "tags/t_*:refs/remotes/two/tags/*" && + ( + cd tmp && + echo "try try" >> tags/t_end/src/b/readme && + poke tags/t_end/src/b/readme && + svn_cmd commit -m "try to try" + ) && + git svn fetch two && + test `git rev-list refs/remotes/two/tags/t_end | wc -l` -eq 6 && + test `git rev-list refs/remotes/two/branches/b_start | wc -l` -eq 3 && + test `git rev-parse refs/remotes/two/branches/b_start~2` = \ + `git rev-parse refs/remotes/two/trunk` && + test `git rev-parse refs/remotes/two/tags/t_end~3` = \ + `git rev-parse refs/remotes/two/branches/b_start` && + git log --pretty=oneline refs/remotes/two/tags/t_end | \ + sed -e "s/^.\{41\}//" > output.two && + test_cmp expect.two output.two + ' + +test_expect_success 'test prefixed globs do not match just prefix' ' + git config --add svn-remote.three.url "$svnrepo" && + git config --add svn-remote.three.fetch \ + trunk:refs/remotes/three/trunk && + git config --add svn-remote.three.branches \ + "branches/b_*:refs/remotes/three/branches/*" && + git config --add svn-remote.three.tags \ + "tags/t_*:refs/remotes/three/tags/*" && + ( + cd tmp && + svn_cmd cp trunk branches/b_ && + echo "You should never see me" >> branches/b_/src/a/readme && + poke branches/b_/src/a/readme && + svn_cmd commit -m "Never seen branch commit" && + svn_cmd up && + svn_cmd cp branches/b_ tags/t_ && + echo "You should never see mee too" >> tags/t_/src/a/readme && + poke tags/t_/src/a/readme && + svn_cmd commit -m "Never seen tag commit" && + svn_cmd up + ) && + git svn fetch three && + test_path_is_missing refs/remotes/three/branches/b_ && + test_path_is_missing refs/remotes/three/tags/t_ + ' + +echo "Only one set of wildcard directories" \ + "(e.g. '*' or '*/*/*') is supported: 'branches/b_*/t/*'" > expect.four +echo "" >> expect.four + +test_expect_success 'test disallow prefixed multi-globs' ' + git config --add svn-remote.four.url "$svnrepo" && + git config --add svn-remote.four.fetch \ + trunk:refs/remotes/four/trunk && + git config --add svn-remote.four.branches \ + "branches/b_*/t/*:refs/remotes/four/branches/*" && + git config --add svn-remote.four.tags \ + "tags/t_*/*:refs/remotes/four/tags/*" && + ( + cd tmp && + echo "try try" >> tags/t_end/src/b/readme && + poke tags/t_end/src/b/readme && + svn_cmd commit -m "try to try" + ) && + test_must_fail git svn fetch four 2> stderr.four && + test_cmp expect.four stderr.four + ' + +test_done
Signature · 1 line
2.7.0.rc0.21.gb793f61
Re: [PATCH 2/2] git-svn: test for git-svn prefixed globs
Thanks for this work. Most things look fine with 1/2, comments on 2/2 below...
Quoted 1 line · Victor Leschuk
Add test for git-svn prefixed globs.
Why a separate patch? Unless there's some documentation purpose for a regression, usually tests and a feature should be added atomically in the same commit.
t/t9168-git-svn-prefixed-glob.sh line 5
Quoted 8 lines
t/t9168-git-svn-prefixed-glob.sh new file +5
-0@@ -0,0 +1,136 @@ +#!/bin/sh +test_description='git svn globbing refspecs with prefixed globs' +. ./lib-git-svn.sh + +cat > expect.end <<EOF
We prefer redirects in new code to be in the form of ">foo" (no space) (or ">>foo" for append).
It wasn't in the old tests, either, but Documentation/CodingGuidelines favors this for new code.
t/t9168-git-svn-prefixed-glob.sh line 10
Quoted 5 lines
t/t9168-git-svn-prefixed-glob.sh new file +5
-0+the end +hi +start a new branch +initial +EOF
All the setup code be checked for errors with '&&' as well.
t/t9168-git-svn-prefixed-glob.sh line 55
Quoted 4 lines
t/t9168-git-svn-prefixed-glob.sh new file +4
-0+ test "`git rev-parse refs/remotes/tags/t_end~1`" = \ + "`git rev-parse refs/remotes/branches/b_start`" && + test "`git rev-parse refs/remotes/branches/b_start~2`" = \ + "`git rev-parse refs/remotes/trunk`" &&
And we prefer $(command) instead of command for nestability as Documentation/CodingGuidelines suggests.
(yeah, most of the old tests don't follow the guidelines, but the
guidelines also warn against fixup patches for them).
Thanks again.
Re: [PATCH 2/2] git-svn: test for git-svn prefixed globs
Hello Eric, sorry, I just copy pasted your old t9108-git-svn-glob.sh, changed branch names to be prefixed and added test for "exact" prefix match. If it is necessary I can rewrite it according to current guidelines.
Quoted 41 lines · Eric Wong
Thanks for this work. Most things look fine with 1/2, comments on 2/2 below...
Quoted 1 line · Victor Leschuk
Add test for git-svn prefixed globs.
Why a separate patch? Unless there's some documentation purpose for a regression, usually tests and a feature should be added atomically in the same commit.
t/t9168-git-svn-prefixed-glob.sh line 5
Quoted 8 lines
t/t9168-git-svn-prefixed-glob.sh new file +5
-0@@ -0,0 +1,136 @@ +#!/bin/sh +test_description='git svn globbing refspecs with prefixed globs' +. ./lib-git-svn.sh + +cat > expect.end <<EOFWe prefer redirects in new code to be in the form of ">foo" (no space) (or ">>foo" for append).
It wasn't in the old tests, either, but
Documentation/CodingGuidelinesfavors this for new code.t/t9168-git-svn-prefixed-glob.sh line 10
Quoted 5 lines
t/t9168-git-svn-prefixed-glob.sh new file +5
-0+the end +hi +start a new branch +initial +EOFAll the setup code be checked for errors with '&&' as well.
t/t9168-git-svn-prefixed-glob.sh line 55
Quoted 4 lines
t/t9168-git-svn-prefixed-glob.sh new file +4
-0+ test "`git rev-parse refs/remotes/tags/t_end~1`" = \ + "`git rev-parse refs/remotes/branches/b_start`" && + test "`git rev-parse refs/remotes/branches/b_start~2`" = \ + "`git rev-parse refs/remotes/trunk`" &&And we prefer $(command) instead of
commandfor nestability asDocumentation/CodingGuidelinessuggests.(yeah, most of the old tests don't follow the guidelines, but the
guidelines also warn against fixup patches for them).Thanks again.
Re: [PATCH 2/2] git-svn: test for git-svn prefixed globs
Quoted 4 lines · Victor Leschuk
Hello Eric, sorry, I just copy pasted your old
t9108-git-svn-glob.sh, changed branch names to be prefixed and added test for "exact" prefix match. If it is necessary I can rewrite it according to current guidelines.
Yes, please do if you can. I can do it if you're willing to wait a bit.