Skip to content

Commit 3d9be15

Browse files
schwernEric Wong
authored and
Eric Wong
committed
Extract Git::SVN::GlobSpec from git-svn.
Straight cut & paste. That's the last class. * Make Git::SVN load it on its own, its the only thing that needs it. Signed-off-by: Eric Wong <[email protected]>
1 parent 10c2aa5 commit 3d9be15

File tree

5 files changed

+64
-60
lines changed

5 files changed

+64
-60
lines changed

git-svn.perl

-59
Original file line numberDiff line numberDiff line change
@@ -2039,65 +2039,6 @@ sub gc_directory {
20392039
}
20402040
}
20412041

2042-
2043-
package Git::SVN::GlobSpec;
2044-
use strict;
2045-
use warnings;
2046-
2047-
sub new {
2048-
my ($class, $glob, $pattern_ok) = @_;
2049-
my $re = $glob;
2050-
$re =~ s!/+$!!g; # no need for trailing slashes
2051-
my (@left, @right, @patterns);
2052-
my $state = "left";
2053-
my $die_msg = "Only one set of wildcard directories " .
2054-
"(e.g. '*' or '*/*/*') is supported: '$glob'\n";
2055-
for my $part (split(m|/|, $glob)) {
2056-
if ($part =~ /\*/ && $part ne "*") {
2057-
die "Invalid pattern in '$glob': $part\n";
2058-
} elsif ($pattern_ok && $part =~ /[{}]/ &&
2059-
$part !~ /^\{[^{}]+\}/) {
2060-
die "Invalid pattern in '$glob': $part\n";
2061-
}
2062-
if ($part eq "*") {
2063-
die $die_msg if $state eq "right";
2064-
$state = "pattern";
2065-
push(@patterns, "[^/]*");
2066-
} elsif ($pattern_ok && $part =~ /^\{(.*)\}$/) {
2067-
die $die_msg if $state eq "right";
2068-
$state = "pattern";
2069-
my $p = quotemeta($1);
2070-
$p =~ s/\\,/|/g;
2071-
push(@patterns, "(?:$p)");
2072-
} else {
2073-
if ($state eq "left") {
2074-
push(@left, $part);
2075-
} else {
2076-
push(@right, $part);
2077-
$state = "right";
2078-
}
2079-
}
2080-
}
2081-
my $depth = @patterns;
2082-
if ($depth == 0) {
2083-
die "One '*' is needed in glob: '$glob'\n";
2084-
}
2085-
my $left = join('/', @left);
2086-
my $right = join('/', @right);
2087-
$re = join('/', @patterns);
2088-
$re = join('\/',
2089-
grep(length, quotemeta($left), "($re)", quotemeta($right)));
2090-
my $left_re = qr/^\/\Q$left\E(\/|$)/;
2091-
bless { left => $left, right => $right, left_regex => $left_re,
2092-
regex => qr/$re/, glob => $glob, depth => $depth }, $class;
2093-
}
2094-
2095-
sub full_path {
2096-
my ($self, $path) = @_;
2097-
return (length $self->{left} ? "$self->{left}/" : '') .
2098-
$path . (length $self->{right} ? "/$self->{right}" : '');
2099-
}
2100-
21012042
__END__
21022043
21032044
Data structures:

perl/Git/SVN.pm

+2
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ sub read_all_remotes {
207207
. "must start with 'refs/'\n")
208208
unless $remote_ref =~ m{^refs/};
209209
$local_ref = uri_decode($local_ref);
210+
211+
require Git::SVN::GlobSpec;
210212
my $rs = {
211213
t => $t,
212214
remote => $remote,

perl/Git/SVN/GlobSpec.pm

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package Git::SVN::GlobSpec;
2+
use strict;
3+
use warnings;
4+
5+
sub new {
6+
my ($class, $glob, $pattern_ok) = @_;
7+
my $re = $glob;
8+
$re =~ s!/+$!!g; # no need for trailing slashes
9+
my (@left, @right, @patterns);
10+
my $state = "left";
11+
my $die_msg = "Only one set of wildcard directories " .
12+
"(e.g. '*' or '*/*/*') is supported: '$glob'\n";
13+
for my $part (split(m|/|, $glob)) {
14+
if ($part =~ /\*/ && $part ne "*") {
15+
die "Invalid pattern in '$glob': $part\n";
16+
} elsif ($pattern_ok && $part =~ /[{}]/ &&
17+
$part !~ /^\{[^{}]+\}/) {
18+
die "Invalid pattern in '$glob': $part\n";
19+
}
20+
if ($part eq "*") {
21+
die $die_msg if $state eq "right";
22+
$state = "pattern";
23+
push(@patterns, "[^/]*");
24+
} elsif ($pattern_ok && $part =~ /^\{(.*)\}$/) {
25+
die $die_msg if $state eq "right";
26+
$state = "pattern";
27+
my $p = quotemeta($1);
28+
$p =~ s/\\,/|/g;
29+
push(@patterns, "(?:$p)");
30+
} else {
31+
if ($state eq "left") {
32+
push(@left, $part);
33+
} else {
34+
push(@right, $part);
35+
$state = "right";
36+
}
37+
}
38+
}
39+
my $depth = @patterns;
40+
if ($depth == 0) {
41+
die "One '*' is needed in glob: '$glob'\n";
42+
}
43+
my $left = join('/', @left);
44+
my $right = join('/', @right);
45+
$re = join('/', @patterns);
46+
$re = join('\/',
47+
grep(length, quotemeta($left), "($re)", quotemeta($right)));
48+
my $left_re = qr/^\/\Q$left\E(\/|$)/;
49+
bless { left => $left, right => $right, left_regex => $left_re,
50+
regex => qr/$re/, glob => $glob, depth => $depth }, $class;
51+
}
52+
53+
sub full_path {
54+
my ($self, $path) = @_;
55+
return (length $self->{left} ? "$self->{left}/" : '') .
56+
$path . (length $self->{right} ? "/$self->{right}" : '');
57+
}
58+
59+
1;

perl/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ modules += Git/SVN
3434
modules += Git/SVN/Memoize/YAML
3535
modules += Git/SVN/Fetcher
3636
modules += Git/SVN/Editor
37+
modules += Git/SVN/GlobSpec
3738
modules += Git/SVN/Log
3839
modules += Git/SVN/Migration
3940
modules += Git/SVN/Prompt

t/Git-SVN/00compile.t

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
use strict;
44
use warnings;
55

6-
use Test::More tests => 6;
6+
use Test::More tests => 7;
77

88
require_ok 'Git::SVN';
99
require_ok 'Git::SVN::Utils';
1010
require_ok 'Git::SVN::Ra';
1111
require_ok 'Git::SVN::Log';
1212
require_ok 'Git::SVN::Migration';
1313
require_ok 'Git::IndexInfo';
14+
require_ok 'Git::SVN::GlobSpec';

0 commit comments

Comments
 (0)