12 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
16 @EXPORT = qw(debiantag server_branch server_ref
17 stat_exists git_for_each_ref
18 $package_re $component_re $branchprefix);
19 %EXPORT_TAGS = ( policyflags => [qw(NOFFCHECK FRESHREPO)] );
20 @EXPORT_OK = @{ $EXPORT_TAGS{policyflags} };
25 our $package_re = '[0-9a-z][-+.0-9a-z]*';
26 our $component_re = '[0-9a-zA-Z][-+.0-9a-zA-Z]*';
27 our $branchprefix = 'dgit';
29 # policy hook exit status bits
30 # see dgit-repos-server head comment for documentation
31 # 1 is reserved in case something fails with `exit 1'
32 sub NOFFCHECK () { return 2; }
33 sub FRESHREPO () { return 4; }
42 sub server_branch ($) { return "$branchprefix/$_[0]"; }
43 sub server_ref ($) { return "refs/".server_branch($_[0]); }
48 return 0 if $!==&ENOENT;
52 sub git_for_each_ref ($$) {
53 my ($pattern,$func) = @_;
54 # calls $func->($objid,$objtype,$fullrefname,$reftail);
55 # $reftail is RHS of ref after refs/\w+/
56 # breaks if $pattern matches any ref `refs/blah' where blah has no `/'
57 my $fh = new IO::File "-|", qw(git for-each-ref), $pattern or die $!;
59 m#^(\w+)\s+(\w+)\s+(refs/\w+/(\S+))\s# or die "$_ ?";
62 $!=0; $?=0; close $fh or die "$pattern $? $!";
65 sub git_for_each_tag_referring ($$) {
66 my ($objreferring, $func) = @_;
67 # calls $func->($objid,$fullrefname,$tagname);
68 git_for_each_ref('refs/tags', sub {
69 my ($objid,$objtype,$fullrefname,$tagname) = @_;
70 next unless $objtype eq 'tag';
71 next if defined $objreferring and $objid ne $objreferring;
72 $func->($objid,$fullrefname,$tagname);