Skip to content

Commit edc662f

Browse files
Vitaly \"_Vi\" ShukelaEric Wong
authored andcommitted
git-svn: add --ignore-paths option for fetching
This will be useful when somebody want to checkout something partially from repository with some non-standart layout or exclude some files from it. Example: repository has structure /module-{a,b,c}/{trunk,branches,tags}/... Modules are interdependent, and you want it to be single repostory (to commit to all modules simultaneously and view complete history), but do not want branches and tags be checked out into working copy. Other use case is excluding some large blobs. The quirk for now is that user must specify this option every fetch/rebase; in other case he may get extra files or "file not found" errors. It may be will be resolved by adding regular expression to .git/config into [svn-remote ...] to make it persistent. Signed-off-by: Vitaly "_Vi" Shukela <[email protected]> Acked-by: Eric Wong <[email protected]> [ew: replaced 4-space indent with tabs] [ew: prefixed $ignore_regex with an underscore to be consistent with other globals in git-svn] [ew: rearranged functions to minimize diff and removed prototype usage to be consistent with the rest of git-svn (and other Perl code in git (and they're ugly to me)]
1 parent bf8a40b commit edc662f

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

git-svn.perl

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ BEGIN
7070
$Git::SVN::_follow_parent = 1;
7171
my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username,
7272
'config-dir=s' => \$Git::SVN::Ra::config_dir,
73-
'no-auth-cache' => \$Git::SVN::Prompt::_no_auth_cache );
73+
'no-auth-cache' => \$Git::SVN::Prompt::_no_auth_cache,
74+
'ignore-paths=s' => \$SVN::Git::Fetcher::_ignore_regex );
7475
my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent,
7576
'authors-file|A=s' => \$_authors,
7677
'repack:i' => \$Git::SVN::_repack,
@@ -3245,6 +3246,7 @@ package SVN::Git::Fetcher;
32453246
use Carp qw/croak/;
32463247
use File::Temp qw/tempfile/;
32473248
use IO::File qw//;
3249+
use vars qw/$_ignore_regex/;
32483250

32493251
# file baton members: path, mode_a, mode_b, pool, fh, blob, base
32503252
sub new {
@@ -3297,6 +3299,15 @@ sub in_dot_git {
32973299
$_[0] =~ m{(?:^|/)\.git(?:/|$)};
32983300
}
32993301

3302+
# return value: 0 -- don't ignore, 1 -- ignore
3303+
sub is_path_ignored {
3304+
my ($path) = @_;
3305+
return 1 if in_dot_git($path);
3306+
return 0 unless defined($_ignore_regex);
3307+
return 1 if $path =~ m!$_ignore_regex!o;
3308+
return 0;
3309+
}
3310+
33003311
sub set_path_strip {
33013312
my ($self, $path) = @_;
33023313
$self->{path_strip} = qr/^\Q$path\E(\/|$)/ if length $path;
@@ -3322,7 +3333,7 @@ sub git_path {
33223333

33233334
sub delete_entry {
33243335
my ($self, $path, $rev, $pb) = @_;
3325-
return undef if in_dot_git($path);
3336+
return undef if is_path_ignored($path);
33263337

33273338
my $gpath = $self->git_path($path);
33283339
return undef if ($gpath eq '');
@@ -3352,7 +3363,7 @@ sub open_file {
33523363
my ($self, $path, $pb, $rev) = @_;
33533364
my ($mode, $blob);
33543365

3355-
goto out if in_dot_git($path);
3366+
goto out if is_path_ignored($path);
33563367

33573368
my $gpath = $self->git_path($path);
33583369
($mode, $blob) = (command('ls-tree', $self->{c}, '--', $gpath)
@@ -3372,7 +3383,7 @@ sub add_file {
33723383
my ($self, $path, $pb, $cp_path, $cp_rev) = @_;
33733384
my $mode;
33743385

3375-
if (!in_dot_git($path)) {
3386+
if (!is_path_ignored($path)) {
33763387
my ($dir, $file) = ($path =~ m#^(.*?)/?([^/]+)$#);
33773388
delete $self->{empty}->{$dir};
33783389
$mode = '100644';
@@ -3383,7 +3394,7 @@ sub add_file {
33833394

33843395
sub add_directory {
33853396
my ($self, $path, $cp_path, $cp_rev) = @_;
3386-
goto out if in_dot_git($path);
3397+
goto out if is_path_ignored($path);
33873398
my $gpath = $self->git_path($path);
33883399
if ($gpath eq '') {
33893400
my ($ls, $ctx) = command_output_pipe(qw/ls-tree
@@ -3407,31 +3418,31 @@ sub add_directory {
34073418

34083419
sub change_dir_prop {
34093420
my ($self, $db, $prop, $value) = @_;
3410-
return undef if in_dot_git($db->{path});
3421+
return undef if is_path_ignored($db->{path});
34113422
$self->{dir_prop}->{$db->{path}} ||= {};
34123423
$self->{dir_prop}->{$db->{path}}->{$prop} = $value;
34133424
undef;
34143425
}
34153426

34163427
sub absent_directory {
34173428
my ($self, $path, $pb) = @_;
3418-
return undef if in_dot_git($pb->{path});
3429+
return undef if is_path_ignored($path);
34193430
$self->{absent_dir}->{$pb->{path}} ||= [];
34203431
push @{$self->{absent_dir}->{$pb->{path}}}, $path;
34213432
undef;
34223433
}
34233434

34243435
sub absent_file {
34253436
my ($self, $path, $pb) = @_;
3426-
return undef if in_dot_git($pb->{path});
3437+
return undef if is_path_ignored($path);
34273438
$self->{absent_file}->{$pb->{path}} ||= [];
34283439
push @{$self->{absent_file}->{$pb->{path}}}, $path;
34293440
undef;
34303441
}
34313442

34323443
sub change_file_prop {
34333444
my ($self, $fb, $prop, $value) = @_;
3434-
return undef if in_dot_git($fb->{path});
3445+
return undef if is_path_ignored($fb->{path});
34353446
if ($prop eq 'svn:executable') {
34363447
if ($fb->{mode_b} != 120000) {
34373448
$fb->{mode_b} = defined $value ? 100755 : 100644;
@@ -3447,7 +3458,7 @@ sub change_file_prop {
34473458

34483459
sub apply_textdelta {
34493460
my ($self, $fb, $exp) = @_;
3450-
return undef if (in_dot_git($fb->{path}));
3461+
return undef if is_path_ignored($fb->{path});
34513462
my $fh = $::_repository->temp_acquire('svn_delta');
34523463
# $fh gets auto-closed() by SVN::TxDelta::apply(),
34533464
# (but $base does not,) so dup() it for reading in close_file
@@ -3494,7 +3505,7 @@ sub apply_textdelta {
34943505

34953506
sub close_file {
34963507
my ($self, $fb, $exp) = @_;
3497-
return undef if (in_dot_git($fb->{path}));
3508+
return undef if is_path_ignored($fb->{path});
34983509

34993510
my $hash;
35003511
my $path = $self->git_path($fb->{path});

0 commit comments

Comments
 (0)