]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/Git.pm
git: cap MAX_INFLIGHT value to POSIX minimum
[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         $self->{$out} = $out_w;
149         $self->{$in} = $in_r;
150 }
151
152 sub poll_in ($) { IO::Poll::_poll($RDTIMEO, fileno($_[0]), my $ev = POLLIN) }
153
154 sub my_read ($$$) {
155         my ($fh, $rbuf, $len) = @_;
156         my $left = $len - length($$rbuf);
157         my $r;
158         while ($left > 0) {
159                 $r = sysread($fh, $$rbuf, $PIPE_BUFSIZ, length($$rbuf));
160                 if ($r) {
161                         $left -= $r;
162                 } elsif (defined($r)) { # EOF
163                         return 0;
164                 } else {
165                         next if ($! == EAGAIN and poll_in($fh));
166                         next if $! == EINTR; # may be set by sysread or poll_in
167                         return; # unrecoverable error
168                 }
169         }
170         my $no_pad = substr($$rbuf, 0, $len, '');
171         \$no_pad;
172 }
173
174 sub my_readline ($$) {
175         my ($fh, $rbuf) = @_;
176         while (1) {
177                 if ((my $n = index($$rbuf, "\n")) >= 0) {
178                         return substr($$rbuf, 0, $n + 1, '');
179                 }
180                 my $r = sysread($fh, $$rbuf, $PIPE_BUFSIZ, length($$rbuf))
181                                                                 and next;
182
183                 # return whatever's left on EOF
184                 return substr($$rbuf, 0, length($$rbuf)+1, '') if defined($r);
185
186                 next if ($! == EAGAIN and poll_in($fh));
187                 next if $! == EINTR; # may be set by sysread or poll_in
188                 return; # unrecoverable error
189         }
190 }
191
192 sub cat_async_retry ($$) {
193         my ($self, $inflight) = @_;
194
195         # {inflight} may be non-existent, but if it isn't we delete it
196         # here to prevent cleanup() from waiting:
197         delete $self->{inflight};
198         cleanup($self);
199
200         $self->{inflight} = $inflight;
201         batch_prepare($self);
202         my $buf = '';
203         for (my $i = 0; $i < @$inflight; $i += 3) {
204                 $buf .= "$inflight->[$i]\n";
205         }
206         print { $self->{out} } $buf or $self->fail("write error: $!");
207         my $req = shift @$inflight;
208         unshift(@$inflight, \$req); # \$ref to indicate retried
209
210         cat_async_step($self, $inflight); # take one step
211 }
212
213 sub cat_async_step ($$) {
214         my ($self, $inflight) = @_;
215         die 'BUG: inflight empty or odd' if scalar(@$inflight) < 3;
216         my ($req, $cb, $arg) = @$inflight[0, 1, 2];
217         my $rbuf = delete($self->{rbuf}) // \(my $new = '');
218         my ($bref, $oid, $type, $size);
219         my $head = my_readline($self->{in}, $rbuf);
220         # ->fail may be called via Gcf2Client.pm
221         if ($head =~ /^([0-9a-f]{40,}) (\S+) ([0-9]+)$/) {
222                 ($oid, $type, $size) = ($1, $2, $3 + 0);
223                 $bref = my_read($self->{in}, $rbuf, $size + 1) or
224                         $self->fail(defined($bref) ? 'read EOF' : "read: $!");
225                 chop($$bref) eq "\n" or $self->fail('LF missing after blob');
226         } elsif ($head =~ s/ missing\n//s) {
227                 $oid = $head;
228                 # ref($req) indicates it's already been retried
229                 # -gcf2 retries internally, so it never hits this path:
230                 if (!ref($req) && !$in_cleanup && $self->alternates_changed) {
231                         return cat_async_retry($self, $inflight);
232                 }
233                 $type = 'missing';
234                 $oid = ref($req) ? $$req : $req if $oid eq '';
235         } else {
236                 my $err = $! ? " ($!)" : '';
237                 $self->fail("bad result from async cat-file: $head$err");
238         }
239         $self->{rbuf} = $rbuf if $$rbuf ne '';
240         splice(@$inflight, 0, 3); # don't retry $cb on ->fail
241         eval { $cb->($bref, $oid, $type, $size, $arg) };
242         async_err($self, $req, $oid, $@, 'cat') if $@;
243 }
244
245 sub cat_async_wait ($) {
246         my ($self) = @_;
247         my $inflight = $self->{inflight} or return;
248         while (scalar(@$inflight)) {
249                 cat_async_step($self, $inflight);
250         }
251 }
252
253 sub batch_prepare ($) {
254         _bidi_pipe($_[0], qw(--batch in out pid));
255 }
256
257 sub _cat_file_cb {
258         my ($bref, $oid, $type, $size, $result) = @_;
259         @$result = ($bref, $oid, $type, $size);
260 }
261
262 sub cat_file {
263         my ($self, $oid) = @_;
264         my $result = [];
265         cat_async($self, $oid, \&_cat_file_cb, $result);
266         cat_async_wait($self);
267         wantarray ? @$result : $result->[0];
268 }
269
270 sub check_async_step ($$) {
271         my ($self, $inflight_c) = @_;
272         die 'BUG: inflight empty or odd' if scalar(@$inflight_c) < 3;
273         my ($req, $cb, $arg) = @$inflight_c[0, 1, 2];
274         my $rbuf = delete($self->{rbuf_c}) // \(my $new = '');
275         chomp(my $line = my_readline($self->{in_c}, $rbuf));
276         my ($hex, $type, $size) = split(/ /, $line);
277
278         # Future versions of git.git may have type=ambiguous, but for now,
279         # we must handle 'dangling' below (and maybe some other oddball
280         # stuff):
281         # https://public-inbox.org/git/20190118033845.s2vlrb3wd3m2jfzu@dcvr/T/
282         if ($hex eq 'dangling' || $hex eq 'notdir' || $hex eq 'loop') {
283                 my $ret = my_read($self->{in_c}, $rbuf, $type + 1);
284                 $self->fail(defined($ret) ? 'read EOF' : "read: $!") if !$ret;
285         }
286         $self->{rbuf_c} = $rbuf if $$rbuf ne '';
287         splice(@$inflight_c, 0, 3); # don't retry $cb on ->fail
288         eval { $cb->($hex, $type, $size, $arg, $self) };
289         async_err($self, $req, $hex, $@, 'check') if $@;
290 }
291
292 sub check_async_wait ($) {
293         my ($self) = @_;
294         my $inflight_c = $self->{inflight_c} or return;
295         while (scalar(@$inflight_c)) {
296                 check_async_step($self, $inflight_c);
297         }
298 }
299
300 sub check_async_begin ($) {
301         my ($self) = @_;
302         cleanup($self) if alternates_changed($self);
303         _bidi_pipe($self, qw(--batch-check in_c out_c pid_c err_c));
304         die 'BUG: already in async check' if $self->{inflight_c};
305         $self->{inflight_c} = [];
306 }
307
308 sub check_async ($$$$) {
309         my ($self, $oid, $cb, $arg) = @_;
310         my $inflight_c = $self->{inflight_c} // check_async_begin($self);
311         while (scalar(@$inflight_c) >= MAX_INFLIGHT) {
312                 check_async_step($self, $inflight_c);
313         }
314         print { $self->{out_c} } $oid, "\n" or $self->fail("write error: $!");
315         push(@$inflight_c, $oid, $cb, $arg);
316 }
317
318 sub _check_cb { # check_async callback
319         my ($hex, $type, $size, $result) = @_;
320         @$result = ($hex, $type, $size);
321 }
322
323 sub check {
324         my ($self, $oid) = @_;
325         my $result = [];
326         check_async($self, $oid, \&_check_cb, $result);
327         check_async_wait($self);
328         my ($hex, $type, $size) = @$result;
329
330         # Future versions of git.git may show 'ambiguous', but for now,
331         # we must handle 'dangling' below (and maybe some other oddball
332         # stuff):
333         # https://public-inbox.org/git/20190118033845.s2vlrb3wd3m2jfzu@dcvr/T/
334         return if $type eq 'missing' || $type eq 'ambiguous';
335         return if $hex eq 'dangling' || $hex eq 'notdir' || $hex eq 'loop';
336         ($hex, $type, $size);
337 }
338
339 sub _destroy {
340         my ($self, $rbuf, $in, $out, $pid, $err) = @_;
341         delete @$self{($rbuf, $in, $out)};
342         delete $self->{$err} if $err; # `err_c'
343
344         # GitAsyncCat::event_step may delete {pid}
345         my $p = delete $self->{$pid} or return;
346         dwaitpid($p) if $$ == $self->{"$pid.owner"};
347 }
348
349 sub async_abort ($) {
350         my ($self) = @_;
351         while (scalar(@{$self->{inflight_c} // []}) ||
352                         scalar(@{$self->{inflight} // []})) {
353                 for my $c ('', '_c') {
354                         my $q = $self->{"inflight$c"} or next;
355                         while (@$q) {
356                                 my ($req, $cb, $arg) = splice(@$q, 0, 3);
357                                 $req = $$req if ref($req);
358                                 $req =~ s/ .*//; # drop git_dir for Gcf2Client
359                                 eval { $cb->(undef, $req, undef, undef, $arg) };
360                                 warn "E: (in abort) $req: $@" if $@;
361                         }
362                         delete $self->{"inflight$c"};
363                         delete $self->{"rbuf$c"};
364                 }
365         }
366         cleanup($self);
367 }
368
369 sub fail { # may be augmented in subclasses
370         my ($self, $msg) = @_;
371         async_abort($self);
372         croak(ref($self) . ' ' . ($self->{git_dir} // '') . ": $msg");
373 }
374
375 sub async_err ($$$$$) {
376         my ($self, $req, $oid, $err, $action) = @_;
377         $req = $$req if ref($req); # retried
378         my $msg = "E: $action $req ($oid): $err";
379         $async_warn ? carp($msg) : $self->fail($msg);
380 }
381
382 # $git->popen(qw(show f00)); # or
383 # $git->popen(qw(show f00), { GIT_CONFIG => ... }, { 2 => ... });
384 sub popen {
385         my ($self, $cmd) = splice(@_, 0, 2);
386         $cmd = [ 'git', "--git-dir=$self->{git_dir}",
387                 ref($cmd) ? @$cmd : ($cmd, grep { defined && !ref } @_) ];
388         popen_rd($cmd, grep { !defined || ref } @_); # env and opt
389 }
390
391 # same args as popen above
392 sub qx {
393         my $fh = popen(@_);
394         if (wantarray) {
395                 my @ret = <$fh>;
396                 close $fh; # caller should check $?
397                 @ret;
398         } else {
399                 local $/;
400                 my $ret = <$fh>;
401                 close $fh; # caller should check $?
402                 $ret;
403         }
404 }
405
406 sub date_parse {
407         my $self = shift;
408         map {
409                 substr($_, length('--max-age='), -1)
410         } $self->qx('rev-parse', map { "--since=$_" } @_);
411 }
412
413 # check_async and cat_async may trigger the other, so ensure they're
414 # both completely done by using this:
415 sub async_wait_all ($) {
416         my ($self) = @_;
417         while (scalar(@{$self->{inflight_c} // []}) ||
418                         scalar(@{$self->{inflight} // []})) {
419                 check_async_wait($self);
420                 cat_async_wait($self);
421         }
422 }
423
424 # returns true if there are pending "git cat-file" processes
425 sub cleanup {
426         my ($self, $lazy) = @_;
427         return 1 if $lazy && (scalar(@{$self->{inflight_c} // []}) ||
428                                 scalar(@{$self->{inflight} // []}));
429         local $in_cleanup = 1;
430         delete $self->{async_cat};
431         delete $self->{async_chk};
432         async_wait_all($self);
433         delete $self->{inflight};
434         delete $self->{inflight_c};
435         _destroy($self, qw(rbuf in out pid));
436         _destroy($self, qw(rbuf_c in_c out_c pid_c err_c));
437         undef;
438 }
439
440 # assuming a well-maintained repo, this should be a somewhat
441 # accurate estimation of its size
442 # TODO: show this in the WWW UI as a hint to potential cloners
443 sub packed_bytes {
444         my ($self) = @_;
445         my $n = 0;
446         my $pack_dir = git_path($self, 'objects/pack');
447         foreach my $p (bsd_glob("$pack_dir/*.pack", GLOB_NOSORT)) {
448                 $n += -s $p;
449         }
450         $n
451 }
452
453 sub DESTROY { cleanup(@_) }
454
455 sub local_nick ($) {
456         # don't show full FS path, basename should be OK:
457         $_[0]->{nick} // ($_[0]->{git_dir} =~ m!/([^/]+?)(?:/*\.git/*)?\z! ?
458                         "$1.git" : undef);
459 }
460
461 sub host_prefix_url ($$) {
462         my ($env, $url) = @_;
463         return $url if index($url, '//') >= 0;
464         my $scheme = $env->{'psgi.url_scheme'};
465         my $host_port = $env->{HTTP_HOST} //
466                 "$env->{SERVER_NAME}:$env->{SERVER_PORT}";
467         "$scheme://$host_port". ($env->{SCRIPT_NAME} || '/') . $url;
468 }
469
470 sub base_url { # for coderepos, PSGI-only
471         my ($self, $env) = @_; # env - PSGI env
472         my $url = host_prefix_url($env, '');
473         # for mount in Plack::Builder
474         $url .= '/' if substr($url, -1, 1) ne '/';
475         $url . $self->{nick} . '/';
476 }
477
478 sub isrch {} # TODO
479
480 sub pub_urls {
481         my ($self, $env) = @_;
482         if (my $urls = $self->{cgit_url}) {
483                 return map { host_prefix_url($env, $_) } @$urls;
484         }
485         (local_nick($self) // '???');
486 }
487
488 sub cat_async_begin {
489         my ($self) = @_;
490         cleanup($self) if $self->alternates_changed;
491         $self->batch_prepare;
492         die 'BUG: already in async' if $self->{inflight};
493         $self->{inflight} = [];
494 }
495
496 sub cat_async ($$$;$) {
497         my ($self, $oid, $cb, $arg) = @_;
498         my $inflight = $self->{inflight} // cat_async_begin($self);
499         while (scalar(@$inflight) >= MAX_INFLIGHT) {
500                 cat_async_step($self, $inflight);
501         }
502         print { $self->{out} } $oid, "\n" or $self->fail("write error: $!");
503         push(@$inflight, $oid, $cb, $arg);
504 }
505
506 # returns the modified time of a git repo, same as the "modified" field
507 # of a grokmirror manifest
508 sub modified ($) {
509         # committerdate:unix is git 2.9.4+ (2017-05-05), so using raw instead
510         my $fh = popen($_[0], qw[for-each-ref --sort=-committerdate
511                                 --format=%(committerdate:raw) --count=1]);
512         (split(/ /, <$fh> // time))[0] + 0; # integerize for JSON
513 }
514
515 sub try_cat {
516         my ($path) = @_;
517         open(my $fh, '<', $path) or return '';
518         local $/;
519         <$fh> // '';
520 }
521
522 sub cat_desc ($) {
523         my $desc = try_cat($_[0]);
524         chomp $desc;
525         utf8::decode($desc);
526         $desc =~ s/\s+/ /smg;
527         $desc eq '' ? undef : $desc;
528 }
529
530 sub description {
531         cat_desc("$_[0]->{git_dir}/description") // 'Unnamed repository';
532 }
533
534 sub cloneurl {
535         my ($self, $env) = @_;
536         $self->{cloneurl} // do {
537                 my @urls = split(/\s+/s, try_cat("$self->{git_dir}/cloneurl"));
538                 scalar(@urls) ? ($self->{cloneurl} = \@urls) : undef;
539         } // [ substr(base_url($self, $env), 0, -1) ];
540 }
541
542 # for grokmirror, which doesn't read gitweb.description
543 # templates/hooks--update.sample and git-multimail in git.git
544 # only match "Unnamed repository", not the full contents of
545 # templates/this--description in git.git
546 sub manifest_entry {
547         my ($self, $epoch, $default_desc) = @_;
548         my $fh = $self->popen('show-ref');
549         my $dig = Digest::SHA->new(1);
550         while (read($fh, my $buf, 65536)) {
551                 $dig->add($buf);
552         }
553         close $fh or return; # empty, uninitialized git repo
554         undef $fh; # for open, below
555         my $git_dir = $self->{git_dir};
556         my $ent = {
557                 fingerprint => $dig->hexdigest,
558                 reference => undef,
559                 modified => modified($self),
560         };
561         chomp(my $owner = $self->qx('config', 'gitweb.owner'));
562         utf8::decode($owner);
563         $ent->{owner} = $owner eq '' ? undef : $owner;
564         my $desc = description($self);
565         if (defined $epoch && index($desc, 'Unnamed repository') == 0) {
566                 $desc = "$default_desc [epoch $epoch]";
567         }
568         $ent->{description} = $desc;
569         if (open($fh, '<', "$git_dir/objects/info/alternates")) {
570                 # n.b.: GitPython doesn't seem to handle comments or C-quoted
571                 # strings like native git does; and we don't for now, either.
572                 local $/ = "\n";
573                 chomp(my @alt = <$fh>);
574
575                 # grokmirror only supports 1 alternate for "reference",
576                 if (scalar(@alt) == 1) {
577                         my $objdir = "$git_dir/objects";
578                         my $ref = File::Spec->rel2abs($alt[0], $objdir);
579                         $ref =~ s!/[^/]+/?\z!!; # basename
580                         $ent->{reference} = $ref;
581                 }
582         }
583         $ent;
584 }
585
586 # returns true if there are pending cat-file processes
587 sub cleanup_if_unlinked {
588         my ($self) = @_;
589         return cleanup($self, 1) if $^O ne 'linux';
590         # Linux-specific /proc/$PID/maps access
591         # TODO: support this inside git.git
592         my $ret = 0;
593         for my $fld (qw(pid pid_c)) {
594                 my $pid = $self->{$fld} // next;
595                 open my $fh, '<', "/proc/$pid/maps" or return cleanup($self, 1);
596                 while (<$fh>) {
597                         # n.b. we do not restart for unlinked multi-pack-index
598                         # since it's not too huge, and the startup cost may
599                         # be higher.
600                         /\.(?:idx|pack) \(deleted\)$/ and
601                                 return cleanup($self, 1);
602                 }
603                 ++$ret;
604         }
605         $ret;
606 }
607
608 1;
609 __END__
610 =pod
611
612 =head1 NAME
613
614 PublicInbox::Git - git wrapper
615
616 =head1 VERSION
617
618 version 1.0
619
620 =head1 SYNOPSIS
621
622         use PublicInbox::Git;
623         chomp(my $git_dir = `git rev-parse --git-dir`);
624         $git_dir or die "GIT_DIR= must be specified\n";
625         my $git = PublicInbox::Git->new($git_dir);
626
627 =head1 DESCRIPTION
628
629 Unstable API outside of the L</new> method.
630 It requires L<git(1)> to be installed.
631
632 =head1 METHODS
633
634 =cut
635
636 =head2 new
637
638         my $git = PublicInbox::Git->new($git_dir);
639
640 Initialize a new PublicInbox::Git object for use with L<PublicInbox::Import>
641 This is the only public API method we support.  Everything else
642 in this module is subject to change.
643
644 =head1 SEE ALSO
645
646 L<Git>, L<PublicInbox::Import>
647
648 =head1 CONTACT
649
650 All feedback welcome via plain-text mail to L<mailto:meta@public-inbox.org>
651
652 The mail archives are hosted at L<https://public-inbox.org/meta/>
653
654 =head1 COPYRIGHT
655
656 Copyright (C) 2016 all contributors L<mailto:meta@public-inbox.org>
657
658 License: AGPL-3.0+ L<http://www.gnu.org/licenses/agpl-3.0.txt>
659
660 =cut