X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=infra%2Fdgit-ssh-dispatch;h=ed9a23d5685079b61cfff82bc1044ea9cd245bab;hp=b515edad988391635275fd4c54c7400a2eb7e9aa;hb=8cba3f92026d48c5792f64ed996f9aab942cc9e6;hpb=1b2c10f57b0257aac61a696378e9c8c05df8bf4f diff --git a/infra/dgit-ssh-dispatch b/infra/dgit-ssh-dispatch index b515edad..ed9a23d5 100755 --- a/infra/dgit-ssh-dispatch +++ b/infra/dgit-ssh-dispatch @@ -3,6 +3,8 @@ use strict; use POSIX; +use Debian::Dgit; + open DEBUG, '>/dev/null' or die $!; if (@ARGV && $ARGV[0] eq '-D') { shift @ARGV; @@ -16,22 +18,24 @@ $authrune //= join ':', '@/keyrings/debian-keyring.gpg,a', '@/keyrings/debian-maintainers.gpg,m@/dm.txt'; -our $lre = '[0-9a-z][-+.0-9a-z]*'; +our $lre = $package_re; our $qre = '["'."']?"; -# $dispatchdir should contain -# dgit-live a clone of dgit -# repos/ -# suites +# $dispatchdir/distro=DISTRO should contain +# dgit-live a clone of dgit (only if not using installed vsns) # diverts +# repos/ } by virtue of +# suites } dgit-repos-server's defaults relating to +# policy-hook } dispatch-dir # plus files required by the authrune (by default, keyrings/ and dm.txt) # # diverts should be list of # [] # where is a package name pattern which may contain * or literals. +# is for `git config dgit-distro.DISTRO.diverts.' -our ($distro,$pkg); -our ($dgitlive,$repos,$suites,$diverts,$repo); +our ($distro,$pkg, $d); +our ($dgitlive,$repos,$suites,$diverts,$policyhook,$repo); sub checkdivert ($) { my ($df) = @_; @@ -70,7 +74,7 @@ sub selectpackage ($$;$) { my $divertfn; ($distro,$pkg, $divertfn) = @_; # $distro,$pkg must have sane syntax - my $d = "$dispatchdir/distro=$distro"; + $d = "$dispatchdir/distro=$distro"; if (!stat $d) { die $! unless $!==ENOENT; @@ -80,6 +84,7 @@ sub selectpackage ($$;$) { $dgitlive= "$d/dgit-live"; $repos= "$d/repos"; $suites= "$d/suites"; + $policyhook= "$d/policy-hook"; $authrune =~ s/\@/$d/g; @@ -107,6 +112,12 @@ sub hasrepo () { } } +sub serve_up ($) { + my ($repo) = @_; + exec qw(git upload-pack --strict --timeout=1000), $repo; + die "exec git: $!"; +} + sub dispatch () { local ($_) = $ENV{'SSH_ORIGINAL_COMMAND'}; @@ -115,21 +126,34 @@ sub dispatch () { prl hasrepo; finish; } elsif ( - m#^${qre}git-([-a-z]+) ${qre}/dgit/($lre)/repos/($lre)\.git${qre}$# - ) { + m#^${qre}git-([-a-z]+) ${qre}/dgit/($lre)/repos/($lre)\.git${qre}$# + ) { my $cmd=$1; selectpackage $2,$3; if ($cmd eq 'receive-pack') { + $ENV{'PERLLIB'} //= ''; + $ENV{'PERLLIB'} =~ s#^(?=.)#:#; + $ENV{'PERLLIB'} =~ s#^# $ENV{DGIT_TEST_INTREE} // $dgitlive #e; my $s = "$dgitlive/infra/dgit-repos-server"; - exec $s, $suites, $authrune, $repos, qw(--ssh); + $s = "dgit-repos-server" if !stat_exists $s; + exec $s, $distro, $d, $authrune, qw(--ssh); die "exec $s: $!"; } elsif ($cmd eq 'upload-pack') { $repo='$repos/_empty' unless hasrepo; - exec qw(git upload-pack --strict --timeout=1000), $repo; - die "exec git: $!"; + serve_up $repo; } else { die "unsupported git operation $cmd ($_)"; } + } elsif ( + m#^${qre}git-upload-pack ${qre}/dgit/($lre)/(?:repos/)?_dgit-repos-server\.git${qre}$# + ) { + my $distro= $1; + # if running installed packages, source code should come + # some other way + serve_up("$dispatchdir/distro=$1/dgit-live/.git"); + } elsif (m#^${qre}git-upload-pack\s#) { + die "unknown repo to serve ($_). use dgit, or for server source ". + "git clone here:/dgit/DISTRO/repos/_dgit-repos-server.git"; } else { die "unsupported operation ($_)"; }