chiark / gitweb /
dgit-repos-server: Deal with FRESHREPO from push hook
[dgit.git] / infra / dgit-repos-server
index ef9f968ea268ac379b2a0cd617389fb3d8fe4a67..5599061de2a68cb8e997c66f2d81e48c489688a9 100755 (executable)
@@ -247,6 +247,7 @@ sub makeworkingclone () {
     $workrepo = "$dgitrepos/_tmp/${package}_incoming$$";
     acquiretree($workrepo, 1);
     runcmd qw(git clone -l -q --mirror), $destrepo, $workrepo;
+    rmtree "${workrepo}_fresh";
 }
 
 sub setupstunthook () {
@@ -264,6 +265,15 @@ END
     debug " stunt hook set up $prerecv";
 }
 
+sub dealwithfreshrepo () {
+    my $freshrepo = "${workrepo}_fresh";
+    if (!stat $freshrepo) {
+       $!==ENOENT or die "$freshrepo $!";
+       return;
+    }
+    $destrepo = $freshrepo;
+}
+
 sub maybeinstallprospective () {
     return if $destrepo eq $realdestrepo;
 
@@ -303,6 +313,8 @@ sub maybeinstallprospective () {
     die Dumper(\%got)." -- missing refs in new repo"
        if grep { !$_ } values %got;
 
+    movetogarbage; # in case of FRESHREPO
+
     debug "install $destrepo => $realdestrepo";
     rename $destrepo, $realdestrepo or die $!;
     remove "$destrepo.lock" or die $!;
@@ -312,6 +324,7 @@ sub main__git_receive_pack () {
     makeworkingclone();
     setupstunthook();
     runcmd qw(git receive-pack), $workrepo;
+    dealwithfreshrepo();
     maybeinstallprospective();
 }
 
@@ -547,6 +560,23 @@ sub checks () {
        chomp $mb;
        $mb eq $oldcommit or reject "not fast forward on dgit branch";
     }
+
+    if ($policy & FRESHREPO) {
+       # This is troublesome.  We have been asked by the policy hook
+       # to receive the push into a fresh repo.  But of course we
+       # have actually already mostly received the push into the working
+       # repo.  (This is unavoidable because the instruction to use a new
+       # repo comes ultimately from the signed tag for the dgit push,
+       # which has to have been received into some repo.)
+       #
+       # So what we do is generate a fresh working repo right now and
+       # push the head and tag into it.  The presence of this fresh
+       # working repo is detected by the parent, which responds by
+       # making a fresh master repo from the template.
+
+       $destrepo = "${workrepo}_fresh"; # workrepo lock covers
+       mkrepo_fromtemplate $destrepo;
+    }
 }
 
 sub stunthook () {