chiark / gitweb /
playground refactoring: Dgit.pm: Provide ensure_a_playground
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 2 Aug 2017 17:34:02 +0000 (18:34 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 3 Aug 2017 08:57:52 +0000 (09:57 +0100)
dgit wants to make a lot of temporary things in .git/dgit.
That's like a playground, but dgit doesn't want it wiped.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Debian/Dgit.pm

index 473c01e..de37261 100644 (file)
@@ -64,7 +64,8 @@ BEGIN {
     # implicitly uses $main::us
     %EXPORT_TAGS = ( policyflags => [qw(NOFFCHECK FRESHREPO NOCOMMITCHECK)],
                     playground => [qw(record_maindir $maindir $local_git_cfg
-                                      fresh_playground $playground)]);
+                                      fresh_playground $playground
+                                       ensure_a_playground)]);
     @EXPORT_OK   = ( @{ $EXPORT_TAGS{policyflags} },
                     @{ $EXPORT_TAGS{playground} } );
 }
@@ -491,6 +492,11 @@ sub git_slurp_config_src ($) {
 #       createing different playgrounds; but $playground global can
 #       refer only to one, obv.
 #
+#    ensure_a_playground SUBDIR_PATH_COMPONENTS
+#      like fresh_playground except:
+#      merely ensures the directory exists; does not delete an existing one
+#      never sets global $playground
+#
 #  then can use
 #
 #    changedir $playground
@@ -515,12 +521,25 @@ sub record_maindir () {
 
 our $playground;
 
-sub fresh_playground ($) {
+sub ensure_a_playground_parent ($) {
     my ($spc) = @_;
     record_maindir();
     $spc = ".git/$spc";
     my $parent = dirname $spc;
     mkdir $parent or $!==EEXIST or fail "failed to mkdir $parent: $!";
+    return $spc;
+}    
+
+sub ensure_a_playground ($) {
+    my ($spc) = @_;
+    $spc = ensure_a_playground_parent $spc;
+    mkdir $spc or $!==EEXIST or fail "failed to mkdir a playground $spc: $!";
+    return $spc;
+}    
+
+sub fresh_playground ($) {
+    my ($spc) = @_;
+    $spc = ensure_a_playground_parent $spc;
     rmtree $spc;
     mkdir $spc or die "$spc $!";
     return $playground = "$maindir/$spc";