]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/Git.pm
git: fix asynchronous batching for deep pipelines
[public-inbox.git] / lib / PublicInbox / Git.pm
1 # Copyright (C) all contributors <meta@public-inbox.org>
2 # License: GPLv2 or later <https://www.gnu.org/licenses/gpl-2.0.txt>
3 #
4 # Used to read files from a git repository without excessive forking.
5 # Used in our web interfaces as well as our -nntpd server.
6 # This is based on code in Git.pm which is GPLv2+, but modified to avoid
7 # dependence on environment variables for compatibility with mod_perl.
8 # There are also API changes to simplify our usage and data set.
9 package PublicInbox::Git;
10 use strict;
11 use v5.10.1;
12 use parent qw(Exporter);
13 use POSIX ();
14 use IO::Handle; # ->autoflush
15 use Errno qw(EINTR EAGAIN ENOENT);
16 use File::Glob qw(bsd_glob GLOB_NOSORT);
17 use File::Spec ();
18 use Time::HiRes qw(stat);
19 use PublicInbox::Spawn qw(popen_rd spawn);
20 use PublicInbox::Tmpfile;
21 use IO::Poll qw(POLLIN);
22 use Carp qw(croak carp);
23 use Digest::SHA ();
24 use PublicInbox::DS qw(dwaitpid);
25 our @EXPORT_OK = qw(git_unquote git_quote);
26 our $PIPE_BUFSIZ = 65536; # Linux default
27 our $in_cleanup;
28 our $RDTIMEO = 60_000; # milliseconds
29 our $async_warn; # true in read-only daemons
30
31 # 512: POSIX PIPE_BUF minimum (see pipe(7))
32 # 3: @$inflight is flattened [ $OID, $cb, $arg ]
33 # 65: SHA-256 hex size + "\n" in preparation for git using non-SHA1
34 use constant MAX_INFLIGHT => 512 * 3 / 65;
35
36 my %GIT_ESC = (
37         a => "\a",
38         b => "\b",
39         f => "\f",
40         n => "\n",
41         r => "\r",
42         t => "\t",
43         v => "\013",
44         '"' => '"',
45         '\\' => '\\',
46 );
47 my %ESC_GIT = map { $GIT_ESC{$_} => $_ } keys %GIT_ESC;
48
49
50 # unquote pathnames used by git, see quote.c::unquote_c_style.c in git.git
51 sub git_unquote ($) {
52         return $_[0] unless ($_[0] =~ /\A"(.*)"\z/);
53         $_[0] = $1;
54         $_[0] =~ s!\\([\\"abfnrtv]|[0-3][0-7]{2})!$GIT_ESC{$1}//chr(oct($1))!ge;
55         $_[0];
56 }
57
58 sub git_quote ($) {
59         if ($_[0] =~ s/([\\"\a\b\f\n\r\t\013]|[^[:print:]])/
60                       '\\'.($ESC_GIT{$1}||sprintf("%03o",ord($1)))/egs) {
61                 return qq{"$_[0]"};
62         }
63         $_[0];
64 }
65
66 sub new {
67         my ($class, $git_dir) = @_;
68         $git_dir =~ tr!/!/!s;
69         $git_dir =~ s!/*\z!!s;
70         # may contain {-tmp} field for File::Temp::Dir
71         bless { git_dir => $git_dir }, $class
72 }
73
74 sub git_path ($$) {
75         my ($self, $path) = @_;
76         $self->{-git_path}->{$path} //= do {
77                 local $/ = "\n";
78                 chomp(my $str = $self->qx(qw(rev-parse --git-path), $path));
79
80                 # git prior to 2.5.0 did not understand --git-path
81                 if ($str eq "--git-path\n$path") {
82                         $str = "$self->{git_dir}/$path";
83                 }
84                 $str;
85         };
86 }
87
88 sub alternates_changed {
89         my ($self) = @_;
90         my $alt = git_path($self, 'objects/info/alternates');
91         my @st = stat($alt) or return 0;
92
93         # can't rely on 'q' on some 32-bit builds, but `d' works
94         my $st = pack('dd', $st[10], $st[7]); # 10: ctime, 7: size
95         return 0 if ($self->{alt_st} // '') eq $st;
96         $self->{alt_st} = $st; # always a true value
97 }
98
99 sub object_format {
100         $_[0]->{object_format} //= do {
101                 my $fmt = $_[0]->qx(qw(config extensions.objectformat));
102                 $fmt eq "sha256\n" ? \'sha256' : \undef;
103         }
104 }
105
106 sub last_check_err {
107         my ($self) = @_;
108         my $fh = $self->{err_c} or return;
109         sysseek($fh, 0, 0) or $self->fail("sysseek failed: $!");
110         defined(sysread($fh, my $buf, -s $fh)) or
111                         $self->fail("sysread failed: $!");
112         $buf;
113 }
114
115 sub _bidi_pipe {
116         my ($self, $batch, $in, $out, $pid, $err) = @_;
117         if ($self->{$pid}) {
118                 if (defined $err) { # "err_c"
119                         my $fh = $self->{$err};
120                         sysseek($fh, 0, 0) or $self->fail("sysseek failed: $!");
121                         truncate($fh, 0) or $self->fail("truncate failed: $!");
122                 }
123                 return;
124         }
125         pipe(my ($out_r, $out_w)) or $self->fail("pipe failed: $!");
126         my $rdr = { 0 => $out_r, pgid => 0 };
127         my $gd = $self->{git_dir};
128         if ($gd =~ s!/([^/]+/[^/]+)\z!/!) {
129                 $rdr->{-C} = $gd;
130                 $gd = $1;
131         }
132         my @cmd = (qw(git), "--git-dir=$gd",
133                         qw(-c core.abbrev=40 cat-file), $batch);
134         if ($err) {
135                 my $id = "git.$self->{git_dir}$batch.err";
136                 my $fh = tmpfile($id) or $self->fail("tmpfile($id): $!");
137                 $self->{$err} = $fh;
138                 $rdr->{2} = $fh;
139         }
140         my ($in_r, $p) = popen_rd(\@cmd, undef, $rdr);
141         $self->{$pid} = $p;
142         $self->{"$pid.owner"} = $$;
143         $out_w->autoflush(1);
144         if ($^O eq 'linux') { # 1031: F_SETPIPE_SZ
145                 fcntl($out_w, 1031, 4096);
146                 fcntl($in_r, 1031, 4096) if $batch eq '--batch-check';
147         }
148         $out_w->blocking(0);
149         $self->{$out} = $out_w;
150         $self->{$in} = $in_r;
151 }
152
153 sub poll_in ($) { IO::Poll::_poll($RDTIMEO, fileno($_[0]), my $ev = POLLIN) }
154
155 sub my_read ($$$) {
156         my ($fh, $rbuf, $len) = @_;
157         my $left = $len - length($$rbuf);
158         my $r;
159         while ($left > 0) {
160                 $r = sysread($fh, $$rbuf, $PIPE_BUFSIZ, length($$rbuf));
161                 if ($r) {
162                         $left -= $r;
163                 } elsif (defined($r)) { # EOF
164                         return 0;
165                 } else {
166                         next if ($! == EAGAIN and poll_in($fh));
167                         next if $! == EINTR; # may be set by sysread or poll_in
168                         return; # unrecoverable error
169                 }
170         }
171         my $no_pad = substr($$rbuf, 0, $len, '');
172         \$no_pad;
173 }
174
175 sub my_readline ($$) {
176         my ($fh, $rbuf) = @_;
177         while (1) {
178                 if ((my $n = index($$rbuf, "\n")) >= 0) {
179                         return substr($$rbuf, 0, $n + 1, '');
180                 }
181                 my $r = sysread($fh, $$rbuf, $PIPE_BUFSIZ, length($$rbuf))
182                                                                 and next;
183
184                 # return whatever's left on EOF
185                 return substr($$rbuf, 0, length($$rbuf)+1, '') if defined($r);
186
187                 next if ($! == EAGAIN and poll_in($fh));
188                 next if $! == EINTR; # may be set by sysread or poll_in
189                 return; # unrecoverable error
190         }
191 }
192
193 sub cat_async_retry ($$) {
194         my ($self, $inflight) = @_;
195
196         # {inflight} may be non-existent, but if it isn't we delete it
197         # here to prevent cleanup() from waiting:
198         delete $self->{inflight};
199         cleanup($self);
200
201         $self->{inflight} = $inflight;
202         batch_prepare($self);
203         my $buf = '';
204         for (my $i = 0; $i < @$inflight; $i += 3) {
205                 $buf .= "$inflight->[$i]\n";
206         }
207         $self->{out}->blocking(1); # brand new pipe, should never block
208         print { $self->{out} } $buf or $self->fail("write error: $!");
209         $self->{out}->blocking(0);
210         my $req = shift @$inflight;
211         unshift(@$inflight, \$req); # \$ref to indicate retried
212
213         cat_async_step($self, $inflight); # take one step
214 }
215
216 sub cat_async_step ($$) {
217         my ($self, $inflight) = @_;
218         die 'BUG: inflight empty or odd' if scalar(@$inflight) < 3;
219         my ($req, $cb, $arg) = @$inflight[0, 1, 2];
220         my $rbuf = delete($self->{rbuf}) // \(my $new = '');
221         my ($bref, $oid, $type, $size);
222         my $head = my_readline($self->{in}, $rbuf);
223         # ->fail may be called via Gcf2Client.pm
224         if ($head =~ /^([0-9a-f]{40,}) (\S+) ([0-9]+)$/) {
225                 ($oid, $type, $size) = ($1, $2, $3 + 0);
226                 $bref = my_read($self->{in}, $rbuf, $size + 1) or
227                         $self->fail(defined($bref) ? 'read EOF' : "read: $!");
228                 chop($$bref) eq "\n" or $self->fail('LF missing after blob');
229         } elsif ($head =~ s/ missing\n//s) {
230                 $oid = $head;
231                 # ref($req) indicates it's already been retried
232                 # -gcf2 retries internally, so it never hits this path:
233                 if (!ref($req) && !$in_cleanup && $self->alternates_changed) {
234                         return cat_async_retry($self, $inflight);
235                 }
236                 $type = 'missing';
237                 $oid = ref($req) ? $$req : $req if $oid eq '';
238         } else {
239                 my $err = $! ? " ($!)" : '';
240                 $self->fail("bad result from async cat-file: $head$err");
241         }
242         $self->{rbuf} = $rbuf if $$rbuf ne '';
243         splice(@$inflight, 0, 3); # don't retry $cb on ->fail
244         eval { $cb->($bref, $oid, $type, $size, $arg) };
245         async_err($self, $req, $oid, $@, 'cat') if $@;
246 }
247
248 sub cat_async_wait ($) {
249         my ($self) = @_;
250         my $inflight = $self->{inflight} or return;
251         while (scalar(@$inflight)) {
252                 cat_async_step($self, $inflight);
253         }
254 }
255
256 sub batch_prepare ($) {
257         _bidi_pipe($_[0], qw(--batch in out pid));
258 }
259
260 sub _cat_file_cb {
261         my ($bref, $oid, $type, $size, $result) = @_;
262         @$result = ($bref, $oid, $type, $size);
263 }
264
265 sub cat_file {
266         my ($self, $oid) = @_;
267         my $result = [];
268         cat_async($self, $oid, \&_cat_file_cb, $result);
269         cat_async_wait($self);
270         wantarray ? @$result : $result->[0];
271 }
272
273 sub check_async_step ($$) {
274         my ($self, $inflight_c) = @_;
275         die 'BUG: inflight empty or odd' if scalar(@$inflight_c) < 3;
276         my ($req, $cb, $arg) = @$inflight_c[0, 1, 2];
277         my $rbuf = delete($self->{rbuf_c}) // \(my $new = '');
278         chomp(my $line = my_readline($self->{in_c}, $rbuf));
279         my ($hex, $type, $size) = split(/ /, $line);
280
281         # Future versions of git.git may have type=ambiguous, but for now,
282         # we must handle 'dangling' below (and maybe some other oddball
283         # stuff):
284         # https://public-inbox.org/git/20190118033845.s2vlrb3wd3m2jfzu@dcvr/T/
285         if ($hex eq 'dangling' || $hex eq 'notdir' || $hex eq 'loop') {
286                 my $ret = my_read($self->{in_c}, $rbuf, $type + 1);
287                 $self->fail(defined($ret) ? 'read EOF' : "read: $!") if !$ret;
288         }
289         $self->{rbuf_c} = $rbuf if $$rbuf ne '';
290         splice(@$inflight_c, 0, 3); # don't retry $cb on ->fail
291         eval { $cb->($hex, $type, $size, $arg, $self) };
292         async_err($self, $req, $hex, $@, 'check') if $@;
293 }
294
295 sub check_async_wait ($) {
296         my ($self) = @_;
297         my $inflight_c = $self->{inflight_c} or return;
298         while (scalar(@$inflight_c)) {
299                 check_async_step($self, $inflight_c);
300         }
301 }
302
303 sub check_async_begin ($) {
304         my ($self) = @_;
305         cleanup($self) if alternates_changed($self);
306         _bidi_pipe($self, qw(--batch-check in_c out_c pid_c err_c));
307         die 'BUG: already in async check' if $self->{inflight_c};
308         $self->{inflight_c} = [];
309 }
310
311 sub write_all {
312         my ($self, $out, $buf, $read_step, $inflight) = @_;
313         $read_step->($self, $inflight) while @$inflight >= MAX_INFLIGHT;
314         do {
315                 my $w = syswrite($out, $buf);
316                 if (defined $w) {
317                         return if $w == length($buf);
318                         warn "chop: $w";
319                         substr($buf, 0, $w, ''); # sv_chop
320                 } elsif ($! != EAGAIN) {
321                         $self->fail("write: $!");
322                 } else { warn "E: $!" }
323                 $read_step->($self, $inflight);
324         } while (1);
325 }
326
327 sub check_async ($$$$) {
328         my ($self, $oid, $cb, $arg) = @_;
329         my $inflight_c = $self->{inflight_c} // check_async_begin($self);
330         write_all($self, $self->{out_c}, $oid."\n",
331                 \&check_async_step, $inflight_c);
332         push(@$inflight_c, $oid, $cb, $arg);
333 }
334
335 sub _check_cb { # check_async callback
336         my ($hex, $type, $size, $result) = @_;
337         @$result = ($hex, $type, $size);
338 }
339
340 sub check {
341         my ($self, $oid) = @_;
342         my $result = [];
343         check_async($self, $oid, \&_check_cb, $result);
344         check_async_wait($self);
345         my ($hex, $type, $size) = @$result;
346
347         # Future versions of git.git may show 'ambiguous', but for now,
348         # we must handle 'dangling' below (and maybe some other oddball
349         # stuff):
350         # https://public-inbox.org/git/20190118033845.s2vlrb3wd3m2jfzu@dcvr/T/
351         return if $type eq 'missing' || $type eq 'ambiguous';
352         return if $hex eq 'dangling' || $hex eq 'notdir' || $hex eq 'loop';
353         ($hex, $type, $size);
354 }
355
356 sub _destroy {
357         my ($self, $rbuf, $in, $out, $pid, $err) = @_;
358         delete @$self{($rbuf, $in, $out)};
359         delete $self->{$err} if $err; # `err_c'
360
361         # GitAsyncCat::event_step may delete {pid}
362         my $p = delete $self->{$pid} or return;
363         dwaitpid($p) if $$ == $self->{"$pid.owner"};
364 }
365
366 sub async_abort ($) {
367         my ($self) = @_;
368         while (scalar(@{$self->{inflight_c} // []}) ||
369                         scalar(@{$self->{inflight} // []})) {
370                 for my $c ('', '_c') {
371                         my $q = $self->{"inflight$c"} or next;
372                         while (@$q) {
373                                 my ($req, $cb, $arg) = splice(@$q, 0, 3);
374                                 $req = $$req if ref($req);
375                                 $req =~ s/ .*//; # drop git_dir for Gcf2Client
376                                 eval { $cb->(undef, $req, undef, undef, $arg) };
377                                 warn "E: (in abort) $req: $@" if $@;
378                         }
379                         delete $self->{"inflight$c"};
380                         delete $self->{"rbuf$c"};
381                 }
382         }
383         cleanup($self);
384 }
385
386 sub fail { # may be augmented in subclasses
387         my ($self, $msg) = @_;
388         async_abort($self);
389         croak(ref($self) . ' ' . ($self->{git_dir} // '') . ": $msg");
390 }
391
392 sub async_err ($$$$$) {
393         my ($self, $req, $oid, $err, $action) = @_;
394         $req = $$req if ref($req); # retried
395         my $msg = "E: $action $req ($oid): $err";
396         $async_warn ? carp($msg) : $self->fail($msg);
397 }
398
399 # $git->popen(qw(show f00)); # or
400 # $git->popen(qw(show f00), { GIT_CONFIG => ... }, { 2 => ... });
401 sub popen {
402         my ($self, $cmd) = splice(@_, 0, 2);
403         $cmd = [ 'git', "--git-dir=$self->{git_dir}",
404                 ref($cmd) ? @$cmd : ($cmd, grep { defined && !ref } @_) ];
405         popen_rd($cmd, grep { !defined || ref } @_); # env and opt
406 }
407
408 # same args as popen above
409 sub qx {
410         my $fh = popen(@_);
411         if (wantarray) {
412                 my @ret = <$fh>;
413                 close $fh; # caller should check $?
414                 @ret;
415         } else {
416                 local $/;
417                 my $ret = <$fh>;
418                 close $fh; # caller should check $?
419                 $ret;
420         }
421 }
422
423 sub date_parse {
424         my $self = shift;
425         map {
426                 substr($_, length('--max-age='), -1)
427         } $self->qx('rev-parse', map { "--since=$_" } @_);
428 }
429
430 # check_async and cat_async may trigger the other, so ensure they're
431 # both completely done by using this:
432 sub async_wait_all ($) {
433         my ($self) = @_;
434         while (scalar(@{$self->{inflight_c} // []}) ||
435                         scalar(@{$self->{inflight} // []})) {
436                 check_async_wait($self);
437                 cat_async_wait($self);
438         }
439 }
440
441 # returns true if there are pending "git cat-file" processes
442 sub cleanup {
443         my ($self, $lazy) = @_;
444         return 1 if $lazy && (scalar(@{$self->{inflight_c} // []}) ||
445                                 scalar(@{$self->{inflight} // []}));
446         local $in_cleanup = 1;
447         delete $self->{async_cat};
448         delete $self->{async_chk};
449         async_wait_all($self);
450         delete $self->{inflight};
451         delete $self->{inflight_c};
452         _destroy($self, qw(rbuf in out pid));
453         _destroy($self, qw(rbuf_c in_c out_c pid_c err_c));
454         undef;
455 }
456
457 # assuming a well-maintained repo, this should be a somewhat
458 # accurate estimation of its size
459 # TODO: show this in the WWW UI as a hint to potential cloners
460 sub packed_bytes {
461         my ($self) = @_;
462         my $n = 0;
463         my $pack_dir = git_path($self, 'objects/pack');
464         foreach my $p (bsd_glob("$pack_dir/*.pack", GLOB_NOSORT)) {
465                 $n += -s $p;
466         }
467         $n
468 }
469
470 sub DESTROY { cleanup(@_) }
471
472 sub local_nick ($) {
473         # don't show full FS path, basename should be OK:
474         $_[0]->{nick} // ($_[0]->{git_dir} =~ m!/([^/]+?)(?:/*\.git/*)?\z! ?
475                         "$1.git" : undef);
476 }
477
478 sub host_prefix_url ($$) {
479         my ($env, $url) = @_;
480         return $url if index($url, '//') >= 0;
481         my $scheme = $env->{'psgi.url_scheme'};
482         my $host_port = $env->{HTTP_HOST} //
483                 "$env->{SERVER_NAME}:$env->{SERVER_PORT}";
484         "$scheme://$host_port". ($env->{SCRIPT_NAME} || '/') . $url;
485 }
486
487 sub base_url { # for coderepos, PSGI-only
488         my ($self, $env) = @_; # env - PSGI env
489         my $url = host_prefix_url($env, '');
490         # for mount in Plack::Builder
491         $url .= '/' if substr($url, -1, 1) ne '/';
492         $url . $self->{nick} . '/';
493 }
494
495 sub isrch {} # TODO
496
497 sub pub_urls {
498         my ($self, $env) = @_;
499         if (my $urls = $self->{cgit_url}) {
500                 return map { host_prefix_url($env, $_) } @$urls;
501         }
502         (local_nick($self) // '???');
503 }
504
505 sub cat_async_begin {
506         my ($self) = @_;
507         cleanup($self) if $self->alternates_changed;
508         $self->batch_prepare;
509         die 'BUG: already in async' if $self->{inflight};
510         $self->{inflight} = [];
511 }
512
513 sub cat_async ($$$;$) {
514         my ($self, $oid, $cb, $arg) = @_;
515         my $inflight = $self->{inflight} // cat_async_begin($self);
516         write_all($self, $self->{out}, $oid."\n", \&cat_async_step, $inflight);
517         push(@$inflight, $oid, $cb, $arg);
518 }
519
520 # returns the modified time of a git repo, same as the "modified" field
521 # of a grokmirror manifest
522 sub modified ($) {
523         # committerdate:unix is git 2.9.4+ (2017-05-05), so using raw instead
524         my $fh = popen($_[0], qw[for-each-ref --sort=-committerdate
525                                 --format=%(committerdate:raw) --count=1]);
526         (split(/ /, <$fh> // time))[0] + 0; # integerize for JSON
527 }
528
529 sub try_cat {
530         my ($path) = @_;
531         open(my $fh, '<', $path) or return '';
532         local $/;
533         <$fh> // '';
534 }
535
536 sub cat_desc ($) {
537         my $desc = try_cat($_[0]);
538         chomp $desc;
539         utf8::decode($desc);
540         $desc =~ s/\s+/ /smg;
541         $desc eq '' ? undef : $desc;
542 }
543
544 sub description {
545         cat_desc("$_[0]->{git_dir}/description") // 'Unnamed repository';
546 }
547
548 sub cloneurl {
549         my ($self, $env) = @_;
550         $self->{cloneurl} // do {
551                 my @urls = split(/\s+/s, try_cat("$self->{git_dir}/cloneurl"));
552                 scalar(@urls) ? ($self->{cloneurl} = \@urls) : undef;
553         } // [ substr(base_url($self, $env), 0, -1) ];
554 }
555
556 # for grokmirror, which doesn't read gitweb.description
557 # templates/hooks--update.sample and git-multimail in git.git
558 # only match "Unnamed repository", not the full contents of
559 # templates/this--description in git.git
560 sub manifest_entry {
561         my ($self, $epoch, $default_desc) = @_;
562         my $fh = $self->popen('show-ref');
563         my $dig = Digest::SHA->new(1);
564         while (read($fh, my $buf, 65536)) {
565                 $dig->add($buf);
566         }
567         close $fh or return; # empty, uninitialized git repo
568         undef $fh; # for open, below
569         my $git_dir = $self->{git_dir};
570         my $ent = {
571                 fingerprint => $dig->hexdigest,
572                 reference => undef,
573                 modified => modified($self),
574         };
575         chomp(my $owner = $self->qx('config', 'gitweb.owner'));
576         utf8::decode($owner);
577         $ent->{owner} = $owner eq '' ? undef : $owner;
578         my $desc = description($self);
579         if (defined $epoch && index($desc, 'Unnamed repository') == 0) {
580                 $desc = "$default_desc [epoch $epoch]";
581         }
582         $ent->{description} = $desc;
583         if (open($fh, '<', "$git_dir/objects/info/alternates")) {
584                 # n.b.: GitPython doesn't seem to handle comments or C-quoted
585                 # strings like native git does; and we don't for now, either.
586                 local $/ = "\n";
587                 chomp(my @alt = <$fh>);
588
589                 # grokmirror only supports 1 alternate for "reference",
590                 if (scalar(@alt) == 1) {
591                         my $objdir = "$git_dir/objects";
592                         my $ref = File::Spec->rel2abs($alt[0], $objdir);
593                         $ref =~ s!/[^/]+/?\z!!; # basename
594                         $ent->{reference} = $ref;
595                 }
596         }
597         $ent;
598 }
599
600 # returns true if there are pending cat-file processes
601 sub cleanup_if_unlinked {
602         my ($self) = @_;
603         return cleanup($self, 1) if $^O ne 'linux';
604         # Linux-specific /proc/$PID/maps access
605         # TODO: support this inside git.git
606         my $ret = 0;
607         for my $fld (qw(pid pid_c)) {
608                 my $pid = $self->{$fld} // next;
609                 open my $fh, '<', "/proc/$pid/maps" or return cleanup($self, 1);
610                 while (<$fh>) {
611                         # n.b. we do not restart for unlinked multi-pack-index
612                         # since it's not too huge, and the startup cost may
613                         # be higher.
614                         /\.(?:idx|pack) \(deleted\)$/ and
615                                 return cleanup($self, 1);
616                 }
617                 ++$ret;
618         }
619         $ret;
620 }
621
622 1;
623 __END__
624 =pod
625
626 =head1 NAME
627
628 PublicInbox::Git - git wrapper
629
630 =head1 VERSION
631
632 version 1.0
633
634 =head1 SYNOPSIS
635
636         use PublicInbox::Git;
637         chomp(my $git_dir = `git rev-parse --git-dir`);
638         $git_dir or die "GIT_DIR= must be specified\n";
639         my $git = PublicInbox::Git->new($git_dir);
640
641 =head1 DESCRIPTION
642
643 Unstable API outside of the L</new> method.
644 It requires L<git(1)> to be installed.
645
646 =head1 METHODS
647
648 =cut
649
650 =head2 new
651
652         my $git = PublicInbox::Git->new($git_dir);
653
654 Initialize a new PublicInbox::Git object for use with L<PublicInbox::Import>
655 This is the only public API method we support.  Everything else
656 in this module is subject to change.
657
658 =head1 SEE ALSO
659
660 L<Git>, L<PublicInbox::Import>
661
662 =head1 CONTACT
663
664 All feedback welcome via plain-text mail to L<mailto:meta@public-inbox.org>
665
666 The mail archives are hosted at L<https://public-inbox.org/meta/>
667
668 =head1 COPYRIGHT
669
670 Copyright (C) 2016 all contributors L<mailto:meta@public-inbox.org>
671
672 License: AGPL-3.0+ L<http://www.gnu.org/licenses/agpl-3.0.txt>
673
674 =cut