Skip to content

Commit cdb51a1

Browse files
mwolsonEric Wong
authored andcommitted
git-svn: Allow certain refs to be ignored
Implement a new --ignore-refs option which specifies a regex of refs to ignore while importing svn history. This is a useful supplement to the --ignore-paths option, as that option only operates on the contents of branches and tags, not the branches and tags themselves. Signed-off-by: Michael Olson <[email protected]> Acked-by: Eric Wong <[email protected]>
1 parent afd7f1e commit cdb51a1

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

git-svn.perl

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ BEGIN
9494
my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username,
9595
'config-dir=s' => \$Git::SVN::Ra::config_dir,
9696
'no-auth-cache' => \$Git::SVN::Prompt::_no_auth_cache,
97-
'ignore-paths=s' => \$SVN::Git::Fetcher::_ignore_regex );
97+
'ignore-paths=s' => \$SVN::Git::Fetcher::_ignore_regex,
98+
'ignore-refs=s' => \$Git::SVN::Ra::_ignore_refs_regex );
9899
my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent,
99100
'authors-file|A=s' => \$_authors,
100101
'authors-prog=s' => \$_authors_prog,
@@ -440,9 +441,12 @@ sub do_git_init_db {
440441
command_noisy('config', "$pfx.$i", $icv{$i});
441442
$set = $i;
442443
}
443-
my $ignore_regex = \$SVN::Git::Fetcher::_ignore_regex;
444-
command_noisy('config', "$pfx.ignore-paths", $$ignore_regex)
445-
if defined $$ignore_regex;
444+
my $ignore_paths_regex = \$SVN::Git::Fetcher::_ignore_regex;
445+
command_noisy('config', "$pfx.ignore-paths", $$ignore_paths_regex)
446+
if defined $$ignore_paths_regex;
447+
my $ignore_refs_regex = \$Git::SVN::Ra::_ignore_refs_regex;
448+
command_noisy('config', "$pfx.ignore-refs", $$ignore_refs_regex)
449+
if defined $$ignore_refs_regex;
446450

447451
if (defined $SVN::Git::Fetcher::_preserve_empty_dirs) {
448452
my $fname = \$SVN::Git::Fetcher::_placeholder_filename;
@@ -2192,6 +2196,8 @@ sub read_all_remotes {
21922196
$r->{$1}->{url} = $2;
21932197
} elsif (m!^(.+)\.pushurl=\s*(.*)\s*$!) {
21942198
$r->{$1}->{pushurl} = $2;
2199+
} elsif (m!^(.+)\.ignore-refs=\s*(.*)\s*$!) {
2200+
$r->{$1}->{ignore_refs_regex} = $2;
21952201
} elsif (m!^(.+)\.(branches|tags)=$svn_refspec$!) {
21962202
my ($remote, $t, $local_ref, $remote_ref) =
21972203
($1, $2, $3, $4);
@@ -2228,6 +2234,16 @@ sub read_all_remotes {
22282234
}
22292235
} keys %$r;
22302236

2237+
foreach my $remote (keys %$r) {
2238+
foreach ( grep { defined $_ }
2239+
map { $r->{$remote}->{$_} } qw(branches tags) ) {
2240+
foreach my $rs ( @$_ ) {
2241+
$rs->{ignore_refs_regex} =
2242+
$r->{$remote}->{ignore_refs_regex};
2243+
}
2244+
}
2245+
}
2246+
22312247
$r;
22322248
}
22332249

@@ -5383,7 +5399,7 @@ sub apply_diff {
53835399
}
53845400

53855401
package Git::SVN::Ra;
5386-
use vars qw/@ISA $config_dir $_log_window_size/;
5402+
use vars qw/@ISA $config_dir $_ignore_refs_regex $_log_window_size/;
53875403
use strict;
53885404
use warnings;
53895405
my ($ra_invalid, $can_do_switch, %ignored_err, $RA);
@@ -5841,6 +5857,17 @@ sub get_dir_globbed {
58415857
@finalents;
58425858
}
58435859

5860+
# return value: 0 -- don't ignore, 1 -- ignore
5861+
sub is_ref_ignored {
5862+
my ($g, $p) = @_;
5863+
my $refname = $g->{ref}->full_path($p);
5864+
return 1 if defined($g->{ignore_refs_regex}) &&
5865+
$refname =~ m!$g->{ignore_refs_regex}!;
5866+
return 0 unless defined($_ignore_refs_regex);
5867+
return 1 if $refname =~ m!$_ignore_refs_regex!o;
5868+
return 0;
5869+
}
5870+
58445871
sub match_globs {
58455872
my ($self, $exists, $paths, $globs, $r) = @_;
58465873

@@ -5877,6 +5904,7 @@ sub match_globs {
58775904
next unless /$g->{path}->{regex}/;
58785905
my $p = $1;
58795906
my $pathname = $g->{path}->full_path($p);
5907+
next if is_ref_ignored($g, $p);
58805908
next if $exists->{$pathname};
58815909
next if ($self->check_path($pathname, $r) !=
58825910
$SVN::Node::dir);

0 commit comments

Comments
 (0)