gitweb: Streamify patch output in git_commitdiff
Change output of patch(set) in git_commitdiff from slurping whole diff in @patchset array before processing, to passing file descriptor to git_patchset_body. Advantages: faster, incremental output, smaller memory footprint. Disadvantages: cannot react when there is error during closing file descriptor. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
1613b79faa
commit
157e43b4b0
@ -1539,7 +1539,7 @@ sub git_difftree_body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub git_patchset_body {
|
sub git_patchset_body {
|
||||||
my ($patchset, $difftree, $hash, $hash_parent) = @_;
|
my ($fd, $difftree, $hash, $hash_parent) = @_;
|
||||||
|
|
||||||
my $patch_idx = 0;
|
my $patch_idx = 0;
|
||||||
my $in_header = 0;
|
my $in_header = 0;
|
||||||
@ -1548,7 +1548,9 @@ sub git_patchset_body {
|
|||||||
|
|
||||||
print "<div class=\"patchset\">\n";
|
print "<div class=\"patchset\">\n";
|
||||||
|
|
||||||
LINE: foreach my $patch_line (@$patchset) {
|
LINE:
|
||||||
|
while (my $patch_line @$fd>) {
|
||||||
|
chomp $patch_line;
|
||||||
|
|
||||||
if ($patch_line =~ m/^diff /) { # "git diff" header
|
if ($patch_line =~ m/^diff /) { # "git diff" header
|
||||||
# beginning of patch (in patchset)
|
# beginning of patch (in patchset)
|
||||||
@ -2727,7 +2729,6 @@ sub git_commitdiff {
|
|||||||
# read commitdiff
|
# read commitdiff
|
||||||
my $fd;
|
my $fd;
|
||||||
my @difftree;
|
my @difftree;
|
||||||
my @patchset;
|
|
||||||
if ($format eq 'html') {
|
if ($format eq 'html') {
|
||||||
open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C',
|
open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C',
|
||||||
"--patch-with-raw", "--full-index", $hash_parent, $hash
|
"--patch-with-raw", "--full-index", $hash_parent, $hash
|
||||||
@ -2738,13 +2739,11 @@ sub git_commitdiff {
|
|||||||
last unless $line;
|
last unless $line;
|
||||||
push @difftree, $line;
|
push @difftree, $line;
|
||||||
}
|
}
|
||||||
@patchset = map { chomp; $_ } <$fd>;
|
|
||||||
|
|
||||||
close $fd
|
|
||||||
or die_error(undef, "Reading git-diff-tree failed");
|
|
||||||
} elsif ($format eq 'plain') {
|
} elsif ($format eq 'plain') {
|
||||||
open $fd, "-|", $GIT, "diff-tree", '-r', '-p', '-B', $hash_parent, $hash
|
open $fd, "-|", $GIT, "diff-tree", '-r', '-p', '-B', $hash_parent, $hash
|
||||||
or die_error(undef, "Open git-diff-tree failed");
|
or die_error(undef, "Open git-diff-tree failed");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
die_error(undef, "Unknown commitdiff format");
|
die_error(undef, "Unknown commitdiff format");
|
||||||
}
|
}
|
||||||
@ -2806,8 +2805,8 @@ TEXT
|
|||||||
#git_difftree_body(\@difftree, $hash, $hash_parent);
|
#git_difftree_body(\@difftree, $hash, $hash_parent);
|
||||||
#print "<br/>\n";
|
#print "<br/>\n";
|
||||||
|
|
||||||
git_patchset_body(\@patchset, \@difftree, $hash, $hash_parent);
|
git_patchset_body($fd, \@difftree, $hash, $hash_parent);
|
||||||
|
close $fd;
|
||||||
print "</div>\n"; # class="page_body"
|
print "</div>\n"; # class="page_body"
|
||||||
git_footer_html();
|
git_footer_html();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user