# 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 $repo = $req->{-repo};
my $git = $repo->{git};
my $tip = $req->{tip} || $repo->tip;
my $obj = "$tip:$req->{expath}";
sub {
my ($res) = @_;
$git->check_async($req->{env}, $obj, sub {
my ($info) = @_;
my ($hex, $type, $size) = @$info;
unless (defined $type) {
return $res->([404,
['Content-Type','text/plain'],
['Not Found']]);
}
show_tree($self, $req, $res, $hex, $type, $size);
});
}
}
sub show_tree {
my ($self, $req, $res, $hex, $type, $size) = @_;
my $opts = { nofollow => 1 };
my $title = "tree: ".utf8_html($req->{expath});
if ($type eq 'tree') {
$opts->{noindex} = 1;
$req->{thtml} = $self->html_start($req, $title, $opts) . "\n";
git_tree_show($req, $res, $hex);
} elsif ($type eq 'blob') {
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,$hex);
$fh->write('