5 # dgit-repos-server DISTRO DISTRO-DIR AUTH-SPEC [<settings>] --ssh
6 # dgit-repos-server DISTRO DISTRO-DIR AUTH-SPEC [<settings>] --cron
8 # --repos=GIT-REPOS-DIR default DISTRO-DIR/repos/
9 # --suites=SUITES-FILE default DISTRO-DIR/suites
10 # --policy-hook=POLICY-HOOK default DISTRO-DIR/policy-hook
11 # --dgit-live=DGIT-LIVE-DIR default DISTRO-DIR/dgit-live
12 # (DISTRO-DIR is not used other than as default and to pass to policy hook)
14 # .../dgit-repos-server --pre-receive-hook PACKAGE
16 # Invoked as the ssh restricted command
18 # Works like git-receive-pack
20 # SUITES is the name of a file which lists the permissible suites
21 # one per line (#-comments and blank lines ignored)
23 # AUTH-SPEC is a :-separated list of
24 # KEYRING.GPG,AUTH-SPEC
25 # where AUTH-SPEC is one of
28 # (With --cron AUTH-SPEC is not used and may be the empty string.)
31 $SIG{__WARN__} = sub { die $_[0]; };
33 # DGIT-REPOS-DIR contains:
34 # git tree (or other object) lock (in acquisition order, outer first)
36 # _tmp/PACKAGE_prospective ! } SAME.lock, held during receive-pack
38 # _tmp/PACKAGE_incoming$$ ! } SAME.lock, held during receive-pack
39 # _tmp/PACKAGE_incoming$$_fresh ! }
41 # PACKAGE.git } PACKAGE.git.lock
42 # PACKAGE_garbage } (also covers executions of
43 # PACKAGE_garbage-old } policy hook script for PACKAGE)
44 # PACKAGE_garbage-tmp }
45 # policy* } (for policy hook script, covered by
46 # } lock only when invoked for a package)
48 # leaf locks, held during brief operaton only:
53 # _template } SAME.lock
55 # locks marked ! may be held during client data transfer
57 # What we do on push is this:
58 # - extract the destination repo name
59 # - make a hardlink clone of the destination repo
60 # - provide the destination with a stunt pre-receive hook
61 # - run actual git-receive-pack with that new destination
62 # as a result of this the stunt pre-receive hook runs; it does this:
63 # + understand what refs we are allegedly updating and
64 # check some correspondences:
65 # * we are updating only refs/tags/debian/* and refs/dgit/*
66 # * and only one of each
67 # * and the tag does not already exist
69 # * recover the suite name from the destination refs/dgit/ ref
70 # + disassemble the signed tag into its various fields and signature
72 # * parsing the first line of the tag message to recover
73 # the package name, version and suite
74 # * checking that the package name corresponds to the dest repo name
75 # * checking that the suite name is as recovered above
76 # + verify the signature on the signed tag
77 # and if necessary check that the keyid and package are listed in dm.txt
78 # + check various correspondences:
79 # * the signed tag must refer to a commit
80 # * the signed tag commit must be the refs/dgit value
81 # * the name in the signed tag must correspond to its ref name
82 # * the tag name must be debian/<version> (massaged as needed)
83 # * the suite is one of those permitted
84 # * the signed tag has a suitable name
85 # * run the "push" policy hook
86 # * replay prevention for --deliberately-not-fast-forward
87 # * check the commit is a fast forward
88 # * handle a request from the policy hook for a fresh repo
89 # + push the signed tag and new dgit branch to the actual repo
91 # If the destination repo does not already exist, we need to make
92 # sure that we create it reasonably atomically, and also that
93 # we don't every have a destination repo containing no refs at all
94 # (because such a thing causes git-fetch-pack to barf). So then we
95 # do as above, except:
96 # - before starting, we take out our own lock for the destination repo
97 # - we create a prospective new destination repo by making a copy
99 # - we use the prospective new destination repo instead of the
100 # actual new destination repo (since the latter doesn't exist)
101 # - after git-receive-pack exits, we
102 # + check that the prospective repo contains a tag and head
103 # + rename the prospective destination repo into place
106 # - We are crash-only
107 # - Temporary working trees and their locks are cleaned up
108 # opportunistically by a program which tries to take each lock and
109 # if successful deletes both the tree and the lockfile
110 # - Prospective working trees and their locks are cleaned up by
111 # a program which tries to take each lock and if successful
112 # deletes any prospective working tree and the lock (but not
113 # of course any actual tree)
114 # - It is forbidden to _remove_ the lockfile without removing
115 # the corresponding temporary tree, as the lockfile is also
116 # a stampfile whose presence indicates that there may be
119 # Policy hook script is invoked like this:
120 # POLICY-HOOK-SCRIPT DISTRO DGIT-REPOS-DIR DGIT-LIVE-DIR DISTRO-DIR ACTION...
122 # POLICY-HOOK-SCRIPT ... check-list [...]
123 # POLICY-HOOK-SCRIPT ... check-package PACKAGE [...]
124 # POLICY-HOOK-SCRIPT ... push PACKAGE \
125 # VERSION SUITE TAGNAME DELIBERATELIES [...]
126 # POLICY-HOOK-SCRIPT ... push-confirm PACKAGE \
127 # VERSION SUITE TAGNAME DELIBERATELIES FRESH-REPO|'' [...]
129 # Exit status is a bitmask. Bit weight constants are defined in Dgit.pm.
131 # suppress dgit-repos-server's fast-forward check ("push" only)
133 # blow away repo right away (ie, as if before push or fetch)
134 # ("check-package" and "push" only)
135 # any unexpected bits mean failure, and then known set bits are ignored
136 # if no unexpected bits set, operation continues (subject to meaning
137 # of any expected bits set). So, eg, exit 0 means "continue normally"
138 # and would be appropriate for an unknown action.
140 # cwd for push and push-confirm is a temporary repo where the
141 # to-be-pushed objects have been received; TAGNAME is the
144 # FRESH-REPO is '' iff the repo for this package already existed, or
145 # the pathname of the newly-created repo which will be renamed into
146 # place if everything goes well. (NB that this is generally not the
147 # same repo as the cwd, because the objects are first received into a
148 # temporary repo so they can be examined.)
150 # if push requested FRESHREPO, push-confirm happens in said fresh repo
151 # and FRESH-REPO is guaranteed not to be ''.
153 # policy hook for a particular package will be invoked only once at
154 # a time - (see comments about DGIT-REPOS-DIR, above)
156 # check-list and check-package are invoked via the --cron option.
157 # First, without any locking, check-list is called. It should produce
158 # a list of package names (one per line). Then check-package will be
159 # invoked for each named package, in each case after taking an
162 # If policy hook wants to run dgit (or something else in the dgit
163 # package), it should use DGIT-LIVE-DIR/dgit (etc.)
167 use Fcntl qw(:flock);
168 use File::Path qw(rmtree);
169 use File::Temp qw(tempfile);
171 use Debian::Dgit qw(:DEFAULT :policyflags);
192 #----- utilities -----
194 sub realdestrepo () { "$dgitrepos/$package.git"; }
196 sub acquirelock ($$) {
197 my ($lock, $must) = @_;
199 printdebug sprintf "locking %s %d\n", $lock, $must;
202 $fh = new IO::File $lock, ">" or die "open $lock: $!";
203 my $ok = flock $fh, $must ? LOCK_EX : (LOCK_EX|LOCK_NB);
205 die "flock $lock: $!" if $must;
206 printdebug " locking $lock failed\n";
209 next unless stat_exists $lock;
210 my $want = (stat _)[1];
212 my $got = (stat _)[1];
213 last if $got == $want;
218 sub acquirermtree ($$) {
219 my ($tree, $must) = @_;
220 my $fh = acquirelock("$tree.lock", $must);
228 sub locksometree ($) {
230 acquirelock("$tree.lock", 1);
233 sub lockrealtree () {
234 locksometree(realdestrepo);
237 sub mkrepotmp () { ensuredir "$dgitrepos/_tmp" };
239 sub removedtagsfile () { "$dgitrepos/_removed-tags/$package"; }
241 sub recorderror ($) {
243 my $w = $ENV{'DGIT_DRS_WORK'}; # we are in stunthook
246 open ERR, ">", "$w/drs-error" or die $!;
247 print ERR $why, "\n" or die $!;
256 recorderror "reject: $why";
257 die "dgit-repos-server: reject: $why\n";
264 die (shellquote @_)." $? $!" if $r;
268 my ($policyallowbits, @polargs) = @_;
269 # => ($exitstatuspolicybitmap);
270 die if $policyallowbits & ~0x3e;
271 my @cmd = ($policyhook,$distro,$dgitrepos,$dgitlive,$distrodir,@polargs);
274 die "system: $!" if $r < 0;
275 die "dgit-repos-server: policy hook failed (or rejected) ($?)\n"
276 if $r & ~($policyallowbits << 8);
277 printdebug sprintf "hook => %#x\n", $r;
281 sub mkemptyrepo ($$) {
282 my ($dir,$sharedperm) = @_;
283 runcmd qw(git init --bare --quiet), "--shared=$sharedperm", $dir;
286 sub mkrepo_fromtemplate ($) {
288 my $template = "$dgitrepos/_template";
289 locksometree($template);
290 printdebug "copy template $template -> $dir\n";
291 my $r = system qw(cp -a --), $template, $dir;
292 !$r or die "create new repo $dir failed: $r $!";
295 sub movetogarbage () {
296 # realdestrepo must have been locked
297 my $garbagerepo = "$dgitrepos/${package}_garbage";
298 # We arrange to always keep at least one old tree, for anti-rewind
299 # purposes (and, I guess, recovery from mistakes). This is either
300 # $garbage or $garbage-old.
301 if (stat_exists "$garbagerepo") {
302 printdebug "movetogarbage: rmtree $garbagerepo-tmp\n";
303 rmtree "$garbagerepo-tmp";
304 if (rename "$garbagerepo-old", "$garbagerepo-tmp") {
305 printdebug "movetogarbage: $garbagerepo-old -> -tmp, rmtree\n";
306 rmtree "$garbagerepo-tmp";
308 die "$garbagerepo $!" unless $!==ENOENT;
309 printdebug "movetogarbage: $garbagerepo-old -> -tmp\n";
311 printdebug "movetogarbage: $garbagerepo -> -old\n";
312 rename "$garbagerepo", "$garbagerepo-old" or die "$garbagerepo $!";
314 my $real = realdestrepo;
315 printdebug "movetogarbage: $real -> $garbagerepo\n";
316 rename $real, $garbagerepo
318 or die "$garbagerepo $!";
321 sub policy_checkpackage () {
322 my $lfh = lockrealtree();
324 $policy = policyhook(FRESHREPO,'check-package',$package);
325 if ($policy & FRESHREPO) {
332 #----- git-receive-pack -----
334 sub fixmissing__git_receive_pack () {
336 $destrepo = "$dgitrepos/_tmp/${package}_prospective";
337 acquirermtree($destrepo, 1);
338 mkrepo_fromtemplate($destrepo);
341 sub makeworkingclone () {
343 $workrepo = "$dgitrepos/_tmp/${package}_incoming$$";
344 acquirermtree($workrepo, 1);
345 my $lfh = lockrealtree();
346 runcmd qw(git clone -l -q --mirror), $destrepo, $workrepo;
348 rmtree "${workrepo}_fresh";
351 sub setupstunthook () {
352 my $prerecv = "$workrepo/hooks/pre-receive";
353 my $fh = new IO::File $prerecv, O_WRONLY|O_CREAT|O_TRUNC, 0777
354 or die "$prerecv: $!";
355 print $fh <<END or die "$prerecv: $!";
358 exec $0 --pre-receive-hook $package
360 close $fh or die "$prerecv: $!";
361 $ENV{'DGIT_DRS_WORK'}= $workrepo;
362 $ENV{'DGIT_DRS_DEST'}= $destrepo;
363 printdebug " stunt hook set up $prerecv\n";
366 sub dealwithfreshrepo () {
367 my $freshrepo = "${workrepo}_fresh";
368 return unless stat_exists $freshrepo;
369 $destrepo = $freshrepo;
372 sub maybeinstallprospective () {
373 return if $destrepo eq realdestrepo;
375 if (open REJ, "<", "$workrepo/drs-error") {
378 REJ->error and die $!;
382 $!==&ENOENT or die $!;
385 printdebug " show-ref ($destrepo) ...\n";
387 my $child = open SR, "-|";
388 defined $child or die $!;
390 chdir $destrepo or die $!;
391 exec qw(git show-ref);
394 my %got = qw(tag 0 head 0);
397 printdebug " show-refs| $_\n";
398 s/^\S*[1-9a-f]\S* (\S+)$/$1/ or die;
400 m{^refs/tags/} ? 'tag' :
401 m{^refs/dgit/} ? 'head' :
405 $!=0; $?=0; close SR or $?==256 or die "$? $!";
407 printdebug "installprospective ?\n";
408 die Dumper(\%got)." -- missing refs in new repo"
409 if grep { !$_ } values %got;
413 if ($destrepo eq "${workrepo}_fresh") {
417 printdebug "install $destrepo => ".realdestrepo."\n";
418 rename $destrepo, realdestrepo or die $!;
419 remove "$destrepo.lock" or die $!;
422 sub main__git_receive_pack () {
425 runcmd qw(git receive-pack), $workrepo;
427 maybeinstallprospective();
430 #----- stunt post-receive hook -----
432 our ($tagname, $tagval, $suite, $oldcommit, $commit);
433 our ($version, %tagh);
436 printdebug " updates ...\n";
439 printdebug " upd.| $_\n";
440 m/^(\S+) (\S+) (\S+)$/ or die "$_ ?";
441 my ($old, $sha1, $refname) = ($1, $2, $3);
442 if ($refname =~ m{^refs/tags/(?=debian/)}) {
443 reject "pushing multiple tags!" if defined $tagname;
446 reject "tag $tagname already exists -".
447 " not replacing previously-pushed version"
449 } elsif ($refname =~ m{^refs/dgit/}) {
450 reject "pushing multiple heads!" if defined $suite;
455 reject "pushing unexpected ref!";
458 STDIN->error and die $!;
460 reject "push is missing tag ref update" unless defined $tagname;
461 reject "push is missing head ref update" unless defined $suite;
462 printdebug " updates ok.\n";
466 printdebug " parsetag...\n";
467 open PT, ">dgit-tmp/plaintext" or die $!;
468 open DS, ">dgit-tmp/plaintext.asc" or die $!;
469 open T, "-|", qw(git cat-file tag), $tagval or die $!;
471 $!=0; $_=<T>; defined or die $!;
473 if (m/^(\S+) (.*)/) {
474 push @{ $tagh{$1} }, $2;
481 $!=0; $_=<T>; defined or die $!;
482 m/^($package_re) release (\S+) for \S+ \((\S+)\) \[dgit\]$/ or
483 reject "tag message not in expected format";
485 die unless $1 eq $package;
487 die "$3 != $suite " unless $3 eq $suite;
491 print PT $copyl or die $!;
492 $!=0; $_=<T>; defined or die "missing signature? $!";
494 if (m/^\[dgit ([^"].*)\]$/) { # [dgit "something"] is for future
497 if (s/^distro\=(\S+) //) {
498 die "$1 != $distro" unless $1 eq $distro;
499 } elsif (s/^(--deliberately-$deliberately_re) //) {
500 push @deliberatelies, $1;
501 } elsif (s/^supersede:(\S+)=(\w+) //) {
502 die "supersede $1 twice" if defined $supersedes{$1};
503 $supersedes{$1} = $2;
504 } elsif (s/^[-+.=0-9a-z]\S* //) {
506 die "unknown dgit info in tag ($_)";
511 last if m/^-----BEGIN PGP/;
522 printdebug " parsetag ok.\n";
525 sub checksig_keyring ($) {
526 my ($keyringfile) = @_;
527 # returns primary-keyid if signed by a key in this keyring
529 # or dies on other errors
533 printdebug " checksig keyring $keyringfile...\n";
535 our @cmd = (qw(gpgv --status-fd=1 --keyring),
537 qw(dgit-tmp/plaintext.asc dgit-tmp/plaintext));
544 next unless s/^\[GNUPG:\] //;
546 printdebug " checksig| $_\n";
547 my @l = split / /, $_;
548 if ($l[0] eq 'NO_PUBKEY') {
550 } elsif ($l[0] eq 'VALIDSIG') {
552 $sigtype eq '00' or reject "signature is not of type 00!";
554 die unless defined $ok;
560 printdebug sprintf " checksig ok=%d\n", !!$ok;
565 sub dm_txt_check ($$) {
566 my ($keyid, $dmtxtfn) = @_;
567 printdebug " dm_txt_check $keyid $dmtxtfn\n";
568 open DT, '<', $dmtxtfn or die "$dmtxtfn $!";
570 m/^fingerprint:\s+$keyid$/oi
572 if (s/^allow:/ /i..0) {
575 or reject "key $keyid missing Allow section in permissions!";
580 or reject "package $package not allowed for key $keyid";
585 printdebug " dm_txt_check allow| $_\n";
586 foreach my $p (split /\s+/) {
587 if ($p eq $package) {
589 printdebug " dm_txt_check ok\n";
594 DT->error and die $!;
596 reject "key $keyid not in permissions list although in keyring!";
600 foreach my $kas (split /:/, $keyrings) {
601 printdebug "verifytag $kas...\n";
602 $kas =~ s/^([^,]+),// or die;
603 my $keyid = checksig_keyring $1;
604 if (defined $keyid) {
605 if ($kas =~ m/^a$/) {
606 printdebug "verifytag a ok\n";
608 } elsif ($kas =~ m/^m([^,]+)$/) {
609 dm_txt_check($keyid, $1);
610 printdebug "verifytag m ok\n";
617 reject "key not found in keyrings";
621 printdebug "checksuite ($suitesfile)\n";
622 open SUITES, "<", $suitesfile or die $!;
628 return if $_ eq $suite;
630 die $! if SUITES->error;
631 reject "unknown suite";
634 sub checktagnoreplay () {
635 # We check that the signed tag mentions the name and value of
636 # (a) in the case of FRESHREPO all tags in the repo;
637 # (b) in the case of just NOFFCHECK all tags referring to
638 # the current head for the suite (there must be at least one).
639 # This prevents a replay attack using an earlier signed tag.
640 return unless $policy & (FRESHREPO|NOFFCHECK);
642 my $garbagerepo = "$dgitrepos/${package}_garbage";
646 foreach my $garb ("$garbagerepo", "$garbagerepo-old") {
647 if (stat_exists $garb) {
648 $ENV{GIT_DIR} = $garb;
652 if (!defined $ENV{GIT_DIR}) {
653 # Nothing to overwrite so the FRESHREPO and NOFFCHECK were
654 # pointless. Oh well.
655 printdebug "checktagnoreplay - no garbage, ok\n";
660 if (!($policy & FRESHREPO)) {
661 my $branch = server_branch($suite);
663 `git for-each-ref --format='%(objectname)' '[r]efs/$branch'`;
664 defined or die "$branch $? $!";
665 $? and die "$branch $?";
667 # No such branch - NOFFCHECK was unnecessary. Oh well.
668 printdebug "checktagnoreplay - not FRESHREPO, new branch, ok\n";
671 m/^(\w+)\n$/ or die "$branch $_ ?";
673 printdebug "checktagnoreplay - not FRESHREPO,".
674 " checking for overwriting refs/$branch=$onlyreferring\n";
679 git_for_each_tag_referring($onlyreferring, sub {
680 my ($objid,$refobjid,$fullrefname,$tagname) = @_;
681 printdebug "checktagnoreplay - overwriting $fullrefname=$objid\n";
682 my $supers = $supersedes{$fullrefname};
683 if (!defined $supers) {
684 push @problems, "does not supersede $fullrefname";
685 } elsif ($supers ne $objid) {
687 "supersedes $fullrefname=$supers but previously $fullrefname=$objid";
694 reject "replay attack prevention check failed:".
695 " signed tag for $version: ".
696 join("; ", @problems).
699 printdebug "checktagnoreply - all ok\n"
704 my $vals = $tagh{$tag};
705 reject "missing header $tag in signed tag object" unless $vals;
706 reject "multiple headers $tag in signed tag object" unless @$vals == 1;
711 printdebug "checks\n";
713 tagh1('type') eq 'commit' or reject "tag refers to wrong kind of object";
714 tagh1('object') eq $commit or reject "tag refers to wrong commit";
715 tagh1('tag') eq $tagname or reject "tag name in tag is wrong";
720 printdebug "translated version $v\n";
721 $tagname eq "debian/$v" or die;
725 my @policy_args = ($package,$version,$suite,$tagname,
726 join(",",@deliberatelies));
727 $policy = policyhook(NOFFCHECK|FRESHREPO, 'push', @policy_args);
732 # check that our ref is being fast-forwarded
733 printdebug "oldcommit $oldcommit\n";
734 if (!($policy & NOFFCHECK) && $oldcommit =~ m/[^0]/) {
735 $?=0; $!=0; my $mb = `git merge-base $commit $oldcommit`;
737 $mb eq $oldcommit or reject "not fast forward on dgit branch";
740 if ($policy & FRESHREPO) {
741 # This is troublesome. We have been asked by the policy hook
742 # to receive the push into a fresh repo. But of course we
743 # have actually already mostly received the push into the working
744 # repo. (This is unavoidable because the instruction to use a new
745 # repo comes ultimately from the signed tag for the dgit push,
746 # which has to have been received into some repo.)
748 # So what we do is generate a fresh working repo right now and
749 # push the head and tag into it. The presence of this fresh
750 # working repo is detected by the parent, which responds by
751 # making a fresh master repo from the template.
753 $destrepo = "${workrepo}_fresh"; # workrepo lock covers
754 mkrepo_fromtemplate $destrepo;
757 my $willinstall = ($destrepo eq realdestrepo ? '' : $destrepo);
758 policyhook(0, 'push-confirm', @policy_args, $willinstall);
762 my @cmd = (qw(git send-pack), $destrepo);
763 push @cmd, qw(--force) if $policy & NOFFCHECK;
764 push @cmd, "$commit:refs/dgit/$suite",
765 "$tagval:refs/tags/$tagname";
769 !$r or die "onward push to $destrepo failed: $r $!";
773 printdebug "stunthook in $workrepo\n";
774 chdir $workrepo or die "chdir $workrepo: $!";
775 mkdir "dgit-tmp" or $!==EEXIST or die $!;
781 printdebug "stunthook done.\n";
784 #----- git-upload-pack -----
786 sub fixmissing__git_upload_pack () {
787 $destrepo = "$dgitrepos/_empty";
788 my $lfh = locksometree($destrepo);
789 return if stat_exists $destrepo;
790 rmtree "$destrepo.new";
791 mkemptyrepo "$destrepo.new", "0644";
792 rename "$destrepo.new", $destrepo or die $!;
793 unlink "$destrepo.lock" or die $!;
797 sub main__git_upload_pack () {
798 my $lfh = locksometree($destrepo);
799 printdebug "git-upload-pack in $destrepo\n";
800 chdir $destrepo or die "$destrepo: $!";
802 runcmd qw(git upload-pack), ".";
805 #----- arg parsing and main program -----
815 # keys are used for DGIT_DRS_XXX too
816 'repos' => \$dgitrepos,
817 'suites' => \$suitesfile,
818 'policy-hook' => \$policyhook,
819 'dgit-live' => \$dgitlive,
822 our @hookenvs = qw(distro suitesfile policyhook
823 dgitlive keyrings dgitrepos distrodir);
825 # workrepo and destrepo handled ad-hoc
830 my $cmd = $ENV{'SSH_ORIGINAL_COMMAND'};
840 or reject "command string not understood";
846 my $mainfunc = $main::{"main__$funcn"};
848 reject "unknown method" unless $mainfunc;
850 policy_checkpackage();
852 if (stat_exists realdestrepo) {
853 $destrepo = realdestrepo;
855 printdebug " fixmissing $funcn\n";
856 my $fixfunc = $main::{"fixmissing__$funcn"};
860 printdebug " running main $funcn\n";
867 my $listfh = tempfile();
868 open STDOUT, ">&", $listfh or die $!;
869 policyhook(0,'check-list');
870 open STDOUT, ">&STDERR" or die $!;
872 seek $listfh, 0, 0 or die $!;
877 die unless m/^($package_re)$/;
880 policy_checkpackage();
882 die $! if $listfh->error;
885 sub parseargsdispatch () {
888 delete $ENV{'GIT_DIR'}; # if not run via ssh, our parent git process
889 delete $ENV{'GIT_PREFIX'}; # sets these and they mess things up
891 if ($ENV{'DGIT_DRS_DEBUG'}) {
895 if ($ARGV[0] eq '--pre-receive-hook') {
898 printdebug "in stunthook ".(shellquote @ARGV)."\n";
899 foreach my $k (sort keys %ENV) {
900 printdebug "$k=$ENV{$k}\n" if $k =~ m/^DGIT/;
905 $package = shift @ARGV;
906 ${ $main::{$_} } = $ENV{"DGIT_DRS_\U$_"} foreach @hookenvs;
907 defined($workrepo = $ENV{'DGIT_DRS_WORK'}) or die;
908 defined($destrepo = $ENV{'DGIT_DRS_DEST'}) or die;
909 open STDOUT, ">&STDERR" or die $!;
914 recorderror "$@" or die;
921 $distrodir = argval();
922 $keyrings = argval();
924 foreach my $dk (keys %indistrodir) {
925 ${ $indistrodir{$dk} } = "$distrodir/$dk";
928 while (@ARGV && $ARGV[0] =~ m/^--([-0-9a-z]+)=/ && $indistrodir{$1}) {
929 ${ $indistrodir{$1} } = $'; #';
933 $ENV{"DGIT_DRS_\U$_"} = ${ $main::{$_} } foreach @hookenvs;
937 my $mode = shift @ARGV;
938 die unless $mode =~ m/^--(\w+)$/;
939 my $fn = ${*::}{"mode_$1"};
945 while (my $fh = pop @lockfhs) { close $fh; }
950 if (!chdir "$dgitrepos/_tmp") {
951 $!==ENOENT or die $!;
954 foreach my $lf (<*.lock>) {
956 $tree =~ s/\.lock$//;
957 next unless acquirermtree($tree, 0);
958 remove $lf or warn $!;