summaryrefslogtreecommitdiff
path: root/Debian
diff options
context:
space:
mode:
Diffstat (limited to 'Debian')
-rw-r--r--Debian/Dgit.pm46
1 files changed, 45 insertions, 1 deletions
diff --git a/Debian/Dgit.pm b/Debian/Dgit.pm
index 1ab65a8..5c079a6 100644
--- a/Debian/Dgit.pm
+++ b/Debian/Dgit.pm
@@ -6,6 +6,7 @@ use strict;
use warnings;
use POSIX;
+use IO::Handle;
BEGIN {
use Exporter ();
@@ -15,7 +16,9 @@ BEGIN {
@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} };
}
@@ -73,4 +76,45 @@ sub git_for_each_tag_referring ($$) {
});
}
+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;