about summary refs log tree commit homepage
path: root/lib/PublicInbox/RepobrowseGitPlain.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-12-13 21:56:39 +0000
committerEric Wong <e@80x24.org>2016-12-14 00:22:55 +0000
commit00488f0cfe9f81d04cd65d09ea783e860c937401 (patch)
tree24e4d9282d5e7098fc6cbdcc9d5615c46513661f /lib/PublicInbox/RepobrowseGitPlain.pm
parentf9d4f28d9761011d3c7ffad9e2c9d1e54b65c519 (diff)
parent6cdb0221d18b2caed4d0caebf7c20d6eb159497d (diff)
downloadpublic-inbox-00488f0cfe9f81d04cd65d09ea783e860c937401.tar.gz
* origin/repobrowse: (98 commits)
  t/repobrowse_git_httpd.t: ensure signature exists for split
  t/repobrowse_git_tree.t: fix test for lack of bold
  repobrowse: fix alignment of gitlink entries
  repobrowse: show invalid type for tree views
  repobrowse: do not bold directory names in tree view
  repobrowse: reduce checks for response fh
  repobrowse: larger, short-lived buffer for reading patches
  repobrowse: reduce risk of callback reference cycles
  repobrowse: snapshot support for cgit compatibility
  test: disable warning for Plack::Test::Impl
  repobrowse: avoid confusing linkification for "diff"
  repobrowse: git commit view uses pi-httpd.async
  repobrowse: more consistent variable naming for /commit/
  repobrowse: show roughly equivalent "diff-tree" invocation
  repobrowse: reduce local variables for state management
  repobrowse: summary handles multiple README types
  repobrowse: remove bold decorations from diff view
  repobrowse: common git diff parsing code
  repobrowse: implement diff view for compatibility
  examples/repobrowse.psgi: disable Chunked response by default
  ...
Diffstat (limited to 'lib/PublicInbox/RepobrowseGitPlain.pm')
-rw-r--r--lib/PublicInbox/RepobrowseGitPlain.pm81
1 files changed, 81 insertions, 0 deletions
diff --git a/lib/PublicInbox/RepobrowseGitPlain.pm b/lib/PublicInbox/RepobrowseGitPlain.pm
new file mode 100644
index 00000000..01919895
--- /dev/null
+++ b/lib/PublicInbox/RepobrowseGitPlain.pm
@@ -0,0 +1,81 @@
+# Copyright (C) 2015-2016 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+package PublicInbox::RepobrowseGitPlain;
+use strict;
+use warnings;
+use base qw(PublicInbox::RepobrowseBase);
+use PublicInbox::RepobrowseGitBlob;
+use PublicInbox::Hval qw(utf8_html);
+
+sub call_git_plain {
+        my ($self, $req) = @_;
+        my $git = $req->{repo_info}->{git};
+        my $q = PublicInbox::RepobrowseGitQuery->new($req->{cgi});
+        my $id = $q->{id};
+        $id eq '' and $id = 'HEAD';
+
+        if (length(my $expath = $req->{expath})) {
+                $id .= ":$expath";
+        } else {
+                $id .= ':';
+        }
+        my ($cat, $hex, $type, $size) = $git->cat_file_begin($id);
+        return unless defined $cat;
+
+        my ($r, $buf);
+        my $left = $size;
+        if ($type eq 'blob') {
+                $type = git_blob_mime_type($self, $req, $cat, \$buf, \$left);
+        } elsif ($type eq 'commit' || $type eq 'tag') {
+                $type = 'text/plain';
+        } elsif ($type eq 'tree') {
+                $git->cat_file_finish($left);
+                return git_tree_plain($req, $git, $hex);
+        } else {
+                $type = 'application/octet-stream';
+        }
+        git_blob_stream_response($git, $cat, $size, $type, $buf, $left);
+}
+
+# This should follow the cgit DOM structure in case anybody depends on it,
+# not using <pre> here as we don't expect people to actually view it much
+sub git_tree_plain {
+        my ($req, $git, $hex) = @_;
+
+        my @ex = @{$req->{extra}};
+        my $rel = $req->{relcmd};
+        my $title = utf8_html(join('/', '', @ex, ''));
+        my $tslash = $req->{tslash};
+        my $pfx = $tslash ? './' : 'plain/';
+        my $t = "<h2>$title</h2><ul>";
+        if (@ex) {
+                if ($tslash) {
+                        $t .= qq(<li><a\nhref="../">../</a></li>);
+                } else  {
+                        $t .= qq(<li><a\nhref="./">../</a></li>);
+                        my $last = PublicInbox::Hval->utf8($ex[-1])->as_href;
+                        $pfx = "$last/";
+                }
+        }
+        my $ls = $git->popen(qw(ls-tree --name-only -z), $git->abbrev, $hex);
+        sub {
+                my ($res) = @_;
+                my $fh = $res->([ 200, ['Content-Type' => 'text/html']]);
+                $fh->write("<html><head><title>$title</title></head><body>".
+                                $t);
+
+                local $/ = "\0";
+                while (defined(my $n = <$ls>)) {
+                        chomp $n;
+                        $n = PublicInbox::Hval->utf8($n);
+                        my $ref = $n->as_path;
+                        $n = $n->as_html;
+
+                        $fh->write(qq(<li><a\nhref="$pfx$ref">$n</a></li>))
+                }
+                $fh->write('</ul></body></html>');
+                $fh->close;
+        }
+}
+
+1;