use warnings;
use POSIX;
+use IO::Handle;
BEGIN {
use Exporter ();
@ISA = qw(Exporter);
@EXPORT = qw(debiantag server_branch server_ref
stat_exists git_for_each_ref
- $package_re $component_re $branchprefix);
+ $package_re $component_re $branchprefix
+ initdebug enabledebug printdebug $debugprefix $debug
+ shellquote printcmd);
%EXPORT_TAGS = ( policyflags => [qw(NOFFCHECK FRESHREPO)] );
@EXPORT_OK = @{ $EXPORT_TAGS{policyflags} };
}
});
}
+our $debugprefix;
+our $debug = 0;
+
+sub initdebug ($) {
+ ($debugprefix) = @_;
+ open ::DEBUG, ">/dev/null" or die $!;
+}
+
+sub enabledebug () {
+ open ::DEBUG, ">&STDERR" or die $!;
+ ::DEBUG->autoflush(1);
+ $debug ||= 1;
+}
+
+sub printdebug {
+ print ::DEBUG $debugprefix, @_ or die $!;
+}
+
+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 $!;
+}
+
1;
our $keyid;
-our $debug = 0;
-open DEBUG, ">/dev/null" or die $!;
-
autoflush STDOUT 1;
our $remotename = 'dgit';
}
our $us = 'dgit';
-our $debugprefix = '';
+initdebug('');
our @end;
END {
}
}
-sub printdebug { print DEBUG $debugprefix, @_ or die $!; }
-
sub fail {
my $s = "@_\n";
my $prefix = $us.($we_are_responder ? " (build host)" : "").": ";
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 ($!) {
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) {
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;