# Copyright (C) 2015 all contributors
# License: AGPL-3.0+
package PublicInbox::RepoGitTree;
use strict;
use warnings;
use base qw(PublicInbox::RepoBase);
use PublicInbox::Hval qw(utf8_html);
use PublicInbox::Qspawn;
my %GIT_MODE = (
'100644' => ' ', # blob
'100755' => 'x', # executable blob
'040000' => 'd', # tree
'120000' => 'l', # symlink
'160000' => 'g', # commit (gitlink)
);
my $BINARY_MSG = "Binary file, save using the 'raw' link above";
sub call_git_tree {
my ($self, $req) = @_;
my @extra = @{$req->{extra}};
my $git = $req->{-repo}->{git};
my $obj = "$req->{-tip}:$req->{expath}";
my ($hex, $type, $size) = $git->check($obj);
unless (defined($type)) {
return [404, ['Content-Type'=>'text/plain'], ['Not Found']];
}
my $opts = { nofollow => 1 };
my $title = $req->{expath};
$title = $title eq '' ? 'tree' : utf8_html($title);
if ($type eq 'tree') {
$opts->{noindex} = 1;
$req->{thtml} = $self->html_start($req, $title, $opts) . "\n";
git_tree_show($req, $hex);
} elsif ($type eq 'blob') {
sub {
my $res = $_[0];
my $fh = $res->([200,
['Content-Type','text/html; charset=UTF-8']]);
$fh->write($self->html_start($req, $title, $opts) .
"\n");
git_blob_show($req, $fh, $git, $hex);
$fh->write('