X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=Debian%2FDgit.pm;h=641a917ee25cb9ced753deb12a5519d2e6bc45f5;hb=0143e613578b90d0e320fe4bab748b7a8726fa13;hp=e177a83950e0eb6fa8ee516f946fcb312fe00623;hpb=1c6183785fa3a9f6fe60a55bb9ff200963b4e791;p=dgit.git diff --git a/Debian/Dgit.pm b/Debian/Dgit.pm index e177a839..641a917e 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,22 +16,26 @@ BEGIN { @ISA = qw(Exporter); @EXPORT = qw(debiantag server_branch server_ref stat_exists git_for_each_ref - $package_re $branchprefix); - %EXPORT_TAGS = ( policyflags => [qw()] ); - @EXPORT_OK = qw(); + $package_re $component_re $branchprefix + initdebug enabledebug printdebug debugcmd + $debugprefix $debug + shellquote printcmd); + %EXPORT_TAGS = ( policyflags => [qw(NOFFCHECK FRESHREPO)] ); + @EXPORT_OK = @{ $EXPORT_TAGS{policyflags} }; } our @EXPORT_OK; our $package_re = '[0-9a-z][-+.0-9a-z]*'; +our $component_re = '[0-9a-zA-Z][-+.0-9a-zA-Z]*'; our $branchprefix = 'dgit'; # policy hook exit status bits # see dgit-repos-server head comment for documentation # 1 is reserved in case something fails with `exit 1' -sub NOFFCHECK () { return 2; } -sub FRESHREPO () { return 4; } -# 128 is reserved +sub NOFFCHECK () { return 0x2; } +sub FRESHREPO () { return 0x4; } +# 0x80 is reserved sub debiantag ($) { my ($v) = @_; @@ -72,4 +77,50 @@ 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 $! if $debug>0; +} + +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 debugcmd { + my $extraprefix = shift @_; + printcmd(\*::DEBUG,$debugprefix.$extraprefix,@_) if $debug>0; +} + 1;