chiark / gitweb /
dgit-repos-server: Deal with FRESHREPO from push hook
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 21 Mar 2015 12:04:01 +0000 (12:04 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 22 Mar 2015 15:19:51 +0000 (15:19 +0000)
Debian/Dgit.pm
infra/dgit-repos-policy-debian
infra/dgit-repos-server

index a124930b39a6adf47953f5a0c604af3e9254bf52..b93477402c72dc3a3662c7a99cab81d6735b66b2 100644 (file)
@@ -30,7 +30,7 @@ sub NOFFCHECK () { return 2; }
 
 sub FRESHREPO () { return 4; }
 # blow away repo right away (ie, as if before push or fetch)
-# ("check-package" only)
+# ("check-package" and "push" only)
 
 
 sub debiantag ($) { 
index 4ba3e8e144432071193092f6fd61223d265f01ff..493fefdd6d9233c3d85056c6483888589c58e238 100755 (executable)
@@ -12,6 +12,8 @@
 # cwd for push is a temporary repo where the to-be-pushed objects have
 #  been received; TAGNAME is the version-based tag
 #
+# if push requested FRESHREPO, push-confirm happens in said fresh repo
+#
 # policy hook for a particular package will be invoked only once at
 # a time
 
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 () {