chiark / gitweb /
dgit: unpack_playtree_need_cd_work: Make idempotent
[dgit.git] / dgit
diff --git a/dgit b/dgit
index cf12faeafe3cc048c940712e3e3f431b256644de..b0c60c4a86e377b3b047b8a95e8ac47289fb6f15 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -5400,10 +5400,7 @@ sub quiltify_splitbrain ($$$$$$$) {
     local $ENV{GIT_AUTHOR_EMAIL} = $authline[1];
     local $ENV{GIT_AUTHOR_DATE} =  $authline[2];
 
-    die if $split_brain;
     die unless $do_split_brain;
-    runcmd @git, qw(checkout -q -b dgit-view);
-    $split_brain = 1;
 
     my $fulldiffhint = sub {
        my ($x,$y) = @_;
@@ -5853,12 +5850,18 @@ END
     }
 }
 
-sub unpack_playtree_mkwork ($) {
+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;
 }
 
@@ -5907,7 +5910,7 @@ sub quilt_fixup_singlepatch ($$$) {
     # necessary to build the source package.
 
     unpack_playtree_linkorigs($upstreamversion, sub { });
-    unpack_playtree_mkwork($headref);
+    unpack_playtree_need_cd_work($headref);
 
     rmtree("debian/patches");
 
@@ -6029,7 +6032,7 @@ sub quilt_check_splitbrain_cache ($$) {
        "refs/$splitbraincache", $splitbrain_cachekey;
 
     if ($cachehit) {
-       unpack_playtree_mkwork($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;
@@ -6148,7 +6151,7 @@ END
 
     changedir '..';
 
-    unpack_playtree_mkwork($headref);
+    unpack_playtree_need_cd_work($headref);
 
     my $mustdeletepc=0;
     if (stat_exists ".pc") {
@@ -6225,6 +6228,11 @@ END
     push @failsuggestion, [ 'origs', __
  "Maybe orig tarball(s) are not identical to git representation?" ];
 
+    if ($do_split_brain) {
+       runcmd @git, qw(checkout -q -b dgit-view);
+       die if $split_brain;
+       $split_brain = 1;
+    }
     if (quiltmode_splitbrain()) {
        quiltify_splitbrain($clogp, $unapplied, $headref, $oldtiptree,
                             $diffbits, \%editedignores,
@@ -6720,7 +6728,7 @@ sub build_source {
         unless ($split_brain) {
             my $upstreamversion = upstreamversion $version;
             unpack_playtree_linkorigs($upstreamversion, sub { });
-            unpack_playtree_mkwork($headref);
+            unpack_playtree_need_cd_work($headref);
             changedir '..';
         }
     } else {