@matheusbsbs / matheus-bagliano / commits / 1d52aba839
Fork 0

contrib/git-svn: fix svn compat and fetch args

'svn info' doesn't work with URLs in svn <= 1.1. Now we only run svn info in local directories. As a side effect, this should also work better for 'init' off directories that are no longer in the latest revision of the repository. svn checkout -r<revision> arguments are fixed. Newer versions of svn (1.2.x) seem to need URL@REV as well as -rREV to checkout a particular revision... Add an example in the manpage of how to track directory that has been moved since its initial revision. A huge thanks to Yann Dirson for the bug reporting and testing my original patch. Thanks also to Junio C Hamano for suggesting a safer way to use git-rev-parse. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <junkio@cox.net>

Eric Wong committed Mar 9, 2006 at 03:48 UTC 1d52aba8397723235e6007d0ee38126714af113e
2 files changed +75 -20
contrib/git-svn/git-svn.perl
+45 -18
@@ -30,6 +30,7 @@ my $sha1_short = qr/[a-f\d]{4,40}/;
30 my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,
31 $_find_copies_harder, $_l, $_version, $_upgrade, $_authors);
32 my (@_branch_from, %tree_map, %users);
33 +my $_svn_co_url_revs;
34
35 my %fc_opts = ( 'no-ignore-externals' => \$_no_ignore_ext,
36 'branch|b=s' => \@_branch_from,
@@ -77,7 +78,7 @@ usage(0) if $_help;
78 version() if $_version;
79 usage(1) unless defined $cmd;
80 load_authors() if $_authors;
80 -svn_check_ignore_externals();
81 +svn_compat_check();
82 $cmd{$cmd}->[0]->(@ARGV);
83 exit 0;
84
@@ -162,7 +163,8 @@ sub rebuild {
163 croak "SVN repository location required: $url\n";
164 }
165 $SVN_URL ||= $url;
165 - $SVN_UUID ||= setup_git_svn();
166 + $SVN_UUID ||= $uuid;
167 + setup_git_svn();
168 $latest = $rev;
169 }
170 assert_revision_eq_or_unknown($rev, $c);
@@ -171,9 +173,7 @@ sub rebuild {
173 }
174 close $rev_list or croak $?;
175 if (!chdir $SVN_WC) {
174 - my @svn_co = ('svn','co',"-r$latest");
175 - push @svn_co, '--ignore-externals' unless $_no_ignore_ext;
176 - sys(@svn_co, $SVN_URL, $SVN_WC);
176 + svn_cmd_checkout($SVN_URL, $latest, $SVN_WC);
177 chdir $SVN_WC or croak $!;
178 }
179
@@ -222,14 +222,14 @@ sub fetch {
222 my $base = shift @$svn_log or croak "No base revision!\n";
223 my $last_commit = undef;
224 unless (-d $SVN_WC) {
225 - my @svn_co = ('svn','co',"-r$base->{revision}");
226 - push @svn_co,'--ignore-externals' unless $_no_ignore_ext;
227 - sys(@svn_co, $SVN_URL, $SVN_WC);
225 + svn_cmd_checkout($SVN_URL,$base->{revision},$SVN_WC);
226 chdir $SVN_WC or croak $!;
227 + read_uuid();
228 $last_commit = git_commit($base, @parents);
229 assert_svn_wc_clean($base->{revision}, $last_commit);
230 } else {
231 chdir $SVN_WC or croak $!;
232 + read_uuid();
233 $last_commit = file_to_s("$REV_DIR/$base->{revision}");
234 }
235 my @svn_up = qw(svn up);
@@ -275,7 +275,9 @@ sub commit {
275
276 fetch();
277 chdir $SVN_WC or croak $!;
278 - my $svn_current_rev = svn_info('.')->{'Last Changed Rev'};
278 + my $info = svn_info('.');
279 + read_uuid($info);
280 + my $svn_current_rev = $info->{'Last Changed Rev'};
281 foreach my $c (@revs) {
282 my $mods = svn_checkout_tree($svn_current_rev, $c);
283 if (scalar @$mods == 0) {
@@ -314,6 +316,14 @@ sub show_ignore {
316
317 ########################### utility functions #########################
318
319 +sub read_uuid {
320 + return if $SVN_UUID;
321 + my $info = shift || svn_info('.');
322 + $SVN_UUID = $info->{'Repository UUID'} or
323 + croak "Repository UUID unreadable\n";
324 + s_to_file($SVN_UUID,"$GIT_DIR/$GIT_SVN/info/uuid");
325 +}
326 +
327 sub setup_git_svn {
328 defined $SVN_URL or croak "SVN repository location required\n";
329 unless (-d $GIT_DIR) {
@@ -323,14 +333,10 @@ sub setup_git_svn {
333 mkpath(["$GIT_DIR/$GIT_SVN/info"]);
334 mkpath([$REV_DIR]);
335 s_to_file($SVN_URL,"$GIT_DIR/$GIT_SVN/info/url");
326 - $SVN_UUID = svn_info($SVN_URL)->{'Repository UUID'} or
327 - croak "Repository UUID unreadable\n";
328 - s_to_file($SVN_UUID,"$GIT_DIR/$GIT_SVN/info/uuid");
336
337 open my $fd, '>>', "$GIT_DIR/$GIT_SVN/info/exclude" or croak $!;
338 print $fd '.svn',"\n";
339 close $fd or croak $!;
333 - return $SVN_UUID;
340 }
341
342 sub assert_svn_wc_clean {
@@ -860,7 +866,6 @@ sub git_commit {
866 my ($log_msg, @parents) = @_;
867 assert_revision_unknown($log_msg->{revision});
868 my $out_fh = IO::File->new_tmpfile or croak $!;
863 - $SVN_UUID ||= svn_info('.')->{'Repository UUID'};
869
870 map_tree_joins() if (@_branch_from && !%tree_map);
871
@@ -922,7 +927,16 @@ sub git_commit {
927 }
928 my @update_ref = ('git-update-ref',"refs/remotes/$GIT_SVN",$commit);
929 if (my $primary_parent = shift @exec_parents) {
925 - push @update_ref, $primary_parent;
930 + $pid = fork;
931 + defined $pid or croak $!;
932 + if (!$pid) {
933 + close STDERR;
934 + close STDOUT;
935 + exec 'git-rev-parse','--verify',
936 + "refs/remotes/$GIT_SVN^0";
937 + }
938 + waitpid $pid, 0;
939 + push @update_ref, $primary_parent unless $?;
940 }
941 sys(@update_ref);
942 sys('git-update-ref',"$GIT_SVN/revs/$log_msg->{revision}",$commit);
@@ -995,13 +1009,26 @@ sub safe_qx {
1009 return wantarray ? @ret : join('',@ret);
1010 }
1011
998 -sub svn_check_ignore_externals {
999 - return if $_no_ignore_ext;
1000 - unless (grep /ignore-externals/,(safe_qx(qw(svn co -h)))) {
1012 +sub svn_compat_check {
1013 + my @co_help = safe_qx(qw(svn co -h));
1014 + unless (grep /ignore-externals/,@co_help) {
1015 print STDERR "W: Installed svn version does not support ",
1016 "--ignore-externals\n";
1017 $_no_ignore_ext = 1;
1018 }
1019 + if (grep /usage: checkout URL\[\@REV\]/,@co_help) {
1020 + $_svn_co_url_revs = 1;
1021 + }
1022 +}
1023 +
1024 +# *sigh*, new versions of svn won't honor -r<rev> without URL@<rev>,
1025 +# (and they won't honor URL@<rev> without -r<rev>, too!)
1026 +sub svn_cmd_checkout {
1027 + my ($url, $rev, $dir) = @_;
1028 + my @cmd = ('svn','co', "-r$rev");
1029 + push @cmd, '--ignore-externals' unless $_no_ignore_ext;
1030 + $url .= "\@$rev" if $_svn_co_url_revs;
1031 + sys(@cmd, $url, $dir);
1032 }
1033
1034 sub check_upgrade_needed {
contrib/git-svn/git-svn.txt
+30 -2
@@ -175,8 +175,8 @@ COMPATIBILITY OPTIONS
175 Do not use this flag unless you know exactly what you're getting
176 yourself into. You have been warned.
177
178 -Examples
179 -~~~~~~~~
178 +Basic Examples
179 +~~~~~~~~~~~~~~
180
181 Tracking and contributing to an Subversion managed-project:
182
@@ -234,6 +234,34 @@ This allows you to tie unfetched SVN revision 375 to your current HEAD::
234
235 git-svn fetch 375=$(git-rev-parse HEAD)
236
237 +Advanced Example: Tracking a Reorganized Repository
238 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
239 +If you're tracking a directory that has moved, or otherwise been
240 +branched or tagged off of another directory in the repository and you
241 +care about the full history of the project, then you can read this
242 +section.
243 +
244 +This is how Yann Dirson tracked the trunk of the ufoai directory when
245 +the /trunk directory of his repository was moved to /ufoai/trunk and
246 +he needed to continue tracking /ufoai/trunk where /trunk left off.
247 +
248 + # This log message shows when the repository was reorganized::
249 + r166 | ydirson | 2006-03-02 01:36:55 +0100 (Thu, 02 Mar 2006) | 1 line
250 + Changed paths:
251 + D /trunk
252 + A /ufoai/trunk (from /trunk:165)
253 +
254 + # First we start tracking the old revisions::
255 + GIT_SVN_ID=git-oldsvn git-svn init \
256 + https://svn.sourceforge.net/svnroot/ufoai/trunk
257 + GIT_SVN_ID=git-oldsvn git-svn fetch -r1:165
258 +
259 + # And now, we continue tracking the new revisions::
260 + GIT_SVN_ID=git-newsvn git-svn init \
261 + https://svn.sourceforge.net/svnroot/ufoai/ufoai/trunk
262 + GIT_SVN_ID=git-newsvn git-svn fetch \
263 + 166=`git-rev-parse refs/remotes/git-oldsvn`
264 +
265 BUGS
266 ----
267 If somebody commits a conflicting changeset to SVN at a bad moment