chiark / gitweb /
playground refactoring: Dgit.pm: Expose $local_git_cfg
[dgit.git] / Debian / Dgit.pm
index 524ae18a2d73b506c25320ea4a6476dd97f15ac0..515a32f600b805634a8b3991e21b702c603dc56d 100644 (file)
@@ -30,7 +30,6 @@ use Digest::SHA;
 use Data::Dumper;
 use IPC::Open2;
 use File::Path;
-use File::Basename;
 
 BEGIN {
     use Exporter   ();
@@ -60,11 +59,12 @@ BEGIN {
                       shellquote printcmd messagequote
                       $negate_harmful_gitattrs
                      changedir git_slurp_config_src
-                     playtree_setup
-                     fresh_playtree in_playtree);
+                     playtree_setup);
     # implicitly uses $main::us
-    %EXPORT_TAGS = ( policyflags => [qw(NOFFCHECK FRESHREPO NOCOMMITCHECK)] );
-    @EXPORT_OK   = ( qw($wa), @{ $EXPORT_TAGS{policyflags} } );
+    %EXPORT_TAGS = ( policyflags => [qw(NOFFCHECK FRESHREPO NOCOMMITCHECK)],
+                    playground => [qw($local_git_cfg)]);
+    @EXPORT_OK   = ( @{ $EXPORT_TAGS{policyflags} },
+                    @{ $EXPORT_TAGS{playground} } );
 }
 
 our @EXPORT_OK;
@@ -456,9 +456,17 @@ sub git_slurp_config_src ($) {
     return $r;
 }
 
-sub playtree_setup ($) {
-    # for use in the playtree
+# ========== playground handling ==========
+
+#   $local_git_cfg    hash of arrays of values: git config from $maindir
+
+our $local_git_cfg;
+
+# ----- playtrees -----
+
+sub playtree_setup (;$) {
     my ($t_local_git_cfg) = @_;
+    $t_local_git_cfg //= $local_git_cfg;
     # should be run in a directory .git/FOO/BAR of a working tree
     runcmd qw(git init -q);
     runcmd qw(git config gc.auto 0);
@@ -478,31 +486,4 @@ sub playtree_setup ($) {
     close GA or die $!;
 }
 
-our $wa;
-our $local_git_cfg;
-
-sub in_playtree ($;$) {
-    my $sub = pop @_; # in_playtree [$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;
-    changedir $twa or die "$twa $!";
-    my $r = eval { $sub->($twa); };
-    changedir '../../..' or die "$@; $!";
-    die $@ if length $@;
-    return $r;
-}
-
-sub fresh_playtree (;$) {
-    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_playtree sub { playtree_setup $local_git_cfg; };
-}
-
 1;