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