13 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
17 @EXPORT = qw(debiantag server_branch server_ref
18 stat_exists git_for_each_ref
19 $package_re $component_re $branchprefix
20 initdebug enabledebug printdebug $debugprefix $debug
22 %EXPORT_TAGS = ( policyflags => [qw(NOFFCHECK FRESHREPO)] );
23 @EXPORT_OK = @{ $EXPORT_TAGS{policyflags} };
28 our $package_re = '[0-9a-z][-+.0-9a-z]*';
29 our $component_re = '[0-9a-zA-Z][-+.0-9a-zA-Z]*';
30 our $branchprefix = 'dgit';
32 # policy hook exit status bits
33 # see dgit-repos-server head comment for documentation
34 # 1 is reserved in case something fails with `exit 1'
35 sub NOFFCHECK () { return 0x2; }
36 sub FRESHREPO () { return 0x4; }
45 sub server_branch ($) { return "$branchprefix/$_[0]"; }
46 sub server_ref ($) { return "refs/".server_branch($_[0]); }
51 return 0 if $!==&ENOENT;
55 sub git_for_each_ref ($$) {
56 my ($pattern,$func) = @_;
57 # calls $func->($objid,$objtype,$fullrefname,$reftail);
58 # $reftail is RHS of ref after refs/\w+/
59 # breaks if $pattern matches any ref `refs/blah' where blah has no `/'
60 my $fh = new IO::File "-|", qw(git for-each-ref), $pattern or die $!;
62 m#^(\w+)\s+(\w+)\s+(refs/\w+/(\S+))\s# or die "$_ ?";
65 $!=0; $?=0; close $fh or die "$pattern $? $!";
68 sub git_for_each_tag_referring ($$) {
69 my ($objreferring, $func) = @_;
70 # calls $func->($objid,$fullrefname,$tagname);
71 git_for_each_ref('refs/tags', sub {
72 my ($objid,$objtype,$fullrefname,$tagname) = @_;
73 next unless $objtype eq 'tag';
74 next if defined $objreferring and $objid ne $objreferring;
75 $func->($objid,$fullrefname,$tagname);
84 open ::DEBUG, ">/dev/null" or die $!;
88 open ::DEBUG, ">&STDERR" or die $!;
89 ::DEBUG->autoflush(1);
94 print ::DEBUG $debugprefix, @_ or die $!;
102 if (m{[^-=_./0-9a-z]}i) {
109 return join ' ', @out;
114 my $intro = shift @_;
115 print $fh $intro," " or die $!;
116 print $fh shellquote @_ or die $!;
117 print $fh "\n" or die $!;