{"thread":{"id":"23541","subject":"[PATCH/RFC 1/2] git-svn: Allow certain refs to be ignored","startedAt":"2010-04-20T21:30:14Z","lastAt":"2010-04-20T21:30:14Z","messageCount":1,"participants":["Michael Olson"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"139998","messageId":"w2nc8b3bef91004201430n4d02e390pa2023d6401a1cb43@mail.gmail.com","threadId":"23541","inReplyTo":null,"subject":"[PATCH/RFC 1/2] git-svn: Allow certain refs to be ignored","fromName":"Michael Olson","fromEmail":"mwolson@gnu.org","sentAt":"2010-04-20T21:30:14Z","receivedAt":"2010-04-20T21:30:14Z","isPatch":true,"sender":{"key":"mwolson@gnu.org","avatar":"https://avatars.githubusercontent.com/u/1510193?v=4"},"body":"Implement a new --ignore-refs option which specifies a regex of refs\nto ignore while importing svn history.\n\nThis is a useful supplement to the --ignore-paths option, as that\noption only operates on the contents of branches and tags, not the\nbranches and tags themselves.\n\nSigned-off-by: Michael W. Olson <mwolson@gnu.org>\n---\n git-svn.perl |   38 +++++++++++++++++++++++++++++++++-----\n 1 files changed, 33 insertions(+), 5 deletions(-)\n\ndiff --git a/git-svn.perl b/git-svn.perl\nindex 2c86ea2..0e1feb3 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -89,7 +89,8 @@ $_q ||= 0;\n my %remote_opts = ( 'username=s' => \\$Git::SVN::Prompt::_username,\n                     'config-dir=s' => \\$Git::SVN::Ra::config_dir,\n                     'no-auth-cache' => \\$Git::SVN::Prompt::_no_auth_cache,\n-                    'ignore-paths=s' => \\$SVN::Git::Fetcher::_ignore_regex );\n+                    'ignore-paths=s' => \\$SVN::Git::Fetcher::_ignore_regex,\n+                    'ignore-refs=s' => \\$Git::SVN::Ra::_ignore_refs_regex );\n my %fc_opts = ( 'follow-parent|follow!' => \\$Git::SVN::_follow_parent,\n \t\t'authors-file|A=s' => \\$_authors,\n \t\t'authors-prog=s' => \\$_authors_prog,\n@@ -378,9 +379,12 @@ sub do_git_init_db {\n \t\tcommand_noisy('config', \"$pfx.$i\", $icv{$i});\n \t\t$set = $i;\n \t}\n-\tmy $ignore_regex = \\$SVN::Git::Fetcher::_ignore_regex;\n-\tcommand_noisy('config', \"$pfx.ignore-paths\", $$ignore_regex)\n-\t\tif defined $$ignore_regex;\n+\tmy $ignore_paths_regex = \\$SVN::Git::Fetcher::_ignore_regex;\n+\tcommand_noisy('config', \"$pfx.ignore-paths\", $$ignore_paths_regex)\n+\t\tif defined $$ignore_paths_regex;\n+\tmy $ignore_refs_regex = \\$Git::SVN::Ra::_ignore_refs_regex;\n+\tcommand_noisy('config', \"$pfx.ignore-refs\", $$ignore_refs_regex)\n+\t\tif defined $$ignore_refs_regex;\n }\n\n sub init_subdir {\n@@ -1823,6 +1827,8 @@ sub read_all_remotes {\n \t\t\t$r->{$1}->{svm} = {};\n \t\t} elsif (m!^(.+)\\.url=\\s*(.*)\\s*$!) {\n \t\t\t$r->{$1}->{url} = $2;\n+\t\t} elsif (m!^(.+)\\.ignore-refs=\\s*(.*)\\s*$!) {\n+\t\t\t$r->{$1}->{ignore_refs_regex} = $2;\n \t\t} elsif (m!^(.+)\\.(branches|tags)=$svn_refspec$!) {\n \t\t\tmy ($remote, $t, $local_ref, $remote_ref) =\n \t\t\t                                     ($1, $2, $3, $4);\n@@ -1858,6 +1864,16 @@ sub read_all_remotes {\n \t\t}\n \t} keys %$r;\n\n+\tforeach my $remote (keys %$r) {\n+\t\tforeach ( grep { defined $_ }\n+\t\t\t  map { $r->{$remote}->{$_} } qw(branches tags) ) {\n+\t\t\tforeach my $rs ( @$_ ) {\n+\t\t\t\t$rs->{ignore_refs_regex} =\n+\t\t\t\t    $r->{$remote}->{ignore_refs_regex};\n+\t\t\t}\n+\t\t}\n+\t}\n+\n \t$r;\n }\n\n@@ -4806,7 +4822,7 @@ sub apply_diff {\n }\n\n package Git::SVN::Ra;\n-use vars qw/@ISA $config_dir $_log_window_size/;\n+use vars qw/@ISA $config_dir $_ignore_refs_regex $_log_window_size/;\n use strict;\n use warnings;\n my ($ra_invalid, $can_do_switch, %ignored_err, $RA);\n@@ -5264,6 +5280,17 @@ sub get_dir_globbed {\n \t@finalents;\n }\n\n+# return value: 0 -- don't ignore, 1 -- ignore\n+sub is_ref_ignored {\n+\tmy ($g, $p) = @_;\n+\tmy $refname = $g->{ref}->full_path($p);\n+\treturn 1 if defined($g->{ignore_refs_regex}) &&\n+\t            $refname =~ m!$g->{ignore_refs_regex}!;\n+\treturn 0 unless defined($_ignore_refs_regex);\n+\treturn 1 if $refname =~ m!$_ignore_refs_regex!o;\n+\treturn 0;\n+}\n+\n sub match_globs {\n \tmy ($self, $exists, $paths, $globs, $r) = @_;\n\n@@ -5300,6 +5327,7 @@ sub match_globs {\n \t\t\tnext unless /$g->{path}->{regex}/;\n \t\t\tmy $p = $1;\n \t\t\tmy $pathname = $g->{path}->full_path($p);\n+\t\t\tnext if is_ref_ignored($g, $p);\n \t\t\tnext if $exists->{$pathname};\n \t\t\tnext if ($self->check_path($pathname, $r) !=\n \t\t\t         $SVN::Node::dir);\n-- \n1.7.1.rc0\n"}]}