1 package Git
::SVN
::GlobSpec
;
6 my ($class, $glob, $pattern_ok) = @_;
8 $re =~ s!/+$!!g; # no need for trailing slashes
9 my (@left, @right, @patterns);
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";
21 die $die_msg if $state eq "right";
23 push(@patterns, "[^/]*");
24 } elsif ($pattern_ok && $part =~ /^\{(.*)\}$/) {
25 die $die_msg if $state eq "right";
27 my $p = quotemeta($1);
29 push(@patterns, "(?:$p)");
31 if ($state eq "left") {
39 my $depth = @patterns;
41 die "One '*' is needed in glob: '$glob'\n";
43 my $left = join('/', @left);
44 my $right = join('/', @right);
45 $re = join('/', @patterns);
47 grep(length, quotemeta($left),
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;
56 my ($self, $path) = @_;
57 return (length $self->{left
} ?
"$self->{left}/" : '') .
58 $path . (length $self->{right
} ?
"/$self->{right}" : '');