@matheusbsbs / matheus-bagliano / commits / 62e349d235
Fork 0

git-svn: add support for using svnsync properties

This is similar to useSvmProps, but far simpler in implementation because svnsync retains a 1:1 between revision numbers and relative paths within the repository Config keys: svn.useSvnsyncProps svn-remote.<repo>.useSvnsyncProps Signed-off-by: Eric Wong <normalperson@yhbt.net>

Eric Wong committed Feb 16, 2007 at 19:57 UTC 62e349d235ecbb20c5338de5d4cbff9ce5c6aa66
1 file changed +58 -2
git-svn.perl
+58 -2
@@ -66,6 +66,7 @@ my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent,
66 'repack:i' => \$Git::SVN::_repack,
67 'noMetadata' => \$Git::SVN::_no_metadata,
68 'useSvmProps' => \$Git::SVN::_use_svm_props,
69 + 'useSvnsyncProps' => \$Git::SVN::_use_svnsync_props,
70 'log-window-size=i' => \$Git::SVN::Ra::_log_window_size,
71 'no-checkout' => \$_no_checkout,
72 'quiet|q' => \$_q,
@@ -747,7 +748,8 @@ package Git::SVN;
748 use strict;
749 use warnings;
750 use vars qw/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
750 - $_repack $_repack_flags $_use_svm_props $_head/;
751 + $_repack $_repack_flags $_use_svm_props $_head
752 + $_use_svnsync_props/;
753 use Carp qw/croak/;
754 use File::Path qw/mkpath/;
755 use File::Copy qw/copy/;
@@ -768,7 +770,8 @@ BEGIN {
770 # per [svn-remote "..."] section. Command-line options will *NOT*
771 # override options set in an [svn-remote "..."] section
772 my $e;
771 - foreach (qw/follow_parent no_metadata use_svm_props/) {
773 + foreach (qw/follow_parent no_metadata use_svm_props
774 + use_svnsync_props/) {
775 my $key = $_;
776 $key =~ tr/_//d;
777 $e .= "sub $_ {
@@ -1186,6 +1189,50 @@ sub _set_svm_vars {
1189 Git::SVN::Ra->new($self->{url});
1190 }
1191
1192 +sub svnsync {
1193 + my ($self) = @_;
1194 + return $self->{svnsync} if $self->{svnsync};
1195 +
1196 + if ($self->no_metadata) {
1197 + die "Can't have both 'noMetadata' and ",
1198 + "'useSvnsyncProps' options set!\n";
1199 + }
1200 + if ($self->rewrite_root) {
1201 + die "Can't have both 'useSvnsyncProps' and 'rewriteRoot' ",
1202 + "options set!\n";
1203 + }
1204 +
1205 + my $svnsync;
1206 + # see if we have it in our config, first:
1207 + eval {
1208 + my $section = "svn-remote.$self->{repo_id}";
1209 + $svnsync = {
1210 + url => tmp_config('--get', "$section.svnsync-url"),
1211 + uuid => tmp_config('--get', "$section.svnsync-uuid"),
1212 + }
1213 + };
1214 + if ($svnsync && $svnsync->{url} && $svnsync->{uuid}) {
1215 + return $self->{svnsync} = $svnsync;
1216 + }
1217 +
1218 + my $err = "useSvnsyncProps set, but failed to read " .
1219 + "svnsync property: svn:sync-from-";
1220 + my $rp = $self->ra->rev_proplist(0);
1221 +
1222 + my $url = $rp->{'svn:sync-from-url'} or die $err . "url\n";
1223 + $url =~ m{^[a-z\+]+://} or
1224 + die "doesn't look right - svn:sync-from-url is '$url'\n";
1225 +
1226 + my $uuid = $rp->{'svn:sync-from-uuid'} or die $err . "uuid\n";
1227 + $uuid =~ m{^[0-9a-f\-]{30,}$} or
1228 + die "doesn't look right - svn:sync-from-uuid is '$uuid'\n";
1229 +
1230 + my $section = "svn-remote.$self->{repo_id}";
1231 + tmp_config('--add', "$section.svnsync-uuid", $uuid);
1232 + tmp_config('--add', "$section.svnsync-url", $url);
1233 + return $self->{svnsync} = { url => $url, uuid => $uuid };
1234 +}
1235 +
1236 # this allows us to memoize our SVN::Ra UUID locally and avoid a
1237 # remote lookup (useful for 'git svn log').
1238 sub ra_uuid {
@@ -1211,6 +1258,9 @@ sub ra {
1258 if ($self->no_metadata) {
1259 die "Can't have both 'noMetadata' and ",
1260 "'useSvmProps' options set!\n";
1261 + } elsif ($self->use_svnsync_props) {
1262 + die "Can't have both 'useSvnsyncProps' and ",
1263 + "'useSvmProps' options set!\n";
1264 }
1265 $ra = $self->_set_svm_vars($ra);
1266 $self->{-want_revprops} = 1;
@@ -1739,6 +1789,12 @@ sub make_log_entry {
1789 $log_entry{metadata} = "$full_url\@$r $uuid";
1790 $log_entry{svm_revision} = $r;
1791 $email ||= "$author\@$uuid"
1792 + } elsif ($self->use_svnsync_props) {
1793 + my $full_url = $self->svnsync->{url};
1794 + $full_url .= "/$self->{path}" if length $self->{path};
1795 + my $uuid = $self->svnsync->{uuid};
1796 + $log_entry{metadata} = "$full_url\@$rev $uuid";
1797 + $email ||= "$author\@$uuid"
1798 } else {
1799 $log_entry{metadata} = $self->metadata_url. "\@$rev " .
1800 $self->ra->get_uuid;