@matheusbsbs / matheus-bagliano / commits / 3e18ce1ac3
Fork 0

git-svn: allow UUID to be manually remapped via rewriteUUID

In certain situations it may be necessary to manually remap an svn repostitory UUID. For example: o--- [git-svn clone] / [origin svn repo] \ o--- [svnsync clone] Imagine that only "git-svn clone" and "svnsync clone" are made available to external users. Furthur, "git-svn clone" contains only trunk, and for reasons unknown, "svnsync clone" is missing the revision properties that normally provide the origin svn repo's UUID. A git user who has cloned the "git-svn clone" repo now wishes to use git-svn to pull in the missing branches from the "synsync clone" repo. In order for git-svn to get the history correct for those branches, it needs to know the origin svn repo's UUID. Hence rewriteUUID. Signed-off-by: Jay Soffian <jaysoffian@gmail.com> Acked-by: Eric Wong <normalperson@yhbt.net>

Jay Soffian committed Jan 23, 2010 at 03:30 UTC 3e18ce1ac3034b1562ec748523aa7636e1b58b52
4 files changed +140 -8
Documentation/git-svn.txt
+12 -3
@@ -62,6 +62,8 @@ COMMANDS
62 Set the 'useSvnsyncProps' option in the [svn-remote] config.
63 --rewrite-root=<URL>;;
64 Set the 'rewriteRoot' option in the [svn-remote] config.
65 +--rewrite-uuid=<UUID>;;
66 + Set the 'rewriteUUID' option in the [svn-remote] config.
67 --username=<USER>;;
68 For transports that SVN handles authentication for (http,
69 https, and plain svn), specify the username. For other
@@ -629,6 +631,12 @@ svn-remote.<name>.rewriteRoot::
631 the repository with a public http:// or svn:// URL in the
632 metadata so users of it will see the public URL.
633
634 +svn-remote.<name>.rewriteUUID::
635 + Similar to the useSvmProps option; this is for users who need
636 + to remap the UUID manually. This may be useful in situations
637 + where the original UUID is not available via either useSvmProps
638 + or useSvnsyncProps.
639 +
640 svn.brokenSymlinkWorkaround::
641 This disables potentially expensive checks to workaround
642 broken symlinks checked into SVN by broken clients. Set this
@@ -638,13 +646,14 @@ svn.brokenSymlinkWorkaround::
646 revision fetched. If unset, 'git svn' assumes this option to
647 be "true".
648
641 -Since the noMetadata, rewriteRoot, useSvnsyncProps and useSvmProps
649 +Since the noMetadata, rewriteRoot, rewriteUUID, useSvnsyncProps and useSvmProps
650 options all affect the metadata generated and used by 'git svn'; they
651 *must* be set in the configuration file before any history is imported
652 and these settings should never be changed once they are set.
653
646 -Additionally, only one of these four options can be used per-svn-remote
647 -section because they affect the 'git-svn-id:' metadata line.
654 +Additionally, only one of these options can be used per svn-remote
655 +section because they affect the 'git-svn-id:' metadata line, except
656 +for rewriteRoot and rewriteUUID which can be used together.
657
658
659 BASIC EXAMPLES
git-svn.perl
+28 -5
@@ -115,6 +115,7 @@ my %init_opts = ( 'template=s' => \$_template, 'shared:s' => \$_shared,
115 'use-svm-props' => sub { $icv{useSvmProps} = 1 },
116 'use-svnsync-props' => sub { $icv{useSvnsyncProps} = 1 },
117 'rewrite-root=s' => sub { $icv{rewriteRoot} = $_[1] },
118 + 'rewrite-uuid=s' => sub { $icv{rewriteUUID} = $_[1] },
119 %remote_opts );
120 my %cmt_opts = ( 'edit|e' => \$_edit,
121 'rmdir' => \$SVN::Git::Editor::_rmdir,
@@ -2207,6 +2208,10 @@ sub svnsync {
2208 die "Can't have both 'useSvnsyncProps' and 'rewriteRoot' ",
2209 "options set!\n";
2210 }
2211 + if ($self->rewrite_uuid) {
2212 + die "Can't have both 'useSvnsyncProps' and 'rewriteUUID' ",
2213 + "options set!\n";
2214 + }
2215
2216 my $svnsync;
2217 # see if we have it in our config, first:
@@ -2488,6 +2493,20 @@ sub rewrite_root {
2493 $self->{-rewrite_root} = $rwr;
2494 }
2495
2496 +sub rewrite_uuid {
2497 + my ($self) = @_;
2498 + return $self->{-rewrite_uuid} if exists $self->{-rewrite_uuid};
2499 + my $k = "svn-remote.$self->{repo_id}.rewriteUUID";
2500 + my $rwid = eval { command_oneline(qw/config --get/, $k) };
2501 + if ($rwid) {
2502 + $rwid =~ s#/+$##;
2503 + if ($rwid !~ m#^[a-f0-9]{8}-(?:[a-f0-9]{4}-){3}[a-f0-9]{12}$#) {
2504 + die "$rwid is not a valid UUID (key: $k)\n";
2505 + }
2506 + }
2507 + $self->{-rewrite_uuid} = $rwid;
2508 +}
2509 +
2510 sub metadata_url {
2511 my ($self) = @_;
2512 ($self->rewrite_root || $self->{url}) .
@@ -3306,6 +3325,10 @@ sub make_log_entry {
3325 die "Can't have both 'useSvmProps' and 'rewriteRoot' ",
3326 "options set!\n";
3327 }
3328 + if ($self->rewrite_uuid) {
3329 + die "Can't have both 'useSvmProps' and 'rewriteUUID' ",
3330 + "options set!\n";
3331 + }
3332 my ($uuid, $r) = $headrev =~ m{^([a-f\d\-]{30,}):(\d+)$}i;
3333 # we don't want "SVM: initializing mirror for junk" ...
3334 return undef if $r == 0;
@@ -3336,10 +3359,10 @@ sub make_log_entry {
3359 } else {
3360 my $url = $self->metadata_url;
3361 remove_username($url);
3339 - $log_entry{metadata} = "$url\@$rev " .
3340 - $self->ra->get_uuid;
3341 - $email ||= "$author\@" . $self->ra->get_uuid;
3342 - $commit_email ||= "$author\@" . $self->ra->get_uuid;
3362 + my $uuid = $self->rewrite_uuid || $self->ra->get_uuid;
3363 + $log_entry{metadata} = "$url\@$rev " . $uuid;
3364 + $email ||= "$author\@" . $uuid;
3365 + $commit_email ||= "$author\@" . $uuid;
3366 }
3367 $log_entry{name} = $name;
3368 $log_entry{email} = $email;
@@ -3421,7 +3444,7 @@ sub rebuild {
3444 '--');
3445 my $metadata_url = $self->metadata_url;
3446 remove_username($metadata_url);
3424 - my $svn_uuid = $self->ra_uuid;
3447 + my $svn_uuid = $self->rewrite_uuid || $self->ra_uuid;
3448 my $c;
3449 while (<$log>) {
3450 if ( m{^commit ($::sha1)$} ) {
t/t9153-git-svn-rewrite-uuid.sh new
+25
@@ -0,0 +1,25 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2010 Jay Soffian
4 +#
5 +
6 +test_description='git svn --rewrite-uuid test'
7 +
8 +. ./lib-git-svn.sh
9 +
10 +uuid=6cc8ada4-5932-4b4a-8242-3534ed8a3232
11 +
12 +test_expect_success 'load svn repo' "
13 + svnadmin load -q '$rawsvnrepo' < '$TEST_DIRECTORY/t9153/svn.dump' &&
14 + git svn init --minimize-url --rewrite-uuid='$uuid' '$svnrepo' &&
15 + git svn fetch
16 + "
17 +
18 +test_expect_success 'verify uuid' "
19 + git cat-file commit refs/remotes/git-svn~0 | \
20 + grep '^${git_svn_id}: .*@2 $uuid$' &&
21 + git cat-file commit refs/remotes/git-svn~1 | \
22 + grep '^${git_svn_id}: .*@1 $uuid$'
23 + "
24 +
25 +test_done
t/t9153/svn.dump new
+75
@@ -0,0 +1,75 @@
1 +SVN-fs-dump-format-version: 2
2 +
3 +UUID: b4885626-c94f-4a6c-b179-00c030fc68e8
4 +
5 +Revision-number: 0
6 +Prop-content-length: 56
7 +Content-length: 56
8 +
9 +K 8
10 +svn:date
11 +V 27
12 +2010-01-23T06:41:03.908576Z
13 +PROPS-END
14 +
15 +Revision-number: 1
16 +Prop-content-length: 109
17 +Content-length: 109
18 +
19 +K 7
20 +svn:log
21 +V 11
22 +initial foo
23 +K 10
24 +svn:author
25 +V 3
26 +jay
27 +K 8
28 +svn:date
29 +V 27
30 +2010-01-23T06:41:48.353776Z
31 +PROPS-END
32 +
33 +Node-path: foo
34 +Node-kind: file
35 +Node-action: add
36 +Prop-content-length: 10
37 +Text-content-length: 4
38 +Text-content-md5: d3b07384d113edec49eaa6238ad5ff00
39 +Text-content-sha1: f1d2d2f924e986ac86fdf7b36c94bcdf32beec15
40 +Content-length: 14
41 +
42 +PROPS-END
43 +foo
44 +
45 +
46 +Revision-number: 2
47 +Prop-content-length: 110
48 +Content-length: 110
49 +
50 +K 7
51 +svn:log
52 +V 12
53 +now with bar
54 +K 10
55 +svn:author
56 +V 3
57 +jay
58 +K 8
59 +svn:date
60 +V 27
61 +2010-01-23T06:42:14.214640Z
62 +PROPS-END
63 +
64 +Node-path: foo
65 +Node-kind: file
66 +Node-action: change
67 +Text-content-length: 8
68 +Text-content-md5: f47c75614087a8dd938ba4acff252494
69 +Text-content-sha1: 4e48e2c9a3d2ca8a708cb0cc545700544efb5021
70 +Content-length: 8
71 +
72 +foo
73 +bar
74 +
75 +