Skip to content

Commit aea736c

Browse files
author
Eric Wong
committed
git-svn: allow overriding of the SVN repo root in metadata
This feature allows users to create repositories from alternate URLs. For example, an administrator could run git-svn on the server locally (accessing via file://) but wish to distribute the repository with a public http:// or svn:// URL in the metadata so users of it will see the public URL. Config key: svn-remote.<remote>.rewriteRoot Signed-off-by: Eric Wong <normalperson@yhbt.net>
1 parent 0425ea9 commit aea736c

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

git-svn.perl

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,26 @@ sub get_commit_parents {
14061406
@ret;
14071407
}
14081408

1409+
sub rewrite_root {
1410+
my ($self) = @_;
1411+
return $self->{-rewrite_root} if exists $self->{-rewrite_root};
1412+
my $k = "svn-remote.$self->{repo_id}.rewriteRoot";
1413+
my $rwr = eval { command_oneline(qw/config --get/, $k) };
1414+
if ($rwr) {
1415+
$rwr =~ s#/+$##;
1416+
if ($rwr !~ m#^[a-z\+]+://#) {
1417+
die "$rwr is not a valid URL (key: $k)\n";
1418+
}
1419+
}
1420+
$self->{-rewrite_root} = $rwr;
1421+
}
1422+
1423+
sub metadata_url {
1424+
my ($self) = @_;
1425+
($self->rewrite_root || $self->{url}) .
1426+
(length $self->{path} ? '/' . $self->{path} : '');
1427+
}
1428+
14091429
sub full_url {
14101430
my ($self) = @_;
14111431
$self->{url} . (length $self->{path} ? '/' . $self->{path} : '');
@@ -1704,6 +1724,10 @@ sub make_log_entry {
17041724
my ($name, $email) = defined $::users{$author} ? @{$::users{$author}}
17051725
: ($author, undef);
17061726
if (defined $headrev && $self->use_svm_props) {
1727+
if ($self->rewrite_root) {
1728+
die "Can't have both 'useSvmProps' and 'rewriteRoot' ",
1729+
"options set!\n";
1730+
}
17071731
my ($uuid, $r) = $headrev =~ m{^([a-f\d\-]{30,}):(\d+)$};
17081732
if ($uuid ne $self->{svm}->{uuid}) {
17091733
die "UUID mismatch on SVM path:\n",
@@ -1716,7 +1740,7 @@ sub make_log_entry {
17161740
$log_entry{svm_revision} = $r;
17171741
$email ||= "$author\@$uuid"
17181742
} else {
1719-
$log_entry{metadata} = $self->full_url . "\@$rev " .
1743+
$log_entry{metadata} = $self->metadata_url. "\@$rev " .
17201744
$self->ra->get_uuid;
17211745
$email ||= "$author\@" . $self->ra->get_uuid;
17221746
}

0 commit comments

Comments
 (0)