summaryrefslogtreecommitdiff
path: root/Debian
diff options
context:
space:
mode:
Diffstat (limited to 'Debian')
-rw-r--r--Debian/Dgit.pm33
1 files changed, 31 insertions, 2 deletions
diff --git a/Debian/Dgit.pm b/Debian/Dgit.pm
index 3d97848..1f9c827 100644
--- a/Debian/Dgit.pm
+++ b/Debian/Dgit.pm
@@ -30,6 +30,7 @@ use Digest::SHA;
use Data::Dumper;
use IPC::Open2;
use File::Path;
+use File::Basename;
BEGIN {
use Exporter ();
@@ -59,10 +60,11 @@ BEGIN {
shellquote printcmd messagequote
$negate_harmful_gitattrs
git_slurp_config_src
- workarea_setup);
+ workarea_setup
+ fresh_workarea in_workarea);
# implicitly uses $main::us
%EXPORT_TAGS = ( policyflags => [qw(NOFFCHECK FRESHREPO NOCOMMITCHECK)] );
- @EXPORT_OK = @{ $EXPORT_TAGS{policyflags} };
+ @EXPORT_OK = ( qw($wa), @{ $EXPORT_TAGS{policyflags} } );
}
our @EXPORT_OK;
@@ -464,4 +466,31 @@ sub workarea_setup ($) {
close GA or die $!;
}
+our $wa;
+our $local_git_cfg;
+
+sub in_workarea ($;$) {
+ my $sub = pop @_; # in_workarea [$twa, sub { ... };]
+ # default $twa is global $wa (which caller must, in that case, set)
+ # $twa should be relative paths of the form .git/FOO/BAR
+ my ($twa) = @_;
+ $twa //= $wa;
+ chdir $twa or die "$twa $!";
+ my $r = eval { $sub->($twa); };
+ chdir '../../..' or die "$@; $!";
+ die $@ if length $@;
+ return $r;
+}
+
+sub fresh_workarea (;$) {
+ my ($twa) = @_;
+ $twa //= $wa;
+ $local_git_cfg //= git_slurp_config_src 'local';
+ my $parent = dirname $twa;
+ mkdir $parent or $!==EEXIST or fail "failed to mkdir $parent: $!";
+ rmtree $twa;
+ mkdir $twa or die "$twa $!";
+ in_workarea sub { workarea_setup $local_git_cfg; };
+}
+
1;