# Copyright (C) 2015-2016 all contributors
# License: AGPL-3.0+
package PublicInbox::RepoGitRaw;
use strict;
use warnings;
use base qw(PublicInbox::RepoBase);
use PublicInbox::Hval qw(utf8_html);
use PublicInbox::Qspawn;
my $MAX_ASYNC = 65536;
sub call_git_raw {
my ($self, $req) = @_;
my $repo = $req->{-repo};
my $git = $repo->{git};
my $tip = $req->{tip} || $repo->tip;
my $expath = $req->{expath};
my $obj = $tip;
$obj .= ":$expath" if $expath ne '';
my $env = $req->{env};
sub {
my ($res) = @_;
$git->check_async($env, $obj, sub {
my ($info) = @_;
my ($hex, $type, $size) = @$info;
if (!defined $type || $type eq 'missing') {
return $res->($self->rt(404, 'plain',
'Not Found'));
}
my $ct;
if ($type eq 'blob') {
my $base = $req->{extra}->[-1];
$ct = $self->mime_type($base) if defined $base;
$ct ||= 'text/plain; charset=UTF-8' if !$size;
} elsif ($type eq 'commit' || $type eq 'tag') {
$ct = 'text/plain; charset=UTF-8';
} elsif ($type eq 'tree') {
return git_tree_raw($self, $req, $res, $hex);
} else {
$ct = 'application/octet-stream';
}
show_raw($self, $req, $res, $ct, $hex, $type, $size);
});
}
}
sub git_tree_sed ($) {
my ($req) = @_;
my $buf = '';
my $end = '';
my $pfx = $req->{tpfx};
sub { # $_[0] = buffer or undef
my $dst = delete $req->{tstart} || '';
my @files;
if (defined $_[0]) {
@files = split(/\0/, $buf .= $_[0]);
$buf = pop @files if scalar @files;
} else {
@files = split(/\0/, $buf);
$end = '