git-svn: "git worktree" awareness

git-svn internals were previously not aware of repository
layout differences for users of the "git worktree" command.
Introduce this awareness by using "git rev-parse --git-path"
instead of relying on outdated uses of GIT_DIR and friends.

Thanks-to: Duy Nguyen <pclouds@gmail.com>
Reported-by: Mathieu Arnold <mat@freebsd.org>
Signed-off-by: Eric Wong <e@80x24.org>
This commit is contained in:
Eric Wong
2016-10-14 00:27:54 +00:00
parent b26098fc2f
commit 112423eb90
3 changed files with 42 additions and 28 deletions

View File

@ -807,10 +807,15 @@ sub get_fetch_range {
(++$min, $max);
}
sub svn_dir {
command_oneline(qw(rev-parse --git-path svn));
}
sub tmp_config {
my (@args) = @_;
my $old_def_config = "$ENV{GIT_DIR}/svn/config";
my $config = "$ENV{GIT_DIR}/svn/.metadata";
my $svn_dir = svn_dir();
my $old_def_config = "$svn_dir/config";
my $config = "$svn_dir/.metadata";
if (! -f $config && -f $old_def_config) {
rename $old_def_config, $config or
die "Failed rename $old_def_config => $config: $!\n";
@ -1671,7 +1676,7 @@ sub tie_for_persistent_memoization {
return if $memoized;
$memoized = 1;
my $cache_path = "$ENV{GIT_DIR}/svn/.caches/";
my $cache_path = svn_dir() . '/.caches/';
mkpath([$cache_path]) unless -d $cache_path;
my %lookup_svn_merge_cache;
@ -1712,7 +1717,7 @@ sub tie_for_persistent_memoization {
sub clear_memoized_mergeinfo_caches {
die "Only call this method in non-memoized context" if ($memoized);
my $cache_path = "$ENV{GIT_DIR}/svn/.caches/";
my $cache_path = svn_dir() . '/.caches/';
return unless -d $cache_path;
for my $cache_file (("$cache_path/lookup_svn_merge",
@ -2446,12 +2451,13 @@ sub _new {
"refs/remotes/$prefix$default_ref_id";
}
$_[1] = $repo_id;
my $dir = "$ENV{GIT_DIR}/svn/$ref_id";
my $svn_dir = svn_dir();
my $dir = "$svn_dir/$ref_id";
# Older repos imported by us used $GIT_DIR/svn/foo instead of
# $GIT_DIR/svn/refs/remotes/foo when tracking refs/remotes/foo
# Older repos imported by us used $svn_dir/foo instead of
# $svn_dir/refs/remotes/foo when tracking refs/remotes/foo
if ($ref_id =~ m{^refs/remotes/(.+)}) {
my $old_dir = "$ENV{GIT_DIR}/svn/$1";
my $old_dir = "$svn_dir/$1";
if (-d $old_dir && ! -d $dir) {
$dir = $old_dir;
}
@ -2461,7 +2467,7 @@ sub _new {
mkpath([$dir]);
my $obj = bless {
ref_id => $ref_id, dir => $dir, index => "$dir/index",
config => "$ENV{GIT_DIR}/svn/config",
config => "$svn_dir/config",
map_root => "$dir/.rev_map", repo_id => $repo_id }, $class;
# Ensure it gets canonicalized