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;