git: Turn $git_dir into a stack

This will be necessary when we use a secondary working tree to do
reverts without leaving the primary working tree in an inconsistent
state.
master
Simon McVittie 2016-12-28 18:02:59 +00:00
parent ad04dac19b
commit 39b8931ad3
1 changed files with 8 additions and 8 deletions

View File

@ -153,13 +153,13 @@ sub genwrapper {
} }
} }
my $git_dir=undef; my @git_dir_stack;
my $prefix=undef; my $prefix;
sub in_git_dir ($$) { sub in_git_dir ($$) {
$git_dir=shift; unshift @git_dir_stack, shift;
my @ret=shift->(); my @ret=shift->();
$git_dir=undef; shift @git_dir_stack;
$prefix=undef; $prefix=undef;
return @ret; return @ret;
} }
@ -178,13 +178,13 @@ sub safe_git (&@) {
if (!$pid) { if (!$pid) {
# In child. # In child.
# Git commands want to be in wc. # Git commands want to be in wc.
if (! defined $git_dir) { if (! @git_dir_stack) {
chdir $config{srcdir} chdir $config{srcdir}
or error("cannot chdir to $config{srcdir}: $!"); or error("cannot chdir to $config{srcdir}: $!");
} }
else { else {
chdir $git_dir chdir $git_dir_stack[0]
or error("cannot chdir to $git_dir: $!"); or error("cannot chdir to $git_dir_stack[0]: $!");
} }
exec @cmdline or error("Cannot exec '@cmdline': $!"); exec @cmdline or error("Cannot exec '@cmdline': $!");
} }
@ -919,7 +919,7 @@ sub git_parse_changes {
die $@ if $@; die $@ if $@;
my $fh; my $fh;
($fh, $path)=File::Temp::tempfile(undef, UNLINK => 1); ($fh, $path)=File::Temp::tempfile(undef, UNLINK => 1);
my $cmd = "cd $git_dir && ". my $cmd = "cd $git_dir_stack[0] && ".
"git show $detail->{sha1_to} > '$path'"; "git show $detail->{sha1_to} > '$path'";
if (system($cmd) != 0) { if (system($cmd) != 0) {
error("failed writing temp file '$path'."); error("failed writing temp file '$path'.");