X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=infra%2Fdgit-ssh-dispatch;h=9c023d80859fecd63cbc6ca64dfc925818bfc473;hp=4769d895830f5aa154e49fc0cc94f069a9e68bb4;hb=067e68de07f7d1cf1d406c4917e9cdd7b0b6f26a;hpb=850c5e51043c2eb3a9804877314edefb6156e816 diff --git a/infra/dgit-ssh-dispatch b/infra/dgit-ssh-dispatch index 4769d895..9c023d80 100755 --- a/infra/dgit-ssh-dispatch +++ b/infra/dgit-ssh-dispatch @@ -21,19 +21,20 @@ $authrune //= join ':', 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 -# policy-hook +# 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 ($distro,$pkg, $d); our ($dgitlive,$repos,$suites,$diverts,$policyhook,$repo); sub checkdivert ($) { @@ -73,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; @@ -111,30 +112,48 @@ 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'}; + local ($_) = $ENV{'SSH_ORIGINAL_COMMAND'} // ''; if (m#^: dgit ($lre) git-check ($lre) ;#) { selectpackage $1,$2, sub { prl "divert @_"; finish; }; 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, $distro, $suites, $authrune, $repos, - $policyhook, 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 ($_)"; }