From: Eric Wong Date: Thu, 24 Dec 2015 01:26:44 +0000 (+0000) Subject: repobrowse: add /patch/ endpoint X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9a36cddfc20432cf0553a87fcc6013c922199146;p=thirdparty%2Fpublic-inbox.git repobrowse: add /patch/ endpoint This is trivial for generating patches so users can run: "curl $URL | git am" against any instance of this. --- diff --git a/lib/PublicInbox/RepoBrowse.pm b/lib/PublicInbox/RepoBrowse.pm index ef3bcf878..3aa8b98a8 100644 --- a/lib/PublicInbox/RepoBrowse.pm +++ b/lib/PublicInbox/RepoBrowse.pm @@ -23,7 +23,7 @@ use warnings; use URI::Escape qw(uri_escape_utf8 uri_unescape); use PublicInbox::RepoConfig; -my %CMD = map { lc($_) => $_ } qw(Log Commit Tree); +my %CMD = map { lc($_) => $_ } qw(Log Commit Tree Patch); my %VCS = (git => 'Git'); my %LOADED; diff --git a/lib/PublicInbox/RepoBrowseGitPatch.pm b/lib/PublicInbox/RepoBrowseGitPatch.pm new file mode 100644 index 000000000..b998a860b --- /dev/null +++ b/lib/PublicInbox/RepoBrowseGitPatch.pm @@ -0,0 +1,39 @@ +# Copyright (C) 2015 all contributors +# License: AGPL-3.0+ + +# shows the /commit/ endpoint for git repositories +package PublicInbox::RepoBrowseGitPatch; +use strict; +use warnings; +use base qw(PublicInbox::RepoBrowseBase); +use PublicInbox::Git; + +sub call_git_patch { + my ($self, $req) = @_; + my $repo_info = $req->{repo_info}; + my $dir = $repo_info->{path}; + my $git = $repo_info->{git} ||= PublicInbox::Git->new($dir); + + my $q = PublicInbox::RepoBrowseQuery->new($req->{cgi}); + my $id = $q->{id}; + $id eq '' and $id = 'HEAD'; + my $fp = $git->popen(qw(format-patch -M -1 --stdout --encoding=utf-8 + --signature=public-inbox.org), $id); + my ($buf, $n); + + $n = read($fp, $buf, 8192); + return unless (defined $n && $n > 0); + sub { + my ($res) = @_; # Plack callback + my $fh = $res->([200, ['Content-Type'=>'text/plain']]); + $fh->write($buf); + while (1) { + $n = read($fp, $buf, 8192); + last unless (defined $n && $n > 0); + $fh->write($buf); + } + $fh->close; + } +} + +1;