git-svn: Add per-svn-remote ignore-paths config
The --ignore-paths option to fetch is very useful for working on a subset of a SVN repository. For proper operation, every command that causes a fetch (explicit or implied) must include a matching --ignore-paths option. This patch adds a persistent svn-remote.$repo_id.ignore-paths config by promoting Fetcher::is_path_ignored to a member function and initializing $self->{ignore_regex} in Fetcher::new. Command line --ignore-paths is still recognized and acts in addition to the config value. Signed-off-by: Ben Jackson <ben@ben.com> Acked-by: Eric Wong <normalperson@yhbt.net>
Ben Jackson committed
Apr 11, 2009 at 10:46 UTC
0d8bee71af1cda3d13d896c210773216dcf87b7c
3 files changed
+82
-21
Documentation/git-svn.txt
+15
-7
@@ -107,17 +107,25 @@ repository, either don't use this option or you should both use it in
107
the same local timezone.
108
109
--ignore-paths=<regex>;;
110
- This allows one to specify Perl regular expression that will
110
+ This allows one to specify a Perl regular expression that will
111
cause skipping of all matching paths from checkout from SVN.
112
- Examples:
112
+ The '--ignore-paths' option should match for every 'fetch'
113
+ (including automatic fetches due to 'clone', 'dcommit',
114
+ 'rebase', etc) on a given repository.
115
114
- --ignore-paths="^doc" - skip "doc*" directory for every fetch.
116
+config key: svn-remote.<name>.ignore-paths
117
116
- --ignore-paths="^[^/]+/(?:branches|tags)" - skip "branches"
117
- and "tags" of first level directories.
118
+ If the ignore-paths config key is set and the command
119
+ line option is also given, both regular expressions
120
+ will be used.
121
119
- Regular expression is not persistent, you should specify
120
- it every time when fetching.
122
+Examples:
123
+
124
+ --ignore-paths="^doc" - skip "doc*" directory for every
125
+ fetch.
126
+
127
+ --ignore-paths="^[^/]+/(?:branches|tags)" - skip
128
+ "branches" and "tags" of first level directories.
129
130
'clone'::
131
Runs 'init' and 'fetch'. It will automatically create a
git-svn.perl
+15
-11
@@ -3331,6 +3331,8 @@ sub new {
3331
$self->{empty_symlinks} =
3332
_mark_empty_symlinks($git_svn, $switch_path);
3333
}
3334
+ $self->{ignore_regex} = eval { command_oneline('config', '--get',
3335
+ "svn-remote.$git_svn->{repo_id}.ignore-paths") };
3336
$self->{empty} = {};
3337
$self->{dir_prop} = {};
3338
$self->{file_prop} = {};
@@ -3395,8 +3397,10 @@ sub in_dot_git {
3397
3398
# return value: 0 -- don't ignore, 1 -- ignore
3399
sub is_path_ignored {
3398
- my ($path) = @_;
3400
+ my ($self, $path) = @_;
3401
return 1 if in_dot_git($path);
3402
+ return 1 if defined($self->{ignore_regex}) &&
3403
+ $path =~ m!$self->{ignore_regex}!;
3404
return 0 unless defined($_ignore_regex);
3405
return 1 if $path =~ m!$_ignore_regex!o;
3406
return 0;
@@ -3427,7 +3431,7 @@ sub git_path {
3431
3432
sub delete_entry {
3433
my ($self, $path, $rev, $pb) = @_;
3430
- return undef if is_path_ignored($path);
3434
+ return undef if $self->is_path_ignored($path);
3435
3436
my $gpath = $self->git_path($path);
3437
return undef if ($gpath eq '');
@@ -3460,7 +3464,7 @@ sub open_file {
3464
my ($self, $path, $pb, $rev) = @_;
3465
my ($mode, $blob);
3466
3463
- goto out if is_path_ignored($path);
3467
+ goto out if $self->is_path_ignored($path);
3468
3469
my $gpath = $self->git_path($path);
3470
($mode, $blob) = (command('ls-tree', '-z', $self->{c}, "./$gpath")
@@ -3480,7 +3484,7 @@ sub add_file {
3484
my ($self, $path, $pb, $cp_path, $cp_rev) = @_;
3485
my $mode;
3486
3483
- if (!is_path_ignored($path)) {
3487
+ if (!$self->is_path_ignored($path)) {
3488
my ($dir, $file) = ($path =~ m#^(.*?)/?([^/]+)$#);
3489
delete $self->{empty}->{$dir};
3490
$mode = '100644';
@@ -3491,7 +3495,7 @@ sub add_file {
3495
3496
sub add_directory {
3497
my ($self, $path, $cp_path, $cp_rev) = @_;
3494
- goto out if is_path_ignored($path);
3498
+ goto out if $self->is_path_ignored($path);
3499
my $gpath = $self->git_path($path);
3500
if ($gpath eq '') {
3501
my ($ls, $ctx) = command_output_pipe(qw/ls-tree
@@ -3515,7 +3519,7 @@ out:
3519
3520
sub change_dir_prop {
3521
my ($self, $db, $prop, $value) = @_;
3518
- return undef if is_path_ignored($db->{path});
3522
+ return undef if $self->is_path_ignored($db->{path});
3523
$self->{dir_prop}->{$db->{path}} ||= {};
3524
$self->{dir_prop}->{$db->{path}}->{$prop} = $value;
3525
undef;
@@ -3523,7 +3527,7 @@ sub change_dir_prop {
3527
3528
sub absent_directory {
3529
my ($self, $path, $pb) = @_;
3526
- return undef if is_path_ignored($path);
3530
+ return undef if $self->is_path_ignored($path);
3531
$self->{absent_dir}->{$pb->{path}} ||= [];
3532
push @{$self->{absent_dir}->{$pb->{path}}}, $path;
3533
undef;
@@ -3531,7 +3535,7 @@ sub absent_directory {
3535
3536
sub absent_file {
3537
my ($self, $path, $pb) = @_;
3534
- return undef if is_path_ignored($path);
3538
+ return undef if $self->is_path_ignored($path);
3539
$self->{absent_file}->{$pb->{path}} ||= [];
3540
push @{$self->{absent_file}->{$pb->{path}}}, $path;
3541
undef;
@@ -3539,7 +3543,7 @@ sub absent_file {
3543
3544
sub change_file_prop {
3545
my ($self, $fb, $prop, $value) = @_;
3542
- return undef if is_path_ignored($fb->{path});
3546
+ return undef if $self->is_path_ignored($fb->{path});
3547
if ($prop eq 'svn:executable') {
3548
if ($fb->{mode_b} != 120000) {
3549
$fb->{mode_b} = defined $value ? 100755 : 100644;
@@ -3555,7 +3559,7 @@ sub change_file_prop {
3559
3560
sub apply_textdelta {
3561
my ($self, $fb, $exp) = @_;
3558
- return undef if is_path_ignored($fb->{path});
3562
+ return undef if $self->is_path_ignored($fb->{path});
3563
my $fh = $::_repository->temp_acquire('svn_delta');
3564
# $fh gets auto-closed() by SVN::TxDelta::apply(),
3565
# (but $base does not,) so dup() it for reading in close_file
@@ -3602,7 +3606,7 @@ sub apply_textdelta {
3606
3607
sub close_file {
3608
my ($self, $fb, $exp) = @_;
3605
- return undef if is_path_ignored($fb->{path});
3609
+ return undef if $self->is_path_ignored($fb->{path});
3610
3611
my $hash;
3612
my $path = $self->git_path($fb->{path});
t/t9134-git-svn-ignore-paths.sh
+52
-3
@@ -31,6 +31,22 @@ test_expect_success 'clone an SVN repository with ignored www directory' '
31
test_cmp expect expect2
32
'
33
34
+test_expect_success 'init+fetch an SVN repository with ignored www directory' '
35
+ git svn init "$svnrepo" c &&
36
+ ( cd c && git svn fetch --ignore-paths="^www" ) &&
37
+ rm expect2 &&
38
+ echo test_qqq > expect &&
39
+ for i in c/*/*.txt; do cat $i >> expect2; done &&
40
+ test_cmp expect expect2
41
+'
42
+
43
+test_expect_success 'set persistent ignore-paths config' '
44
+ (
45
+ cd g &&
46
+ git config svn-remote.svn.ignore-paths "^www"
47
+ )
48
+'
49
+
50
test_expect_success 'SVN-side change outside of www' '
51
(
52
cd s &&
@@ -41,9 +57,20 @@ test_expect_success 'SVN-side change outside of www' '
57
)
58
'
59
44
-test_expect_success 'update git svn-cloned repo' '
60
+test_expect_success 'update git svn-cloned repo (config ignore)' '
61
(
62
cd g &&
63
+ git svn rebase &&
64
+ printf "test_qqq\nb\n" > expect &&
65
+ for i in */*.txt; do cat $i >> expect2; done &&
66
+ test_cmp expect2 expect &&
67
+ rm expect expect2
68
+ )
69
+'
70
+
71
+test_expect_success 'update git svn-cloned repo (option ignore)' '
72
+ (
73
+ cd c &&
74
git svn rebase --ignore-paths="^www" &&
75
printf "test_qqq\nb\n" > expect &&
76
for i in */*.txt; do cat $i >> expect2; done &&
@@ -62,9 +89,20 @@ test_expect_success 'SVN-side change inside of ignored www' '
89
)
90
'
91
65
-test_expect_success 'update git svn-cloned repo' '
92
+test_expect_success 'update git svn-cloned repo (config ignore)' '
93
(
94
cd g &&
95
+ git svn rebase &&
96
+ printf "test_qqq\nb\n" > expect &&
97
+ for i in */*.txt; do cat $i >> expect2; done &&
98
+ test_cmp expect2 expect &&
99
+ rm expect expect2
100
+ )
101
+'
102
+
103
+test_expect_success 'update git svn-cloned repo (option ignore)' '
104
+ (
105
+ cd c &&
106
git svn rebase --ignore-paths="^www" &&
107
printf "test_qqq\nb\n" > expect &&
108
for i in */*.txt; do cat $i >> expect2; done &&
@@ -84,9 +122,20 @@ test_expect_success 'SVN-side change in and out of ignored www' '
122
)
123
'
124
87
-test_expect_success 'update git svn-cloned repo again' '
125
+test_expect_success 'update git svn-cloned repo again (config ignore)' '
126
(
127
cd g &&
128
+ git svn rebase &&
129
+ printf "test_qqq\nb\nygg\n" > expect &&
130
+ for i in */*.txt; do cat $i >> expect2; done &&
131
+ test_cmp expect2 expect &&
132
+ rm expect expect2
133
+ )
134
+'
135
+
136
+test_expect_success 'update git svn-cloned repo again (option ignore)' '
137
+ (
138
+ cd c &&
139
git svn rebase --ignore-paths="^www" &&
140
printf "test_qqq\nb\nygg\n" > expect &&
141
for i in */*.txt; do cat $i >> expect2; done &&