64
'authors-file|A=s' => \$_authors,
65
'repack:i' => \$Git::SVN::_repack,
66
'no-metadata' => \$Git::SVN::_no_metadata,
67
+ 'use-svm-props|svm-props' => \$Git::SVN::_use_svm_props,
68
'quiet|q' => \$_q,
69
'repack-flags|repack-args|repack-opts=s' =>
70
\$Git::SVN::_repack_flags,
646
use strict;
647
use warnings;
648
use vars qw/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
648
- $_repack $_repack_flags/;
649
+ $_repack $_repack_flags $_use_svm_props/;
650
use Carp qw/croak/;
651
use File::Path qw/mkpath/;
652
use File::Copy qw/copy/;
921
922
sub refname { "refs/remotes/$_[0]->{ref_id}" }
923
924
+sub set_svm_vars {
925
+ my ($self, $ra) = @_;
926
+ my $section = "svn-remote.$self->{repo_id}";
927
+
928
+ # see if we have it in our config, first:
929
+ eval {
930
+ $self->{svm} = {
931
+ source => $self->tmp_config('--get', "$section.svm-source"),
932
+ uuid => $self->tmp_config('--get', "$section.svm-uuid"),
933
+ }
934
+ };
935
+ return $ra if ($self->{svm}->{source} && $self->{svm}->{uuid});
936
+
937
+ # nope, make sure we're connected to the repository root:
938
+ if ($ra->{repos_root} ne $self->{url}) {
939
+ $ra = Git::SVN::Ra->new($ra->{repos_root});
940
+ }
941
+ my $r = $ra->get_latest_revnum;
942
+ my ($props) = ($ra->get_dir('', $r))[2];
943
+ if (my $src = $props->{'svm:source'}) {
944
+ # don't know what a '!' is there for, also the
945
+ # username is of no interest
946
+ $src =~ s{!$}{};
947
+ $src =~ s{(^[a-z\+]*://)[^/@]*@}{$1};
948
+ $self->tmp_config('--add', "$section.svm-source", $src);
949
+
950
+ my $uuid = $props->{'svm:uuid'};
951
+ $uuid =~ m{^[0-9a-f\-]{30,}$}
952
+ or die "doesn't look right - svm:uuid is '$uuid'\n";
953
+ $self->tmp_config('--add', "$section.svm-uuid", $uuid);
954
+
955
+ $self->{svm} = { source => $src , uuid => $uuid };
956
+ }
957
+ if ($ra->{repos_root} ne $self->{url}) {
958
+ $ra = Git::SVN::Ra->new($self->{url});
959
+ }
960
+ $ra;
961
+}
962
+
963
sub ra {
964
my ($self) = shift;
925
- Git::SVN::Ra->new($self->{url});
965
+ 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}) {
968
+ $ra = $self->set_svm_vars($ra);
969
+ $self->{-want_revprops} = 1;
970
+ }
971
+ $ra;
972
}
973
974
sub rel_path {
1052
(++$min, $max);
1053
}
1054
1055
+sub tmp_config {
1056
+ my ($self, @args) = @_;
1057
+ unless (-f $self->{config}) {
1058
+ open my $fh, '>', $self->{config} or
1059
+ die "Can't open $self->{config}: $!\n";
1060
+ print $fh "; This file is used internally by git-svn\n" or
1061
+ die "Couldn't write to $self->{config}: $!\n";
1062
+ print $fh "; You should not have to edit it\n" or
1063
+ die "Couldn't write to $self->{config}: $!\n";
1064
+ close $fh or die "Couldn't close $self->{config}: $!\n";
1065
+ }
1066
+ my $old_config = $ENV{GIT_CONFIG};
1067
+ $ENV{GIT_CONFIG} = $self->{config};
1068
+ $@ = undef;
1069
+ my @ret = eval { command('config', @args) };
1070
+ my $err = $@;
1071
+ if (defined $old_config) {
1072
+ $ENV{GIT_CONFIG} = $old_config;
1073
+ } else {
1074
+ delete $ENV{GIT_CONFIG};
1075
+ }
1076
+ die $err if $err;
1077
+ wantarray ? @ret : $ret[0];
1078
+}
1079
+
1080
sub tmp_index_do {
1081
my ($self, $sub) = @_;
1082
my $old_index = $ENV{GIT_INDEX_FILE};
1083
$ENV{GIT_INDEX_FILE} = $self->{index};
1013
- my @ret = &$sub;
1014
- if ($old_index) {
1084
+ $@ = undef;
1085
+ my @ret = eval { &$sub };
1086
+ my $err = $@;
1087
+ if (defined $old_index) {
1088
$ENV{GIT_INDEX_FILE} = $old_index;
1089
} else {
1090
delete $ENV{GIT_INDEX_FILE};
1091
}
1092
+ die $err if $err;
1093
wantarray ? @ret : $ret[0];
1094
}
1095
1179
or croak $!;
1180
print $msg_fh $log_entry->{log} or croak $!;
1181
unless ($_no_metadata) {
1108
- print $msg_fh "\ngit-svn-id: ", $self->full_url, '@',
1109
- $log_entry->{revision}, ' ',
1110
- $self->ra->uuid, "\n" or croak $!;
1182
+ print $msg_fh "\ngit-svn-id: $log_entry->{metadata}\n"
1183
+ or croak $!;
1184
}
1185
$msg_fh->flush == 0 or croak $!;
1186
close $msg_fh or croak $!;
1196
1197
$self->{last_rev} = $log_entry->{revision};
1198
$self->{last_commit} = $commit;
1126
- print "r$log_entry->{revision} = $commit ($self->{ref_id})\n";
1199
+ print "r$log_entry->{revision}";
1200
+ if (defined $log_entry->{svm_revision}) {
1201
+ print " (\@$log_entry->{svm_revision})";
1202
+ }
1203
+ print " = $commit ($self->{ref_id})\n";
1204
if (defined $_repack && (--$_repack_nr == 0)) {
1205
$_repack_nr = $_repack;
1206
# repack doesn't use any arguments with spaces in them, does it?
1428
my %log_entry = ( parents => $parents || [], revision => $rev,
1429
log => '');
1430
1431
+ my $headrev;
1432
my $logged = delete $self->{logged_rev_props};
1355
- if (!$logged || $self->{-want_extra_revprops}) {
1433
+ if (!$logged || $self->{-want_revprops}) {
1434
my $rp = $self->ra->rev_proplist($rev);
1435
foreach (sort keys %$rp) {
1436
my $v = $rp->{$_};
1437
if (/^svn:(author|date|log)$/) {
1438
$log_entry{$1} = $v;
1439
+ } elsif ($_ eq 'svm:headrev') {
1440
+ $headrev = $v;
1441
} else {
1442
print $un " rev_prop: ", uri_encode($_), ' ',
1443
uri_encode($v), "\n";
1451
$log_entry{date} = parse_svn_date($log_entry{date});
1452
$log_entry{author} = check_author($log_entry{author});
1453
$log_entry{log} .= "\n";
1454
+ if (defined $headrev && $self->{-use_svm_props}) {
1455
+ my ($uuid, $r) = $headrev =~ m{^([a-f\d\-]{30,}):(\d+)$};
1456
+ if ($uuid ne $self->{svm}->{uuid}) {
1457
+ die "UUID mismatch on SVM path:\n",
1458
+ "expected: $self->{svm}->{uuid}\n",
1459
+ " got: $uuid\n";
1460
+ }
1461
+ my $full_url = $self->{svm}->{source};
1462
+ $full_url .= "/$self->{path}" if length $self->{path};
1463
+ $log_entry{metadata} = "$full_url\@$r $uuid";
1464
+ $log_entry{svm_revision} = $r;
1465
+ } else {
1466
+ $log_entry{metadata} = $self->full_url . "\@$rev " .
1467
+ $self->ra->uuid;
1468
+ }
1469
\%log_entry;
1470
}
1471
1644
close $fh or croak $!;
1645
}
1646
bless { ref_id => $ref_id, dir => $dir, index => "$dir/index",
1552
- path => $path,
1647
+ path => $path, config => "$ENV{GIT_DIR}/svn/config",
1648
db_path => "$dir/.rev_db", repo_id => $repo_id }, $class;
1649
}
1650