X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=Debian%2FDgit.pm;h=f33b173ca9bdac1424757b1d7c3adb022bda57da;hb=13161881906ef646bf3a40d3ed343cfbdd50657a;hp=e2f8edd05848c76f74e13c65d6561e39df1d1e48;hpb=996984bbcc5c1c7b4ed734fdb7a3dd844f2ff567;p=dgit.git diff --git a/Debian/Dgit.pm b/Debian/Dgit.pm index e2f8edd0..f33b173c 100644 --- a/Debian/Dgit.pm +++ b/Debian/Dgit.pm @@ -1,10 +1,13 @@ -# +# -*- perl -*- package Debian::Dgit; use strict; use warnings; +use POSIX; +use IO::Handle; + BEGIN { use Exporter (); our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); @@ -13,27 +16,27 @@ 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 enabledebuglevel + printdebug debugcmd + $debugprefix *debuglevel *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 -# any unexpected bits mean failure, and then known set bits are ignored - -sub NOFFCHECK () { return 2; } -# suppress dgit-repos-server's ff check ("push" only) - -sub FRESHREPO () { return 4; } -# blow away repo right away (ie, as if before push or fetch) -# ("check-package" and "push" only) - +# see dgit-repos-server head comment for documentation +# 1 is reserved in case something fails with `exit 1' +sub NOFFCHECK () { return 0x2; } +sub FRESHREPO () { return 0x4; } +# 0x80 is reserved sub debiantag ($) { my ($v) = @_; @@ -56,7 +59,7 @@ sub git_for_each_ref ($$) { # calls $func->($objid,$objtype,$fullrefname,$reftail); # $reftail is RHS of ref after refs/\w+/ # breaks if $pattern matches any ref `refs/blah' where blah has no `/' - my $fh = new IO::File, "-|", qw(git for-each-ref), $pattern or die $!; + my $fh = new IO::File "-|", qw(git for-each-ref), $pattern or die $!; while (<$fh>) { m#^(\w+)\s+(\w+)\s+(refs/\w+/(\S+))\s# or die "$_ ?"; $func->($1,$2,$3,$4); @@ -75,4 +78,56 @@ sub git_for_each_tag_referring ($$) { }); } +our $debugprefix; +our $debuglevel = 0; + +sub initdebug ($) { + ($debugprefix) = @_; + open DEBUG, ">/dev/null" or die $!; +} + +sub enabledebug () { + open DEBUG, ">&STDERR" or die $!; + DEBUG->autoflush(1); + $debuglevel ||= 1; +} + +sub enabledebuglevel ($) { + die if $debuglevel; + ($debuglevel) = @_ + 0; + enabledebug(); +} + +sub printdebug { + print DEBUG $debugprefix, @_ or die $! if $debuglevel>0; +} + +sub shellquote { + my @out; + local $_; + foreach my $a (@_) { + $_ = $a; + if (!length || 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 $debuglevel>0; +} + 1;