@matheusbsbs / matheus-bagliano / commits / 91b03282b5
Fork 0

git-svn: add support for per-[svn-remote "..."] options

Available options are currently: svn-remote.<remote>.{noMetadata,useSvmProps,followParent} These boolean switches will override options set globally in [svn], and even override options set on the command-line (this should probably change in the future, however). Note that the noMetadata and useSvmProps options conflict. It's both technically and logically impossible to use them together. Signed-off-by: Eric Wong <normalperson@yhbt.net>

Eric Wong committed Feb 11, 2007 at 00:51 UTC 91b03282b586cc521f9b009ea8273444fb58f2f1
1 file changed +35 -9
git-svn.perl
+35 -9
@@ -662,6 +662,29 @@ BEGIN {
662 svn:entry:last-author
663 svn:entry:uuid
664 svn:entry:committed-date/;
665 +
666 + # some options are read globally, but can be overridden locally
667 + # per [svn-remote "..."] section. Command-line options will *NOT*
668 + # override options set in an [svn-remote "..."] section
669 + my $e;
670 + foreach (qw/follow_parent no_metadata use_svm_props/) {
671 + my $key = $_;
672 + $key =~ tr/_//d;
673 + $e .= "sub $_ {
674 + my (\$self) = \@_;
675 + return \$self->{-$_} if exists \$self->{-$_};
676 + my \$k = \"svn-remote.\$self->{repo_id}\.$key\";
677 + eval { command_oneline(qw/config --get/, \$k) };
678 + if (\$@) {
679 + \$self->{-$_} = \$Git::SVN::_$_;
680 + } else {
681 + my \$v = command_oneline(qw/config --bool/,\$k);
682 + \$self->{-$_} = \$v eq 'false' ? 0 : 1;
683 + }
684 + return \$self->{-$_} }\n";
685 + }
686 + $e .= "1;\n";
687 + eval $e or die $@;
688 }
689
690 my %LOCKFILES;
@@ -963,8 +986,11 @@ sub set_svm_vars {
986 sub ra {
987 my ($self) = shift;
988 my $ra = Git::SVN::Ra->new($self->{url});
966 - $self->{-use_svm_props} = $Git::SVN::_use_svm_props;
967 - if ($self->{-use_svm_props} && !$self->{svm}) {
989 + if ($self->use_svm_props && !$self->{svm}) {
990 + if ($self->no_metadata) {
991 + die "Can't have both --no-metadata and ",
992 + "--use-svm-props options set!\n";
993 + }
994 $ra = $self->set_svm_vars($ra);
995 $self->{-want_revprops} = 1;
996 }
@@ -1014,7 +1040,7 @@ sub last_rev_commit {
1040 return ($self->{last_rev}, $self->{last_commit});
1041 }
1042 my $c = ::verify_ref($self->refname.'^0');
1017 - if ($c) {
1043 + if ($c && !$self->use_svm_props && !$self->no_metadata) {
1044 my $rev = (::cmt_metadata($c))[1];
1045 if (defined $rev) {
1046 ($self->{last_rev}, $self->{last_commit}) = ($rev, $c);
@@ -1034,7 +1060,7 @@ sub last_rev_commit {
1060 sysread($fh, $rl, 41) == 41 or return (undef, undef);
1061 chomp $rl;
1062 }
1037 - if ($c) {
1063 + if ($c && $c ne $rl) {
1064 die "$self->{db_path} and ", $self->refname,
1065 " inconsistent!:\n$c != $rl\n";
1066 }
@@ -1178,7 +1204,7 @@ sub do_git_commit {
1204 defined(my $pid = open3(my $msg_fh, my $out_fh, '>&STDERR', @exec))
1205 or croak $!;
1206 print $msg_fh $log_entry->{log} or croak $!;
1181 - unless ($_no_metadata) {
1207 + unless ($self->no_metadata) {
1208 print $msg_fh "\ngit-svn-id: $log_entry->{metadata}\n"
1209 or croak $!;
1210 }
@@ -1236,7 +1262,7 @@ sub match_paths {
1262
1263 sub find_parent_branch {
1264 my ($self, $paths, $rev) = @_;
1239 - return undef unless $_follow_parent;
1265 + return undef unless $self->follow_parent;
1266 unless (defined $paths) {
1267 my $err_handler = $SVN::Error::handler;
1268 $SVN::Error::handler = \&Git::SVN::Ra::skip_unknown_revs;
@@ -1297,7 +1323,7 @@ sub find_parent_branch {
1323 $gs = Git::SVN->init($new_url, '', $ref_id, $ref_id, 1);
1324 }
1325 my ($r0, $parent) = $gs->find_rev_before($r, 1);
1300 - if ($_follow_parent && (!defined $r0 || !defined $parent)) {
1326 + if (!defined $r0 || !defined $parent) {
1327 $gs->fetch(0, $r);
1328 ($r0, $parent) = $gs->last_rev_commit;
1329 }
@@ -1451,7 +1477,7 @@ sub make_log_entry {
1477 $log_entry{date} = parse_svn_date($log_entry{date});
1478 $log_entry{author} = check_author($log_entry{author});
1479 $log_entry{log} .= "\n";
1454 - if (defined $headrev && $self->{-use_svm_props}) {
1480 + if (defined $headrev && $self->use_svm_props) {
1481 my ($uuid, $r) = $headrev =~ m{^([a-f\d\-]{30,}):(\d+)$};
1482 if ($uuid ne $self->{svm}->{uuid}) {
1483 die "UUID mismatch on SVM path:\n",
@@ -1556,7 +1582,7 @@ sub rev_db_set {
1582 $SIG{USR1} = $SIG{USR2} = sub { $sig = $_[0] };
1583 }
1584 $LOCKFILES{$db_lock} = 1;
1559 - if ($_no_metadata) {
1585 + if ($self->no_metadata) {
1586 copy($db, $db_lock) or die "rev_db_set(@_): ",
1587 "Failed to copy: ",
1588 "$db => $db_lock ($!)\n";