Skip to contentSkip to conversation

git-svn: loosen config globs limitations

PATCH In review Victor Leschuk 4 participants 10 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-svn: loosen config globs limitations

Expand the area of globs applicability for branches and tags in git-svn. It is now possible to use globs like 'a*e', or 'release_*'. This allows users to avoid long lines in config like:

branches = branches/{release_20,release_21,release_22,...}

---
Changes from $gmane/283172:
* Not only prefixed globs are allowed now (one can put '*' in the middle of a word) - thus changed patch name
* Added tests for globs in the middle of a word

 Documentation/git-svn.txt                  |  12 ++
 perl/Git/SVN/GlobSpec.pm                   |  12 +-
 t/t9168-git-svn-partially-globbed-names.sh | 222 +++++++++++++++++++++++++++++
 3 files changed, 241 insertions(+), 5 deletions(-)
 create mode 100755 t/t9168-git-svn-partially-globbed-names.sh
Documentation/git-svn.txt +12 -0
index 0c0f60b..fb23a98 100644
@@ -1034,6 +1034,8 @@ 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_*
+	branches = branches/re*se:refs/remotes/project-a/branches/*
 	tags = tags/*/project-a:refs/remotes/project-a/tags/*
 ------------------------------------------------------------------------
 
@@ -1044,6 +1046,16 @@ 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 only one asterisk is allowed per word. For example:
+
+	branches = branches/re*se:refs/remotes/project-a/branches/*
+
+will match branches 'release', 'rese', 're123se', however
+
+	branches = branches/re*s*e:refs/remotes/project-a/branches/*
+
+will produce an error.
+
 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 +7 -5
index c95f5d7..1248e6d 100644
@@ -11,16 +11,18 @@ 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 "*") {
+		my $nstars = $part =~ tr/\*//;
+		die "Only one '*' is allowed in a pattern: '$part'\n" if $nstars > 1;
+		if ($part =~ /(.*)\*(.*)/) {
 			die $die_msg if $state eq "right";
+			my ($l, $r) = ($1, $2);
 			$state = "pattern";
-			push(@patterns, "[^/]*");
+			my $pat = quotemeta($l) . '[^/]*' . quotemeta($r);
+			push(@patterns, $pat);
 		} elsif ($pattern_ok && $part =~ /^\{(.*)\}$/) {
 			die $die_msg if $state eq "right";
 			$state = "pattern";
t/t9168-git-svn-partially-globbed-names.sh new file +222 -0

222 lines not on this page · raw message

Signature · 1 line
2.7.0.1.g72018be.dirty
#1 lore raw

Thanks, I made a minor cleanup and applied with --whitespace=fix to remove spaces from indentation.

perl/Git/SVN/GlobSpec.pm +4 -2
@@ -15,8 +15,10 @@ sub new {
 			 $part !~ /^\{[^{}]+\}/) {
 			die "Invalid pattern in '$glob': $part\n";
 		}
-		my $nstars = $part =~ tr/\*//;
-		die "Only one '*' is allowed in a pattern: '$part'\n" if $nstars > 1;
+		my $nstars = $part =~ tr/*//;
+		if ($nstars > 1) {
+			die "Only one '*' is allowed in a pattern: '$part'\n";
+		}
 		if ($part =~ /(.*)\*(.*)/) {
 			die $die_msg if $state eq "right";
 			my ($l, $r) = ($1, $2);

So I'll push out with the following commit message:

Subject: [PATCH] git-svn: loosen config globs limitations

Expand the area of globs applicability for branches and tags in git-svn. It is now possible to use globs like 'a*e', or 'release_*'. This allows users to avoid long lines in config like:

	branches = branches/{release_20,release_21,release_22,...}

In favor of:

branches = branches/release_*

[ew: amended commit message, minor formatting and style fixes]

I also noticed the "Only one set of wildcard directories" error message is unnecessary long and "wildcard directories" should probably be shortened to "wildcards" to avoid wrapping in a terminal. That will probably be a separate patch for me.

#2 lore raw

Thanks a lot Eric,

I agree with all corrections, I also noticed the "wildcard directories" message situation when was creating test for the patch, however didn't want mix up unrelated changes for this patchset.

--
Best Regards,
Victor
________________________________________
From: Eric Wong [[email protected]]
Sent: Tuesday, January 12, 2016 19:16
To: Victor Leschuk
Cc: [email protected]; Victor Leschuk; [email protected]
Subject: Re: [PATCH] git-svn: loosen config globs limitations

Thanks, I made a minor cleanup and applied with --whitespace=fix to remove spaces from indentation.

perl/Git/SVN/GlobSpec.pm +4 -2
@@ -15,8 +15,10 @@ sub new {
                         $part !~ /^\{[^{}]+\}/) {
                        die "Invalid pattern in '$glob': $part\n";
                }
-               my $nstars = $part =~ tr/\*//;
-               die "Only one '*' is allowed in a pattern: '$part'\n" if $nstars > 1;
+               my $nstars = $part =~ tr/*//;
+               if ($nstars > 1) {
+                       die "Only one '*' is allowed in a pattern: '$part'\n";
+               }
                if ($part =~ /(.*)\*(.*)/) {
                        die $die_msg if $state eq "right";
                        my ($l, $r) = ($1, $2);

So I'll push out with the following commit message:

Subject: [PATCH] git-svn: loosen config globs limitations

Expand the area of globs applicability for branches and tags in git-svn. It is now possible to use globs like 'a*e', or 'release_*'. This allows users to avoid long lines in config like:

        branches = branches/{release_20,release_21,release_22,...}

In favor of:

branches = branches/release_*

[ew: amended commit message, minor formatting and style fixes]

I also noticed the "Only one set of wildcard directories" error message is unnecessary long and "wildcard directories" should probably be shortened to "wildcards" to avoid wrapping in a terminal. That will probably be a separate patch for me.

#3 lore raw
In reply to Eric Wong
Quoted 7 lines · Eric Wong

Thanks, I made a minor cleanup and applied with --whitespace=fix to remove spaces from indentation.
...
I also noticed the "Only one set of wildcard directories" error message is unnecessary long and "wildcard directories" should probably be shortened to "wildcards" to avoid wrapping in a terminal. That will probably be a separate patch for me.

Should I pull something from you now from 'master' at your bogomips.org repository? I do not mind (and actually I would prefer) waiting until I hear a go ahead, which would let you work on your own changes before I pull.

Thanks.

#4 lore raw
Quoted 10 lines · Junio C Hamano
Quoted 4 lines · Eric Wong

I also noticed the "Only one set of wildcard directories" error message is unnecessary long and "wildcard directories" should probably be shortened to "wildcards" to avoid wrapping in a terminal. That will probably be a separate patch for me.

Should I pull something from you now from 'master' at your bogomips.org repository? I do not mind (and actually I would prefer) waiting until I hear a go ahead, which would let you work on your own changes before I pull.

Yes, please wait. I'll fix the long messages later today. Thanks

#5 lore raw

PATCH 1/1 git-svn: shorten glob error message

In reply to Eric Wong

Error messages should attempt to fit within the confines of an 80-column terminal to avoid compatibility and accessibility problems. Furthermore the word "directories" can be misleading when used in the context of git refnames.

---

Quoted 4 lines · Eric Wong

I also noticed the "Only one set of wildcard directories" error message is unnecessary long and "wildcard directories" should probably be shortened to "wildcards" to avoid wrapping in a terminal. That will probably be a separate patch for me.

There's likely more instances of this in git-svn, but I figured we'll get this one fixed, first.

Also pushed to bogomips.org/git-svn.git (commit dc6aa7e61e9d33856f54d63b7acb518383420373) along with Victor's patch.

 perl/Git/SVN/GlobSpec.pm                   | 4 ++--
 t/t9108-git-svn-glob.sh                    | 9 ++++++---
 t/t9109-git-svn-multi-glob.sh              | 9 ++++++---
 t/t9168-git-svn-partially-globbed-names.sh | 7 ++++---
 4 files changed, 18 insertions(+), 11 deletions(-)
perl/Git/SVN/GlobSpec.pm +2 -2
index 4775026..a0a8d17 100644
@@ -8,8 +8,8 @@ sub new {
 	$re =~ s!/+$!!g; # no need for trailing slashes
 	my (@left, @right, @patterns);
 	my $state = "left";
-	my $die_msg = "Only one set of wildcard directories " .
-				"(e.g. '*' or '*/*/*') is supported: '$glob'\n";
+	my $die_msg = "Only one set of wildcards " .
+				"(e.g. '*' or '*/*/*') is supported: $glob\n";
 	for my $part (split(m|/|, $glob)) {
 		if ($pattern_ok && $part =~ /[{}]/ &&
 			 $part !~ /^\{[^{}]+\}/) {
t/t9108-git-svn-glob.sh +6 -3
index d732d31..29b363b 100755
@@ -86,9 +86,12 @@ test_expect_success 'test left-hand-side only globbing' '
 	test_cmp expect.two output.two
 	'
 
-echo "Only one set of wildcard directories" \
-     "(e.g. '*' or '*/*/*') is supported: 'branches/*/t/*'" > expect.three
-echo "" >> expect.three
+test_expect_success 'prepare test disallow multi-globs' "
+cat >expect.three <<EOF
+Only one set of wildcards (e.g. '*' or '*/*/*') is supported: branches/*/t/*
+
+EOF
+	"
 
 test_expect_success 'test disallow multi-globs' '
 	git config --add svn-remote.three.url "$svnrepo" &&
t/t9109-git-svn-multi-glob.sh +6 -3
index c318f9f..d0b79fe 100755
@@ -135,9 +135,12 @@ test_expect_success 'test another branch' '
 	test_cmp expect.four output.four
 	'
 
-echo "Only one set of wildcard directories" \
-     "(e.g. '*' or '*/*/*') is supported: 'branches/*/t/*'" > expect.three
-echo "" >> expect.three
+test_expect_success 'prepare test disallow multiple globs' "
+cat >expect.three <<EOF
+Only one set of wildcards (e.g. '*' or '*/*/*') is supported: branches/*/t/*
+
+EOF
+	"
 
 test_expect_success 'test disallow multiple globs' '
 	git config --add svn-remote.three.url "$svnrepo" &&
t/t9168-git-svn-partially-globbed-names.sh +4 -3
index a7641dc..8b22f22 100755
@@ -130,9 +130,10 @@ test_expect_success 'test prefixed globs match just prefix' '
 	'
 
 test_expect_success 'prepare test disallow prefixed multi-globs' "
-	echo \"Only one set of wildcard directories\" \
-	     \"(e.g. '*' or '*/*/*') is supported: 'branches/b_*/t/*'\" >expect.four &&
-	echo \"\" >>expect.four
+cat >expect.four <<EOF
+Only one set of wildcards (e.g. '*' or '*/*/*') is supported: branches/b_*/t/*
+
+EOF
 	"
 
 test_expect_success 'test disallow prefixed multi-globs' '
Signature · 1 line
EW
#6 lore raw

Re: [PATCH] git-svn: shorten glob error message

Quoted 13 lines · Eric Wong

Error messages should attempt to fit within the confines of an 80-column terminal to avoid compatibility and accessibility problems. Furthermore the word "directories" can be misleading when used in the context of git refnames.

---

Quoted 4 lines · Eric Wong

I also noticed the "Only one set of wildcard directories" error message is unnecessary long and "wildcard directories" should probably be shortened to "wildcards" to avoid wrapping in a terminal. That will probably be a separate patch for me.

Quoted 6 lines

There's likely more instances of this in git-svn, but I figured we'll get this one fixed, first.

Also pushed to bogomips.org/git-svn.git (commit dc6aa7e61e9d33856f54d63b7acb518383420373) along with Victor's patch.

Thanks.

I am not sure if it is a good idea to show */*/* as an example in the message (that is an anti-example of 'one set of wildcard' by having three stars, isn't it?), but that is not a new issue this change introduces.

Quoted 66 lines
perl/Git/SVN/GlobSpec.pm +2 -2
 	my $state = "left";
-	my $die_msg = "Only one set of wildcard directories " .
-				"(e.g. '*' or '*/*/*') is supported: '$glob'\n";
+	my $die_msg = "Only one set of wildcards " .
+				"(e.g. '*' or '*/*/*') is supported: $glob\n";
 	for my $part (split(m|/|, $glob)) {
 		if ($pattern_ok && $part =~ /[{}]/ &&
 			 $part !~ /^\{[^{}]+\}/) {
t/t9108-git-svn-glob.sh +6 -3
index d732d31..29b363b 100755
@@ -86,9 +86,12 @@ test_expect_success 'test left-hand-side only globbing' '
 	test_cmp expect.two output.two
 	'
 
-echo "Only one set of wildcard directories" \
-     "(e.g. '*' or '*/*/*') is supported: 'branches/*/t/*'" > expect.three
-echo "" >> expect.three
+test_expect_success 'prepare test disallow multi-globs' "
+cat >expect.three <<EOF
+Only one set of wildcards (e.g. '*' or '*/*/*') is supported: branches/*/t/*
+
+EOF
+	"
 
 test_expect_success 'test disallow multi-globs' '
 	git config --add svn-remote.three.url "$svnrepo" &&
t/t9109-git-svn-multi-glob.sh +6 -3
index c318f9f..d0b79fe 100755
@@ -135,9 +135,12 @@ test_expect_success 'test another branch' '
 	test_cmp expect.four output.four
 	'
 
-echo "Only one set of wildcard directories" \
-     "(e.g. '*' or '*/*/*') is supported: 'branches/*/t/*'" > expect.three
-echo "" >> expect.three
+test_expect_success 'prepare test disallow multiple globs' "
+cat >expect.three <<EOF
+Only one set of wildcards (e.g. '*' or '*/*/*') is supported: branches/*/t/*
+
+EOF
+	"
 
 test_expect_success 'test disallow multiple globs' '
 	git config --add svn-remote.three.url "$svnrepo" &&
t/t9168-git-svn-partially-globbed-names.sh +4 -3
index a7641dc..8b22f22 100755
@@ -130,9 +130,10 @@ test_expect_success 'test prefixed globs match just prefix' '
 	'
 
 test_expect_success 'prepare test disallow prefixed multi-globs' "
-	echo \"Only one set of wildcard directories\" \
-	     \"(e.g. '*' or '*/*/*') is supported: 'branches/b_*/t/*'\" >expect.four &&
-	echo \"\" >>expect.four
+cat >expect.four <<EOF
+Only one set of wildcards (e.g. '*' or '*/*/*') is supported: branches/b_*/t/*
+
+EOF
 	"
 
 test_expect_success 'test disallow prefixed multi-globs' '
#7 lore raw

Re: [PATCH] git-svn: shorten glob error message

Hello all,

Quoted 21 lines · Junio C Hamano
Quoted 13 lines · Eric Wong

Error messages should attempt to fit within the confines of an 80-column terminal to avoid compatibility and accessibility problems. Furthermore the word "directories" can be misleading when used in the context of git refnames.

---

Quoted 4 lines · Eric Wong

I also noticed the "Only one set of wildcard directories" error message is unnecessary long and "wildcard directories" should probably be shortened to "wildcards" to avoid wrapping in a terminal. That will probably be a separate patch for me.

Quoted 6 lines

There's likely more instances of this in git-svn, but I figured we'll get this one fixed, first.

Also pushed to bogomips.org/git-svn.git (commit dc6aa7e61e9d33856f54d63b7acb518383420373) along with Victor's patch.

Quoted 6 lines

Thanks.

I am not sure if it is a good idea to show */*/* as an example in the message (that is an anti-example of 'one set of wildcard' by having three stars, isn't it?), but that is not a new issue this change introduces.

I agree, this should be changed, however I think this should be done in separate patch.

Do we have any questions left open before this could be merged into main git repo?

--
Victor

#8 lore raw

Re: [PATCH] git-svn: shorten glob error message

In reply to Junio C Hamano
Quoted 4 lines · Junio C Hamano

I am not sure if it is a good idea to show */*/* as an example in the message (that is an anti-example of 'one set of wildcard' by having three stars, isn't it?), but that is not a new issue this change introduces.

Actually, going back to commit 570d35c26dfbc40757da6032cdc96afb58cc0037 ("git-svn: Allow deep branch names by supporting multi-globs"), having equal '*' on both sides is all that is required.

Not sure how to improve the wording, though...

Quoted 8 lines
Quoted 8 lines
perl/Git/SVN/GlobSpec.pm +2 -2
 	my $state = "left";
-	my $die_msg = "Only one set of wildcard directories " .
-				"(e.g. '*' or '*/*/*') is supported: '$glob'\n";
+	my $die_msg = "Only one set of wildcards " .
+				"(e.g. '*' or '*/*/*') is supported: $glob\n";
 	for my $part (split(m|/|, $glob)) {
 		if ($pattern_ok && $part =~ /[{}]/ &&
 			 $part !~ /^\{[^{}]+\}/) {
#9 lore raw

Re: [PATCH] git-svn: shorten glob error message

Quoted 11 lines · Eric Wong
Quoted 4 lines · Junio C Hamano

I am not sure if it is a good idea to show */*/* as an example in the message (that is an anti-example of 'one set of wildcard' by having three stars, isn't it?), but that is not a new issue this change introduces.

Actually, going back to commit 570d35c26dfbc40757da6032cdc96afb58cc0037 ("git-svn: Allow deep branch names by supporting multi-globs"), having equal '*' on both sides is all that is required.

Not sure how to improve the wording, though...

I dunno, either, and that is why "not a new issue", iow, the patch is good as-is. The wording might be an area with possible future improvement, but that does not have to block the improvement the patch under discussion brings us.

Thanks.