# Copyright (C) 2016 all contributors
# License: AGPL-3.0+
# shows the /diff endpoint for git repositories for cgit compatibility
# usage: /repo.git/diff?id=COMMIT_ID&id2=COMMIT_ID2
#
# We probably will not link to this outright because it's expensive,
# but exists to preserve URL compatibility with cgit.
package PublicInbox::RepoGitDiff;
use strict;
use warnings;
use base qw(PublicInbox::RepoBase);
use PublicInbox::Hval qw(utf8_html);
use PublicInbox::RepoGitDiffCommon;
use PublicInbox::Qspawn;
sub git_diff_sed ($$) {
my ($self, $req) = @_;
git_diff_sed_init($req);
$req->{dstate} = DSTATE_STAT;
# this filters for $fh->write or $body->getline (see Qspawn)
sub {
my $dst = delete $req->{dhtml} || '';
if (defined $_[0]) { # $_[0] == scalar buffer
$req->{dbuf} .= $_[0];
git_diff_sed_run(\$dst, $req);
} else { # undef means EOF from "git show", flush the last bit
git_diff_sed_close(\$dst, $req);
$dst .= '