diff options
author | Eric Wong <e@80x24.org> | 2017-02-09 01:37:03 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2017-02-09 01:37:03 +0000 |
commit | d9563ea5516e8e786debf223e10ec11695aee9d7 (patch) | |
tree | a0842b1ee0953bc8e65d21d5d96432f41973adb7 /lib/PublicInbox/RepoGitPatch.pm | |
parent | fb9ed5324ec7de9420956840ba9a6585b81e8231 (diff) | |
download | public-inbox-d9563ea5516e8e786debf223e10ec11695aee9d7.tar.gz |
We'll still be keeping "repobrowse" for the public API for use with .psgi files, but shortening the name means less typing and we may have command-line tools, too.
Diffstat (limited to 'lib/PublicInbox/RepoGitPatch.pm')
-rw-r--r-- | lib/PublicInbox/RepoGitPatch.pm | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/PublicInbox/RepoGitPatch.pm b/lib/PublicInbox/RepoGitPatch.pm new file mode 100644 index 00000000..e9227b6f --- /dev/null +++ b/lib/PublicInbox/RepoGitPatch.pm @@ -0,0 +1,39 @@ +# Copyright (C) 2015 all contributors <meta@public-inbox.org> +# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> + +# shows the /patch/ endpoint for git repositories +# usage: /repo.git/patch?id=COMMIT_ID +package PublicInbox::RepoGitPatch; +use strict; +use warnings; +use base qw(PublicInbox::RepoBase); +use PublicInbox::Qspawn; + +# try to be educational and show the command-line used in the signature +my @CMD = qw(format-patch -M --stdout); +my $sig = '--signature=git '.join(' ', @CMD); + +sub call_git_patch { + my ($self, $req) = @_; + my $git = $req->{repo_info}->{git}; + my $env = $req->{env}; + my $q = PublicInbox::RepoGitQuery->new($env); + my $id = $q->{id}; + $id =~ /\A[\w-]+([~\^][~\^\d])*\z/ or $id = 'HEAD'; + + # limit scope, don't take extra args to avoid wasting server + # resources buffering: + my $range = "$id~1..$id^0"; + my $cmd = $git->cmd(@CMD, $sig." $range", $range, '--'); + my $expath = $req->{expath}; + push @$cmd, $expath if $expath ne ''; + + my $qsp = PublicInbox::Qspawn->new($cmd); + $qsp->psgi_return($env, undef, sub { + my ($r) = @_; + my $h = ['Content-Type', 'text/plain; charset=UTF-8']; + $r ? [ 200, $h ] : [ 500, $h, [ "format-patch error\n" ] ]; + }); +} + +1; |