about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-03-04 00:32:45 +0000
committerEric Wong <e@80x24.org>2017-03-04 00:32:45 +0000
commit10f315b0f25cc8141ddfd9c03c58db65ca5652b5 (patch)
treeced7f98f785aac85dfbb79ff05ba7deea5cc413f
parent839d6fc6598473644f80056c1ebabad3fa05af63 (diff)
downloadpublic-inbox-10f315b0f25cc8141ddfd9c03c58db65ca5652b5.tar.gz
We need to take the revision into account when generating
patches :P  While we're at it, disabiguate URLs by resolving
refnames to (un-SHAttered) hex identifiers.
-rw-r--r--lib/PublicInbox/RepoGitPatch.pm31
1 files changed, 25 insertions, 6 deletions
diff --git a/lib/PublicInbox/RepoGitPatch.pm b/lib/PublicInbox/RepoGitPatch.pm
index 1c9ec45f..b9b73e0a 100644
--- a/lib/PublicInbox/RepoGitPatch.pm
+++ b/lib/PublicInbox/RepoGitPatch.pm
@@ -13,13 +13,11 @@ use PublicInbox::Qspawn;
 my @CMD = qw(format-patch -M --stdout);
 my $sig = '--signature=git '.join(' ', @CMD);
 
-sub call_git_patch {
-        my ($self, $req) = @_;
-        my $repo = $req->{-repo};
-        my $git = $repo->{git};
+sub fmt_patch ($$$) {
+        my ($self, $req, $res) = @_;
+        my $git = $req->{-repo}->{git};
+        my $tip = $req->{tip};
         my $env = $req->{env};
-        my $tip = $repo->tip;
-        $tip =~ /\A[\w-]+([~\^][~\^\d])*\z/;
 
         # limit scope, don't take extra args to avoid wasting server
         # resources buffering:
@@ -27,6 +25,7 @@ sub call_git_patch {
         my $cmd = $git->cmd(@CMD, $sig." $range", $range, '--');
         my $expath = $req->{expath};
         push @$cmd, $expath if $expath ne '';
+        $env->{'qspawn.response'} = $res;
 
         my $qsp = PublicInbox::Qspawn->new($cmd);
         $qsp->psgi_return($env, undef, sub {
@@ -36,4 +35,24 @@ sub call_git_patch {
         });
 }
 
+sub call_git_patch {
+        my ($self, $req) = @_;
+        sub {
+                my ($res) = @_;
+                my $repo = $req->{-repo};
+                my $tip = $req->{tip};
+                my $obj = $tip || $repo->tip;
+                $repo->{git}->check_async($req->{env}, $obj.'^{commit}', sub {
+                        my ($info) = @_;
+                        my ($hex, $type, undef) = @$info;
+                        if (!defined $type || $type ne 'commit') {
+                                return $res->($self->rt(400, 'plain',
+                                                "$obj is not a commit\n"));
+                        }
+                        return fmt_patch($self, $req, $res) if $obj eq $hex;
+                        $res->($self->r(302, $req, $tip ? "../$hex" : $hex));
+                });
+        }
+}
+
 1;