chiark / gitweb /
dgit: unpack_playtree_need_cd_work: Make idempotent
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 26 May 2019 11:31:11 +0000 (12:31 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 28 Jun 2019 11:45:38 +0000 (12:45 +0100)
This won't be able to recover from a truly-messed-up "work" but this
is good enough not to have to explicitly arrange for each place that
uses it to know whether it has been done already.

Checking in the filesystem is OK because mktree_in_ud_here calls
playtree_setup which expects the playground to have been set up
already - ie, all our callers have called prep_ud already.
Add a comment about this requirement.

No overall functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
dgit

diff --git a/dgit b/dgit
index 149345dd23073630b932e9953d955b072750d898..b0c60c4a86e377b3b047b8a95e8ac47289fb6f15 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -5850,12 +5850,18 @@ END
     }
 }
 
-sub unpack_playtree_mk_cd_work ($) {
+sub unpack_playtree_need_cd_work ($) {
     my ($headref) = @_;
 
-    mkdir "work" or confess "$!";
-    changedir "work";
-    mktree_in_ud_here();
+    # prep_ud() must have been called already.
+    if (!chdir "work") {
+       # Check in the filesystem because sometimes we run prep_ud
+       # in between multiple calls to unpack_playtree_need_cd_work.
+       confess "$!" unless $!==ENOENT;
+       mkdir "work" or confess "$!";
+       changedir "work";
+       mktree_in_ud_here();
+    }
     runcmd @git, qw(reset -q --hard), $headref;
 }
 
@@ -5904,7 +5910,7 @@ sub quilt_fixup_singlepatch ($$$) {
     # necessary to build the source package.
 
     unpack_playtree_linkorigs($upstreamversion, sub { });
-    unpack_playtree_mk_cd_work($headref);
+    unpack_playtree_need_cd_work($headref);
 
     rmtree("debian/patches");
 
@@ -6026,7 +6032,7 @@ sub quilt_check_splitbrain_cache ($$) {
        "refs/$splitbraincache", $splitbrain_cachekey;
 
     if ($cachehit) {
-       unpack_playtree_mk_cd_work($headref);
+       unpack_playtree_need_cd_work($headref);
        my $saved = maybe_split_brain_save $headref, $cachehit, "cache-hit";
        if ($cachehit ne $headref) {
            progress f_ "dgit view: found cached (%s)", $saved;
@@ -6145,7 +6151,7 @@ END
 
     changedir '..';
 
-    unpack_playtree_mk_cd_work($headref);
+    unpack_playtree_need_cd_work($headref);
 
     my $mustdeletepc=0;
     if (stat_exists ".pc") {
@@ -6722,7 +6728,7 @@ sub build_source {
         unless ($split_brain) {
             my $upstreamversion = upstreamversion $version;
             unpack_playtree_linkorigs($upstreamversion, sub { });
-            unpack_playtree_mk_cd_work($headref);
+            unpack_playtree_need_cd_work($headref);
             changedir '..';
         }
     } else {