+sub policyhook {
+ my ($policyallowbits, @polargs) = @_;
+ # => ($exitstatuspolicybitmap);
+ die if $policyallowbits & ~0x3e;
+ my @cmd = ($policyhook,$distro,$repos,@polargs);
+ debugcmd @_;
+ my $r = system @_;
+ die "system: $!" if $r < 0;
+ die "hook (@cmd) failed ($?)" if $r & ~($policyallowbits << 8);
+ return $r >> 8;
+}
+
+sub mkemptyrepo ($$) {
+ my ($dir,$sharedperm) = @_;
+ runcmd qw(git init --bare --quiet), "--shared=$sharedperm", $dir;
+}
+
+sub mkrepo_fromtemplate ($) {
+ my ($dir) = @_;
+ my $template = "$dgitrepos/_template";
+ locksometree($template);
+ debug "copy template $template -> $dir";
+ my $r = system qw(cp -a --), $template, $dir;
+ !$r or die "create new repo $dir failed: $r $!";
+}
+
+sub movetogarbage () {
+ # $realdestrepo must have been locked
+ my $garbagerepo = "$dgitrepos/${package}_garbage";
+ # We arrange to always keep at least one old tree, for anti-rewind
+ # purposes (and, I guess, recovery from mistakes). This is either
+ # $garbage or $garbage-old.
+ if (stat_exists "$garbagerepo") {
+ rmtree "$garbagerepo-tmp";
+ if (rename "$garbagerepo-old", "$garbagerepo-tmp") {
+ rmtree "$garbagerepo-tmp";
+ } else {
+ die "$garbagerepo $!" unless $!==ENOENT;
+ }
+ rename "$garbagerepo", "$garbagerepo-old" or die "$garbagerepo $!";
+ }
+ rename $realdestrepo, $garbagerepo
+ or $! == ENOENT
+ or die "$garbagerepo $!";
+}
+
+sub onwardpush () {
+ my @cmd = (qw(git send-pack), $destrepo);
+ push @cmd, qw(--force) if $policy & NOFFCHECK;
+ push @cmd, "$commit:refs/dgit/$suite",
+ "$tagval:refs/tags/$tagname");
+ debugcmd @cmd;
+ $!=0;
+ my $r = system @cmd;
+ !$r or die "onward push to $destrepo failed: $r $!";
+}
+