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 $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 $branchprefix = 'dgit';
28 # policy hook exit status bits
29 # see dgit-repos-server head comment for documentation
30 # 1 is reserved in case something fails with `exit 1'
31 sub NOFFCHECK () { return 2; }
32 sub FRESHREPO () { return 4; }
41 sub server_branch ($) { return "$branchprefix/$_[0]"; }
42 sub server_ref ($) { return "refs/".server_branch($_[0]); }
47 return 0 if $!==&ENOENT;
51 sub git_for_each_ref ($$) {
52 my ($pattern,$func) = @_;
53 # calls $func->($objid,$objtype,$fullrefname,$reftail);
54 # $reftail is RHS of ref after refs/\w+/
55 # breaks if $pattern matches any ref `refs/blah' where blah has no `/'
56 my $fh = new IO::File "-|", qw(git for-each-ref), $pattern or die $!;
58 m#^(\w+)\s+(\w+)\s+(refs/\w+/(\S+))\s# or die "$_ ?";
61 $!=0; $?=0; close $fh or die "$pattern $? $!";
64 sub git_for_each_tag_referring ($$) {
65 my ($objreferring, $func) = @_;
66 # calls $func->($objid,$fullrefname,$tagname);
67 git_for_each_ref('refs/tags', sub {
68 my ($objid,$objtype,$fullrefname,$tagname) = @_;
69 next unless $objtype eq 'tag';
70 next if defined $objreferring and $objid ne $objreferring;
71 $func->($objid,$fullrefname,$tagname);