@matheusbsbs / matheus-bagliano / commits / 74b1e12357
Fork 0

git-svn: make rebuild respect rewriteRoot option

Suppose someone fetches git-svn-ified commits from another repo and then attempts to use 'git-svn init --rewrite-root=foo bar'. Using git svn rebase after that will fail badly: * For each commit tried by working_head_info, rebuild is called indirectly. * rebuild will iterate over all commits and skip all of them because the URL does not match. Because of that no rev_map file is generated at all. * Thus, rebuild will run once for every commit. This takes ages. * In the end there still isn't any rev_map file and thus working_head_info fails. Addressing this behaviour fixes an apparently not too uncommon problem with providing git-svn mirrors of Subversion repositories. Some repositories are accessed using different URLs depending on whether the user has push privileges or not. In the latter case, an anonymous URL is often used that differs from the push URL. Providing a mirror that is usable in both cases becomes a lot more possible with this change. Signed-off-by: Jan Krüger <jk@jk.gs> Acked-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jan Krüger committed Jun 24, 2008 at 02:17 UTC 74b1e1235781bbe5c90b802c1551446a5f5d69f1
2 files changed +35 -3
git-svn.perl
+3 -3
@@ -2577,8 +2577,8 @@ sub rebuild {
2577 my ($log, $ctx) =
2578 command_output_pipe(qw/rev-list --pretty=raw --no-color --reverse/,
2579 $self->refname, '--');
2580 - my $full_url = $self->full_url;
2581 - remove_username($full_url);
2580 + my $metadata_url = $self->metadata_url;
2581 + remove_username($metadata_url);
2582 my $svn_uuid = $self->ra_uuid;
2583 my $c;
2584 while (<$log>) {
@@ -2596,7 +2596,7 @@ sub rebuild {
2596 # if we merged or otherwise started elsewhere, this is
2597 # how we break out of it
2598 if (($uuid ne $svn_uuid) ||
2599 - ($full_url && $url && ($url ne $full_url))) {
2599 + ($metadata_url && $url && ($url ne $metadata_url))) {
2600 next;
2601 }
2602
t/t9123-git-svn-rebuild-with-rewriteroot.sh new
+32
@@ -0,0 +1,32 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2008 Jan Krüger
4 +#
5 +
6 +test_description='git-svn respects rewriteRoot during rebuild'
7 +
8 +. ./lib-git-svn.sh
9 +
10 +mkdir import
11 +cd import
12 + touch foo
13 + svn import -m 'import for git-svn' . "$svnrepo" >/dev/null
14 +cd ..
15 +rm -rf import
16 +
17 +test_expect_success 'init, fetch and checkout repository' '
18 + git svn init --rewrite-root=http://invalid.invalid/ "$svnrepo" &&
19 + git svn fetch
20 + git checkout -b mybranch remotes/git-svn
21 + '
22 +
23 +test_expect_success 'remove rev_map' '
24 + rm "$GIT_SVN_DIR"/.rev_map.*
25 + '
26 +
27 +test_expect_success 'rebuild rev_map' '
28 + git svn rebase >/dev/null
29 + '
30 +
31 +test_done
32 +