chiark / gitweb /
Move dgit's debugging arrangements into Dgit.pm
[dgit.git] / dgit
diff --git a/dgit b/dgit
index e5c8eab9a30cc69292cf912252df615549c236ca..268f35673d54e17e7013c682473676d92c6e1046 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -18,6 +18,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 use strict;
+$SIG{__WARN__} = sub { die $_[0]; };
 
 use IO::Handle;
 use Data::Dumper;
@@ -98,9 +99,6 @@ our %opts_opt_cmdonly = ('gpg' => 1);
 
 our $keyid;
 
-our $debug = 0;
-open DEBUG, ">/dev/null" or die $!;
-
 autoflush STDOUT 1;
 
 our $remotename = 'dgit';
@@ -131,7 +129,7 @@ sub dscfn ($) {
 }
 
 our $us = 'dgit';
-our $debugprefix = '';
+initdebug('');
 
 our @end;
 END { 
@@ -159,8 +157,6 @@ sub waitstatusmsg () {
     }
 }
 
-sub printdebug { print DEBUG $debugprefix, @_ or die $!; }
-
 sub fail { 
     my $s = "@_\n";
     my $prefix = $us.($we_are_responder ? " (build host)" : "").": ";
@@ -378,29 +374,6 @@ sub url_get {
 
 our ($dscdata,$dscurl,$dsc,$dsc_checked,$skew_warning_vsn);
 
-sub shellquote {
-    my @out;
-    local $_;
-    foreach my $a (@_) {
-       $_ = $a;
-       if (m{[^-=_./0-9a-z]}i) {
-           s{['\\]}{'\\$&'}g;
-           push @out, "'$_'";
-       } else {
-           push @out, $_;
-       }
-    }
-    return join ' ', @out;
-}
-
-sub printcmd {
-    my $fh = shift @_;
-    my $intro = shift @_;
-    print $fh $intro," " or die $!;
-    print $fh shellquote @_ or die $!;
-    print $fh "\n" or die $!;
-}
-
 sub failedcmd {
     { local ($!); printcmd \*STDERR, "$us: failed command:", @_ or die $!; };
     if ($!) {
@@ -558,7 +531,8 @@ sub cfg {
        my @cmd = (@git, qw(config --), $c);
        my $v;
        {
-           local ($debug) = $debug-1;
+           local ($Debian::Dgit::debug) = $debug-1;
+           *debug = *Debian::Dgit::debug; # nnng
            $v = cmdoutput_errok @cmd;
        };
        if ($?==0) {
@@ -935,7 +909,7 @@ sub sshpsql ($$$) {
     my @rows;
     my @cmd = (access_cfg_ssh, $userhost,
               access_runeinfo("ssh-psql $runeinfo").
-              " export LANG=C;".
+              " export LC_MESSAGES=C; export LC_CTYPE=C;".
               " ".shellquote qw(psql -A), $dbname, qw(-c), $sql);
     printcmd(\*DEBUG,$debugprefix."|",@cmd) if $debug>0;
     open P, "-|", @cmd or die $!;
@@ -1503,8 +1477,8 @@ sub clone ($) {
     }
     fetch_from_archive() or no_such_package;
     my $vcsgiturl = $dsc->{'Vcs-Git'};
-    $vcsgiturl =~ s/\s+-b\s+\S+//g;
     if (length $vcsgiturl) {
+       $vcsgiturl =~ s/\s+-b\s+\S+//g;
        runcmd @git, qw(remote add vcs-git), $vcsgiturl;
     }
     runcmd @git, qw(reset --hard), lrref();
@@ -2828,9 +2802,8 @@ sub parseopts () {
                    cmd_help();
                } elsif (s/^-D/-/) {
                    push @ropts, $&;
-                   open DEBUG, ">&STDERR" or die $!;
-                   autoflush DEBUG 1;
                    $debug++;
+                   enabledebug();
                } elsif (s/^-N/-/) {
                    push @ropts, $&;
                    $new_package=1;