# mDM.TXT
use strict;
+$SIG{__WARN__} = sub { die $_[0]; };
# DGIT-REPOS-DIR contains:
# git tree (or other object) lock (in acquisition order, outer first)
our $distro;
our $suitesfile;
our $policyhook;
-our $realdestrepo;
our $destrepo;
our $workrepo;
our $keyrings;
print DEBUG "$debug @_\n";
}
+sub realdestrepo () { "$dgitrepos/$package.git"; }
+
sub acquirelock ($$) {
my ($lock, $must) = @_;
my $fh;
}
sub lockrealtree () {
- locksometree($realdestrepo);
+ locksometree(realdestrepo);
}
sub mkrepotmp () {
}
sub movetogarbage () {
- # $realdestrepo must have been locked
+ # 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
}
rename "$garbagerepo", "$garbagerepo-old" or die "$garbagerepo $!";
}
- rename $realdestrepo, $garbagerepo
+ rename realdestrepo, $garbagerepo
or $! == ENOENT
or die "$garbagerepo $!";
}
}
sub maybeinstallprospective () {
- return if $destrepo eq $realdestrepo;
+ return if $destrepo eq realdestrepo;
if (open REJ, "<", "$workrepo/drs-error") {
local $/ = undef;
movetogarbage;
}
- debug "install $destrepo => $realdestrepo";
- rename $destrepo, $realdestrepo or die $!;
+ debug "install $destrepo => ".realdestrepo;
+ rename $destrepo, realdestrepo or die $!;
remove "$destrepo.lock" or die $!;
}
# workrepo and destrepo handled ad-hoc
+sub mode_ssh () {
+ die if @ARGV;
+
+ my $cmd = $ENV{'SSH_ORIGINAL_COMMAND'};
+ $cmd =~ m{
+ ^
+ (?: \S* / )?
+ ( [-0-9a-z]+ )
+ \s+
+ '? (?: \S* / )?
+ ($package_re) \.git
+ '?$
+ }ox
+ or reject "command string not understood";
+ my $method = $1;
+ $package = $2;
+
+ my $funcn = $method;
+ $funcn =~ y/-/_/;
+ my $mainfunc = $main::{"main__$funcn"};
+
+ reject "unknown method" unless $mainfunc;
+
+ my $lfh = lockrealtree();
+
+ $policy = policyhook(FRESHREPO,'check-package',$package);
+ if ($policy & FRESHREPO) {
+ movetogarbage;
+ }
+
+ close $lfh;
+
+ if (stat_exists realdestrepo) {
+ $destrepo = realdestrepo;
+ } else {
+ debug " fixmissing $funcn";
+ my $fixfunc = $main::{"fixmissing__$funcn"};
+ &$fixfunc;
+ }
+
+ debug " running main $funcn";
+ &$mainfunc;
+}
+
sub parseargsdispatch () {
die unless @ARGV;
$ENV{"DGIT_DRS_\U$_"} = ${ $main::{$_} } foreach @hookenvs;
- die unless @ARGV==1 && $ARGV[0] eq '--ssh';
-
- my $cmd = $ENV{'SSH_ORIGINAL_COMMAND'};
- $cmd =~ m{
- ^
- (?: \S* / )?
- ( [-0-9a-z]+ )
- \s+
- '? (?: \S* / )?
- ($package_re) \.git
- '?$
- }ox
- or reject "command string not understood";
- my $method = $1;
- $package = $2;
- $realdestrepo = "$dgitrepos/$package.git";
-
- my $funcn = $method;
- $funcn =~ y/-/_/;
- my $mainfunc = $main::{"main__$funcn"};
+ die unless @ARGV==1;
- reject "unknown method" unless $mainfunc;
-
- my $lfh = lockrealtree();
-
- $policy = policyhook(FRESHREPO,'check-package',$package);
- if ($policy & FRESHREPO) {
- movetogarbage;
- }
-
- close $lfh;
-
- if (stat_exists $realdestrepo) {
- $destrepo = $realdestrepo;
- } else {
- debug " fixmissing $funcn";
- my $fixfunc = $main::{"fixmissing__$funcn"};
- &$fixfunc;
- }
-
- debug " running main $funcn";
- &$mainfunc;
+ my $mode = shift @ARGV;
+ die unless $mode =~ m/^--(\w+)$/;
+ my $fn = ${*::}{"mode_$1"};
+ die unless $fn;
+ $fn->();
}
sub unlockall () {