chiark / gitweb /
Do some quoting on debug output (needed if the server might not be trustworthy and...
[dgit.git] / dgit
diff --git a/dgit b/dgit
index 079e5dec7c212c0c4ea1be9ecb76f4891af75cfb..8f4a71c2a3683087b020520dcc05fea6eb8a1fe5 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -461,6 +461,7 @@ our %defcfg = ('dgit.default.distro' => 'debian',
 #   '--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/push.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://',
@@ -485,20 +486,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 +549,12 @@ sub access_quirk () {
     return ('none',undef);
 }
 
+our $access_pushing = 0;
+
+sub pushing () {
+    $access_pushing = 1;
+}
+
 sub access_distros () {
     # Returns list of distros to try, in order
     #
@@ -546,7 +568,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_pushing) {
+       @l = map { ("$_/push", $_) } @l;
+    }
+    @l;
 }
 
 sub access_cfg (@) {
@@ -619,6 +646,7 @@ sub access_gituserhost () {
 sub access_giturl (;$) {
     my ($optional) = @_;
     my $url = access_cfg('git-url','RETURN-UNDEF');
+    my $suffix;
     if (!defined $url) {
        my $proto = access_cfg('git-proto', 'RETURN-UNDEF');
        return undef unless defined $proto;
@@ -626,8 +654,11 @@ sub access_giturl (;$) {
            $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 +1050,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)";
@@ -1935,6 +1967,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 +2021,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 +2082,7 @@ sub i_method {
 }
 
 sub cmd_rpush {
+    pushing();
     my $host = nextarg;
     my $dir;
     if ($host =~ m/^((?:[^][]|\[[^][]*\])*)\:/) {
@@ -2633,10 +2668,18 @@ sub quilt_fixup_editor () {
 sub clean_tree () {
     if ($cleanmode eq 'dpkg-source') {
        runcmd_ordryrun_local @dpkgbuildpackage, qw(-T clean);
+    } elsif ($cleanmode eq 'dpkg-source-d') {
+       runcmd_ordryrun_local @dpkgbuildpackage, qw(-d -T clean);
     } elsif ($cleanmode eq 'git') {
        runcmd_ordryrun_local @git, qw(clean -xdf);
     } elsif ($cleanmode eq 'git-ff') {
        runcmd_ordryrun_local @git, qw(clean -xdff);
+    } elsif ($cleanmode eq 'check') {
+       my $leftovers = cmdoutput @git, qw(clean -xdn);
+       if (length $leftovers) {
+           print STDERR $leftovers, "\n" or die $!;
+           fail "tree contains uncommitted files and --clean=check specified";
+       }
     } elsif ($cleanmode eq 'none') {
     } else {
        die "$cleanmode ?";
@@ -2731,6 +2774,9 @@ sub build_source {
     if ($cleanmode eq 'dpkg-source') {
        runcmd_ordryrun_local (@dpkgbuildpackage, qw(-us -uc -S)),
            changesopts();
+    } elsif ($cleanmode eq 'dpkg-source-d') {
+       runcmd_ordryrun_local (@dpkgbuildpackage, qw(-us -uc -S -d)),
+           changesopts();
     } else {
        my $pwd = must_getcwd();
        my $leafdir = basename $pwd;
@@ -2873,7 +2919,7 @@ sub parseopts () {
            } elsif (m/^--build-products-dir=(.*)/s) {
                push @ropts, $_;
                $buildproductsdir = $1;
-           } elsif (m/^--clean=(dpkg-source|git|git-ff|none)$/s) {
+           } elsif (m/^--clean=(dpkg-source(?:-d)?|git|git-ff|check|none)$/s) {
                push @ropts, $_;
                $cleanmode = $1;
            } elsif (m/^--clean=(.*)$/s) {
@@ -2951,6 +2997,12 @@ sub parseopts () {
                } elsif (s/^-wd$//s) {
                    push @ropts, $&;
                    $cleanmode = 'dpkg-source';
+               } elsif (s/^-wdd$//s) {
+                   push @ropts, $&;
+                   $cleanmode = 'dpkg-source-d';
+               } elsif (s/^-wc$//s) {
+                   push @ropts, $&;
+                   $cleanmode = 'check';
                } else {
                    badusage "unknown short option \`$_'";
                }