Skip to content

Commit 51e383d

Browse files
committed
Merge branch 'extract-remaining' of git://git.bogomips.org/git-svn
* 'extract-remaining' of git://git.bogomips.org/git-svn: Extract Git::SVN::GlobSpec from git-svn. Move Git::IndexInfo into its own file. Load all the modules in one place and before running code. Extract Git::SVN::Migration from git-svn. Prepare Git::SVN::Migration for extraction from git-svn. Extract Git::SVN::Log from git-svn. Prepare Git::SVN::Log for extraction from git-svn.
2 parents 646e417 + 3d9be15 commit 51e383d

9 files changed

Lines changed: 795 additions & 761 deletions

File tree

git-svn.perl

Lines changed: 36 additions & 759 deletions
Large diffs are not rendered by default.

perl/Git/IndexInfo.pm

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package Git::IndexInfo;
2+
use strict;
3+
use warnings;
4+
use Git qw/command_input_pipe command_close_pipe/;
5+
6+
sub new {
7+
my ($class) = @_;
8+
my ($gui, $ctx) = command_input_pipe(qw/update-index -z --index-info/);
9+
bless { gui => $gui, ctx => $ctx, nr => 0}, $class;
10+
}
11+
12+
sub remove {
13+
my ($self, $path) = @_;
14+
if (print { $self->{gui} } '0 ', 0 x 40, "\t", $path, "\0") {
15+
return ++$self->{nr};
16+
}
17+
undef;
18+
}
19+
20+
sub update {
21+
my ($self, $mode, $hash, $path) = @_;
22+
if (print { $self->{gui} } $mode, ' ', $hash, "\t", $path, "\0") {
23+
return ++$self->{nr};
24+
}
25+
undef;
26+
}
27+
28+
sub DESTROY {
29+
my ($self) = @_;
30+
command_close_pipe($self->{gui}, $self->{ctx});
31+
}
32+
33+
1;

perl/Git/SVN.pm

Lines changed: 2 additions & 0 deletions
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/Fetcher.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ sub new {
5757
$self->{file_prop} = {};
5858
$self->{absent_dir} = {};
5959
$self->{absent_file} = {};
60+
require Git::IndexInfo;
6061
$self->{gii} = $git_svn->tmp_index_do(sub { Git::IndexInfo->new });
6162
$self->{pathnameencoding} = Git::config('svn.pathnameencoding');
6263
$self;

perl/Git/SVN/GlobSpec.pm

Lines changed: 59 additions & 0 deletions
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;

0 commit comments

Comments
 (0)