chiark / gitweb /
Test suite: Use t-make-hook-link for mirroring
[dgit.git] / dgit
diff --git a/dgit b/dgit
index 1a2ee88feabca1487696f6abf7d3a406329de9b0..9e2e66e4841b4adb690225fab1def69b6229df6d 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -444,12 +444,15 @@ our %defcfg = ('dgit.default.distro' => 'debian',
               'dgit.default.archive-query' => 'madison:',
               'dgit.default.sshpsql-dbname' => 'service=projectb',
               'dgit-distro.debian.archive-query' => 'ftpmasterapi:',
-              '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' => '/dgit/debian/repos',
-              'dgit-distro.debian.git-create' => 'true',
-              'dgit-distro.debian.git-check' => 'ssh-cmd',
+              'dgit-distro.debian.git-check' => 'url',
+              'dgit-distro.debian.git-check-suffix' => '/info/refs',
+              'dgit-distro.debian/push.git-url' => '',
+              'dgit-distro.debian/push.git-host' => 'push.dgit.debian.org',
+              'dgit-distro.debian/push.git-user-force' => 'dgit',
+              'dgit-distro.debian/push.git-proto' => 'git+ssh://',
+              'dgit-distro.debian/push.git-path' => '/dgit/debian/repos',
+              'dgit-distro.debian/push.git-create' => 'true',
+              'dgit-distro.debian/push.git-check' => 'ssh-cmd',
  'dgit-distro.debian.archive-query-url', 'https://api.ftp-master.debian.org/',
 # 'dgit-distro.debian.archive-query-tls-key',
 #    '/etc/ssl/certs/%HOST%.pem:/etc/dgit/%HOST%.pem',
@@ -460,12 +463,8 @@ our %defcfg = ('dgit.default.distro' => 'debian',
 # 'dgit-distro.debian.archive-query-tls-curl-args',
 #   '--ca-path=/etc/ssl/ca-debian',
 # ^ this is a workaround but works (only) on DSA-administered machines
-              '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/alioth.git-create' => 'ssh-cmd',
+              'dgit-distro.debian.git-url' => 'https://git.dgit.debian.org',
+              'dgit-distro.debian.git-url-suffix' => '',
               'dgit-distro.debian.upload-host' => 'ftp-master', # for dput
               'dgit-distro.debian.mirror' => 'http://ftp.debian.org/debian/',
  'dgit-distro.debian.backports-quirk' => '(squeeze)-backports*',
@@ -485,20 +484,35 @@ our %defcfg = ('dgit.default.distro' => 'debian',
               'dgit-distro.test-dummy.upload-host' => 'test-dummy',
                );
 
+sub git_get_config ($) {
+    my ($c) = @_;
+
+    our %git_get_config_memo;
+    if (exists $git_get_config_memo{$c}) {
+       return $git_get_config_memo{$c};
+    }
+
+    my $v;
+    my @cmd = (@git, qw(config --), $c);
+    {
+       local ($debuglevel) = $debuglevel-2;
+       $v = cmdoutput_errok @cmd;
+    };
+    if ($?==0) {
+    } elsif ($?==256) {
+       $v = undef;
+    } else {
+       failedcmd @cmd;
+    }
+    $git_get_config_memo{$c} = $v;
+    return $v;
+}
+
 sub cfg {
     foreach my $c (@_) {
        return undef if $c =~ /RETURN-UNDEF/;
-       my @cmd = (@git, qw(config --), $c);
-       my $v;
-       {
-           local ($debuglevel) = $debuglevel-2;
-           $v = cmdoutput_errok @cmd;
-       };
-       if ($?==0) {
-           return $v;
-       } elsif ($?!=256) {
-           failedcmd @cmd;
-       }
+       my $v = git_get_config($c);
+       return $v if defined $v;
        my $dv = $defcfg{$c};
        return $dv if defined $dv;
     }
@@ -533,6 +547,31 @@ sub access_quirk () {
     return ('none',undef);
 }
 
+our $access_forpush;
+
+sub access_forpush_config () {
+    my $d = access_basedistro();
+    my $v = cfg("dgit-distro.$d.readonly", 'RETURN-UNDEF');
+    $v //= 'a';
+    return
+       $v =~ m/^[ty1]/ ? 0 : # force readonly,    forpush = 0
+       $v =~ m/^[fn0]/ ? 1 : # force nonreadonly, forpush = 1
+       $v =~ m/^[a]/  ? '' : # auto,              forpush = ''
+       badcfg "readonly needs t (true, y, 1) or f (false, n, 0) or a (auto)";
+}
+
+sub access_forpush () {
+    $access_forpush //= access_forpush_config();
+    return $access_forpush;
+}
+
+sub pushing () {
+    die "$access_forpush ?" if ($access_forpush // 1) ne 1;
+    badcfg "pushing but distro is configured readonly"
+       if access_forpush_config() eq '0';
+    $access_forpush = 1;
+}
+
 sub access_distros () {
     # Returns list of distros to try, in order
     #
@@ -546,7 +585,12 @@ sub access_distros () {
     my (undef,$quirkdistro) = access_quirk();
     unshift @l, $quirkdistro;
     unshift @l, $instead_distro;
-    return grep { defined } @l;
+    @l = grep { defined } @l;
+
+    if (access_forpush()) {
+       @l = map { ("$_/push", $_) } @l;
+    }
+    @l;
 }
 
 sub access_cfg (@) {
@@ -619,15 +663,19 @@ sub access_gituserhost () {
 sub access_giturl (;$) {
     my ($optional) = @_;
     my $url = access_cfg('git-url','RETURN-UNDEF');
-    if (!defined $url) {
+    my $suffix;
+    if (!length $url) {
        my $proto = access_cfg('git-proto', 'RETURN-UNDEF');
        return undef unless defined $proto;
        $url =
            $proto.
            access_gituserhost().
            access_cfg('git-path');
+    } else {
+       $suffix = access_cfg('git-url-suffix','RETURN-UNDEF');
     }
-    return "$url/$package.git";
+    $suffix //= '.git';
+    return "$url/$package$suffix";
 }             
 
 sub parsecontrolfh ($$;$) {
@@ -1019,6 +1067,7 @@ sub check_for_git () {
        if ($r =~ m/^divert (\w+)$/) {
            my $divert=$1;
            my ($usedistro,) = access_distros();
+           # NB that if we are pushing, $usedistro will be $distro/push
            $instead_distro= cfg("dgit-distro.$usedistro.diverts.$divert");
            $instead_distro =~ s{^/}{ access_basedistro()."/" }e;
            progress "diverting to $divert (using config for $instead_distro)";
@@ -1026,6 +1075,24 @@ sub check_for_git () {
        }
        failedcmd @cmd unless $r =~ m/^[01]$/;
        return $r+0;
+    } elsif ($how eq 'url') {
+       my $prefix = access_cfg('git-check-url','git-url');
+       my $suffix = access_cfg('git-check-suffix','git-suffix',
+                               'RETURN-UNDEF') // '.git';
+       my $url = "$prefix/$package$suffix";
+       my @cmd = (qw(curl -sS -I), $url);
+       my $result = cmdoutput @cmd;
+       $result =~ m/^\S+ (404|200) /s or
+           fail "unexpected results from git check query - ".
+               Dumper($prefix, $result);
+       my $code = $1;
+       if ($code eq '404') {
+           return 0;
+       } elsif ($code eq '200') {
+           return 1;
+       } else {
+           die;
+       }
     } elsif ($how eq 'true') {
        return 1;
     } elsif ($how eq 'false') {
@@ -1768,12 +1835,6 @@ sub dopush ($) {
            failedcmd @diffcmd;
        }
     }
-#fetch from alioth
-#do fast forward check and maybe fake merge
-#    if (!is_fast_fwd(mainbranch
-#    runcmd @git, qw(fetch -p ), "$alioth_git/$package.git",
-#        map { lref($_).":".rref($_) }
-#        (uploadbranch());
     my $head = git_rev_parse('HEAD');
     if (!$changesfile) {
        my $multi = "$buildproductsdir/".
@@ -1935,6 +1996,7 @@ sub cmd_pull {
 }
 
 sub cmd_push {
+    pushing();
     parseopts();
     badusage "-p is not allowed with dgit push" if defined $package;
     check_not_dirty();
@@ -1988,6 +2050,7 @@ sub cmd_push {
 #---------- remote commands' implementation ----------
 
 sub cmd_remote_push_build_host {
+    pushing();
     my ($nrargs) = shift @ARGV;
     my (@rargs) = @ARGV[0..$nrargs-1];
     @ARGV = @ARGV[$nrargs..$#ARGV];
@@ -2048,6 +2111,7 @@ sub i_method {
 }
 
 sub cmd_rpush {
+    pushing();
     my $host = nextarg;
     my $dir;
     if ($host =~ m/^((?:[^][]|\[[^][]*\])*)\:/) {
@@ -2992,6 +3056,7 @@ my $cmd = shift @ARGV;
 $cmd =~ y/-/_/;
 
 if (!defined $quilt_mode) {
+    local $access_forpush;
     $quilt_mode = cfg('dgit.force.quilt-mode', 'RETURN-UNDEF')
        // access_cfg('quilt-mode', 'RETURN-UNDEF')
        // 'linear';