Skip to content

Commit

Permalink
Merge branch 'extract-remaining' of git://git.bogomips.org/git-svn
Browse files Browse the repository at this point in the history
* '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.
  • Loading branch information
gitster committed Jul 28, 2012
2 parents 646e417 + 3d9be15 commit 51e383d
Show file tree
Hide file tree
Showing 9 changed files with 795 additions and 761 deletions.
795 changes: 36 additions & 759 deletions git-svn.perl

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions perl/Git/IndexInfo.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package Git::IndexInfo;
use strict;
use warnings;
use Git qw/command_input_pipe command_close_pipe/;

sub new {
my ($class) = @_;
my ($gui, $ctx) = command_input_pipe(qw/update-index -z --index-info/);
bless { gui => $gui, ctx => $ctx, nr => 0}, $class;
}

sub remove {
my ($self, $path) = @_;
if (print { $self->{gui} } '0 ', 0 x 40, "\t", $path, "\0") {
return ++$self->{nr};
}
undef;
}

sub update {
my ($self, $mode, $hash, $path) = @_;
if (print { $self->{gui} } $mode, ' ', $hash, "\t", $path, "\0") {
return ++$self->{nr};
}
undef;
}

sub DESTROY {
my ($self) = @_;
command_close_pipe($self->{gui}, $self->{ctx});
}

1;
2 changes: 2 additions & 0 deletions perl/Git/SVN.pm
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ sub read_all_remotes {
. "must start with 'refs/'\n")
unless $remote_ref =~ m{^refs/};
$local_ref = uri_decode($local_ref);

require Git::SVN::GlobSpec;
my $rs = {
t => $t,
remote => $remote,
Expand Down
1 change: 1 addition & 0 deletions perl/Git/SVN/Fetcher.pm
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ sub new {
$self->{file_prop} = {};
$self->{absent_dir} = {};
$self->{absent_file} = {};
require Git::IndexInfo;
$self->{gii} = $git_svn->tmp_index_do(sub { Git::IndexInfo->new });
$self->{pathnameencoding} = Git::config('svn.pathnameencoding');
$self;
Expand Down
59 changes: 59 additions & 0 deletions perl/Git/SVN/GlobSpec.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package Git::SVN::GlobSpec;
use strict;
use warnings;

sub new {
my ($class, $glob, $pattern_ok) = @_;
my $re = $glob;
$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";
for my $part (split(m|/|, $glob)) {
if ($part =~ /\*/ && $part ne "*") {
die "Invalid pattern in '$glob': $part\n";
} elsif ($pattern_ok && $part =~ /[{}]/ &&
$part !~ /^\{[^{}]+\}/) {
die "Invalid pattern in '$glob': $part\n";
}
if ($part eq "*") {
die $die_msg if $state eq "right";
$state = "pattern";
push(@patterns, "[^/]*");
} elsif ($pattern_ok && $part =~ /^\{(.*)\}$/) {
die $die_msg if $state eq "right";
$state = "pattern";
my $p = quotemeta($1);
$p =~ s/\\,/|/g;
push(@patterns, "(?:$p)");
} else {
if ($state eq "left") {
push(@left, $part);
} else {
push(@right, $part);
$state = "right";
}
}
}
my $depth = @patterns;
if ($depth == 0) {
die "One '*' is needed in glob: '$glob'\n";
}
my $left = join('/', @left);
my $right = join('/', @right);
$re = join('/', @patterns);
$re = join('\/',
grep(length, quotemeta($left), "($re)", quotemeta($right)));
my $left_re = qr/^\/\Q$left\E(\/|$)/;
bless { left => $left, right => $right, left_regex => $left_re,
regex => qr/$re/, glob => $glob, depth => $depth }, $class;
}

sub full_path {
my ($self, $path) = @_;
return (length $self->{left} ? "$self->{left}/" : '') .
$path . (length $self->{right} ? "/$self->{right}" : '');
}

1;
Loading

0 comments on commit 51e383d

Please sign in to comment.