our @ourdscfield = qw(Dgit Vcs-Dgit-Master);
our $branchprefix = 'dgit';
our $csuite;
+our $instead_distro;
sub lbranch () { return "$branchprefix/$csuite"; }
my $lbranch_re = '^refs/heads/'.$branchprefix.'/([^/.]+)$';
'dgit.default.archive-query' => 'madison:',
'dgit.default.sshpsql-dbname' => 'service=projectb',
'dgit-distro.debian.archive-query' => 'sshpsql:',
- 'dgit-distro.debian.git-host' => 'git.debian.org',
+ 'dgit-distro.debian.git-host' => 'dgit-git.debian.net',
+ 'dgit-distro.debian.git-user-force' => 'dgit',
'dgit-distro.debian.git-proto' => 'git+ssh://',
- 'dgit-distro.debian.git-path' => '/git/dgit-repos/repos',
+ 'dgit-distro.debian.git-path' => '/dgit/debian/repos',
+ 'dgit-distro.debian.diverts.alioth' => '/alioth',
+ 'dgit-distro.debian/alioth.git-host' => 'git.debian.org',
+ 'dgit-distro.debian/alioth.git-user-force' => '',
+ 'dgit-distro.debian/alioth.git-proto' => 'git+ssh://',
+ 'dgit-distro.debian/alioth.git-path' => '/git/dgit-repos/repos',
'dgit-distro.debian.git-check' => 'ssh-cmd',
'dgit-distro.debian.git-create' => 'ssh-cmd',
'dgit-distro.debian.sshpsql-host' => 'mirror.ftp-master.debian.org',
sub access_basedistro () {
if (defined $idistro) {
- return cfg("dgit-distro.basedistro.distro",
- "dgit-suite.$isuite.distro",
- 'RETURN-UNDEF') // $idistro;
+ return $idistro;
} else {
return cfg("dgit-suite.$isuite.distro",
"dgit.default.distro");
}
sub access_quirk () {
- # returns (quirk name, distro to use instead, quirk-specific info)
+ # returns (quirk name, distro to use instead or undef, quirk-specific info)
my $basedistro = access_basedistro();
my $backports_quirk = cfg("dgit-distro.$basedistro.backports-quirk",
'RETURN-UNDEF');
return ('backports',"$basedistro-backports",$1);
}
}
- return ('none',$basedistro);
+ return ('none',undef);
}
-sub access_distro () {
- return (access_quirk())[1];
+sub access_distros () {
+ # Returns list of distros to try, in order
+ #
+ # We want to try:
+ # 0. `instead of' distro name(s) we have been pointed to
+ # 1. the access_quirk distro, if any
+ # 2a. the user's specified distro, or failing that } basedistro
+ # 2b. the distro calculated from the suite }
+ my @l = access_basedistro();
+
+ my (undef,$quirkdistro) = access_quirk();
+ unshift @l, $quirkdistro;
+ unshift @l, $instead_distro;
+ return grep { defined } @l;
}
sub access_cfg (@) {
my (@keys) = @_;
- my $basedistro = access_basedistro();
- my $distro = $idistro || access_distro();
- my $value = cfg(map {
- ("dgit-distro.$distro.$_",
- "dgit-distro.$basedistro.$_",
- "dgit.default.$_")
- } @keys);
+ my @cfgs;
+ # The nesting of these loops determines the search order. We put
+ # the key loop on the outside so that we search all the distros
+ # for each key, before going on to the next key. That means that
+ # if access_cfg is called with a more specific, and then a less
+ # specific, key, an earlier distro can override the less specific
+ # without necessarily overriding any more specific keys. (If the
+ # distro wants to override the more specific keys it can simply do
+ # so; whereas if we did the loop the other way around, it would be
+ # impossible to for an earlier distro to override a less specific
+ # key but not the more specific ones without restating the unknown
+ # values of the more specific keys.
+ my @realkeys;
+ my @rundef;
+ # We have to deal with RETURN-UNDEF specially, so that we don't
+ # terminate the search prematurely.
+ foreach (@keys) {
+ if (m/RETURN-UNDEF/) { push @rundef, $_; last; }
+ push @realkeys, $_
+ }
+ foreach my $d (access_distros()) {
+ push @cfgs, map { "dgit-distro.$d.$_" } @realkeys;
+ }
+ push @cfgs, map { "dgit.default.$_" } @realkeys;
+ push @cfgs, @rundef;
+ my $value = cfg(@cfgs);
return $value;
}
}
}
+sub access_runeinfo ($) {
+ my ($info) = @_;
+ return ": dgit ".access_basedistro()." $info ;";
+}
+
sub access_someuserhost ($) {
my ($some) = @_;
- my $user = access_cfg("$some-user",'username');
+ my $user = access_cfg("$some-user-force", 'RETURN-UNDEF');
+ defined($user) && length($user) or
+ $user = access_cfg("$some-user",'username');
my $host = access_cfg("$some-host");
return length($user) ? "$user\@$host" : $host;
}
return "/pool/$component/$prefix/$package/".dscfn($vsn);
}
-sub archive_query_madison ($$) {
+sub archive_query_madison {
+ return map { [ @$_[0..1] ] } madison_get_parse(@_);
+}
+
+sub madison_get_parse {
my ($proto,$data) = @_;
die unless $proto eq 'madison';
if (!length $data) {
- $data= access_cfg('madison-distro',access_basedistro());
+ $data= access_cfg('madison-distro','RETURN-UNDEF');
+ $data //= access_basedistro();
}
- $rmad{$package} ||= cmdoutput
+ $rmad{$proto,$data,$package} ||= cmdoutput
qw(rmadison -asource),"-s$isuite","-u$data",$package;
- my $rmad = $rmad{$package};
- return madison_parse($rmad);
-}
+ my $rmad = $rmad{$proto,$data,$package};
-sub madison_parse ($) {
- my ($rmad) = @_;
my @out;
foreach my $l (split /\n/, $rmad) {
$l =~ m{^ \s*( [^ \t|]+ )\s* \|
return sort { -version_compare($a->[0],$b->[0]); } @out;
}
-sub canonicalise_suite_madison ($$) {
+sub canonicalise_suite_madison {
# madison canonicalises for us
- my @r = archive_query_madison($_[0],$_[1]);
+ my @r = madison_get_parse(@_);
@r or fail
"unable to canonicalise suite using package $package".
" which does not appear to exist in suite $isuite;".
return $r[0][2];
}
-sub sshpsql ($$) {
- my ($data,$sql) = @_;
+sub sshpsql ($$$) {
+ my ($data,$runeinfo,$sql) = @_;
if (!length $data) {
$data= access_someuserhost('sshpsql').':'.
access_cfg('sshpsql-dbname');
my ($userhost,$dbname) = ($`,$'); #';
my @rows;
my @cmd = (access_cfg_ssh, $userhost,
- "export LANG=C; ".shellquote qw(psql -A), $dbname, qw(-c), $sql);
+ access_runeinfo("ssh-psql $runeinfo").
+ " export LANG=C;".
+ " ".shellquote qw(psql -A), $dbname, qw(-c), $sql);
printcmd(\*DEBUG,$debugprefix."|",@cmd) if $debug>0;
open P, "-|", @cmd or die $!;
while (<P>) {
}
sub sql_injection_check {
- foreach (@_) { die "$_ $& ?" if m/[']/; }
+ foreach (@_) { die "$_ $& ?" if m{[^-+=:_.,/0-9a-zA-Z]}; }
}
sub archive_query_sshpsql ($$) {
my ($proto,$data) = @_;
sql_injection_check $isuite, $package;
- my @rows = sshpsql($data, <<END);
+ my @rows = sshpsql($data, "archive-query $isuite $package", <<END);
SELECT source.version, component.name, files.filename, files.sha256sum
FROM source
JOIN src_associations ON source.id = src_associations.source
sub canonicalise_suite_sshpsql ($$) {
my ($proto,$data) = @_;
sql_injection_check $isuite;
- my @rows = sshpsql($data, <<END);
+ my @rows = sshpsql($data, "canonicalise-suite $isuite", <<END);
SELECT suite.codename
FROM suite where suite_name='$isuite' or codename='$isuite';
END
$dsc = undef;
}
+sub check_for_git ();
sub check_for_git () {
# returns 0 or 1
my $how = access_cfg('git-check');
if ($how eq 'ssh-cmd') {
my @cmd =
(access_cfg_ssh, access_gituserhost(),
+ access_runeinfo("git-check $package").
" set -e; cd ".access_cfg('git-path').";".
" if test -d $package.git; then echo 1; else echo 0; fi");
my $r= cmdoutput @cmd;
+ if ($r =~ m/^divert (\w+)$/) {
+ my $divert=$1;
+ my ($usedistro,) = access_distros();
+ $instead_distro= cfg("dgit-distro.$usedistro.diverts.$divert");
+ $instead_distro =~ s{^/}{ access_basedistro()."/" }e;
+ printdebug "diverting $divert so using distro $instead_distro\n";
+ return check_for_git();
+ }
failedcmd @cmd unless $r =~ m/^[01]$/;
return $r+0;
} elsif ($how eq 'true') {
if ($how eq 'ssh-cmd') {
runcmd_ordryrun
(access_cfg_ssh, access_gituserhost(),
+ access_runeinfo("git-create $package").
"set -e; cd ".access_cfg('git-path').";".
" cp -a _template $package.git");
} elsif ($how eq 'true') {
my ($dstdir) = @_;
canonicalise_suite();
badusage "dry run makes no sense with clone" unless act_local();
+ my $hasgit = check_for_git();
mkdir $dstdir or die "$dstdir $!";
changedir $dstdir;
runcmd @git, qw(init -q);
close H or die $!;
runcmd @git, qw(remote add), 'origin', $giturl;
}
- if (check_for_git()) {
+ if ($hasgit) {
progress "fetching existing git history";
git_fetch_us();
runcmd_ordryrun_local @git, qw(fetch origin);