git-svn: use private $GIT_DIR/svn/config file more
Switch max_rev storage over to using it for globbing branches and tags. Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Feb 11, 2007 at 01:20 UTC
93f2689ccdf7b62864aac40097bfd51328fae5b7
1 file changed
+21
-32
git-svn.perl
+21
-32
@@ -738,16 +738,10 @@ sub fetch_all {
738
foreach my $t (qw/branches tags/) {
739
defined $remote->{$t} or next;
740
push @globs, $remote->{$t};
741
- my $f = "$ENV{GIT_DIR}/svn/.$uuid.$t";
742
- if (open my $fh, '<', $f) {
743
- chomp(my $max_rev = <$fh>);
744
- close $fh or die "Error closing $f: $!\n";
745
-
746
- if ($max_rev !~ /^\d+$/) {
747
- die "$max_rev (in $f) is not an integer!\n";
748
- }
749
- $remote->{$t}->{max_rev} = $max_rev;
750
- $base = $max_rev if ($max_rev < $base);
741
+ my $max_rev = eval { tmp_config(qw/--int --get/,
742
+ "svn-remote.$repo_id.${t}-maxRev") };
743
+ if (defined $max_rev && ($max_rev < $base)) {
744
+ $base = $max_rev;
745
}
746
}
747
@@ -774,6 +768,7 @@ sub read_all_remotes {
768
my ($p, $g) = ($3, $4);
769
my $rs = $r->{$1}->{$2} = {
770
t => $2,
771
+ remote => $1,
772
path => Git::SVN::GlobSpec->new($p),
773
ref => Git::SVN::GlobSpec->new($g) };
774
if (length($rs->{ref}->{right}) != 0) {
@@ -951,8 +946,8 @@ sub set_svm_vars {
946
# see if we have it in our config, first:
947
eval {
948
$self->{svm} = {
954
- source => $self->tmp_config('--get', "$section.svm-source"),
955
- uuid => $self->tmp_config('--get', "$section.svm-uuid"),
949
+ source => tmp_config('--get', "$section.svm-source"),
950
+ uuid => tmp_config('--get', "$section.svm-uuid"),
951
}
952
};
953
return $ra if ($self->{svm}->{source} && $self->{svm}->{uuid});
@@ -968,12 +963,12 @@ sub set_svm_vars {
963
# username is of no interest
964
$src =~ s{!$}{};
965
$src =~ s{(^[a-z\+]*://)[^/@]*@}{$1};
971
- $self->tmp_config('--add', "$section.svm-source", $src);
966
+ tmp_config('--add', "$section.svm-source", $src);
967
968
my $uuid = $props->{'svm:uuid'};
969
$uuid =~ m{^[0-9a-f\-]{30,}$}
970
or die "doesn't look right - svm:uuid is '$uuid'\n";
976
- $self->tmp_config('--add', "$section.svm-uuid", $uuid);
971
+ tmp_config('--add', "$section.svm-uuid", $uuid);
972
973
$self->{svm} = { source => $src , uuid => $uuid };
974
}
@@ -1079,18 +1074,19 @@ sub get_fetch_range {
1074
}
1075
1076
sub tmp_config {
1082
- my ($self, @args) = @_;
1083
- unless (-f $self->{config}) {
1084
- open my $fh, '>', $self->{config} or
1085
- die "Can't open $self->{config}: $!\n";
1077
+ my (@args) = @_;
1078
+ my $config = "$ENV{GIT_DIR}/svn/config";
1079
+ unless (-f $config) {
1080
+ open my $fh, '>', $config or
1081
+ die "Can't open $config: $!\n";
1082
print $fh "; This file is used internally by git-svn\n" or
1087
- die "Couldn't write to $self->{config}: $!\n";
1083
+ die "Couldn't write to $config: $!\n";
1084
print $fh "; You should not have to edit it\n" or
1089
- die "Couldn't write to $self->{config}: $!\n";
1090
- close $fh or die "Couldn't close $self->{config}: $!\n";
1085
+ die "Couldn't write to $config: $!\n";
1086
+ close $fh or die "Couldn't close $config: $!\n";
1087
}
1088
my $old_config = $ENV{GIT_CONFIG};
1093
- $ENV{GIT_CONFIG} = $self->{config};
1089
+ $ENV{GIT_CONFIG} = $config;
1090
$@ = undef;
1091
my @ret = eval { command('config', @args) };
1092
my $err = $@;
@@ -2673,16 +2669,9 @@ sub gs_fetch_loop_common {
2669
}
2670
}
2671
foreach my $g (@$globs) {
2676
- my $f = "$ENV{GIT_DIR}/svn/." .
2677
- $self->uuid . ".$g->{t}";
2678
- open my $fh, '>', "$f.tmp" or
2679
- die "Can't open $f.tmp for writing: $!";
2680
- print $fh "$r\n" or
2681
- die "Couldn't write to $f: $!\n";
2682
- close $fh or die "Error closing $f: $!\n";
2683
- rename "$f.tmp", $f or
2684
- die "Couldn't rename ",
2685
- "$f.tmp => $f: $!\n";
2672
+ my $k = "svn-remote.$g->{remote}." .
2673
+ "$g->{t}-maxRev";
2674
+ Git::SVN::tmp_config($k, $r);
2675
}
2676
}
2677
# pre-fill the .rev_db since it'll eventually get filled in