@matheusbsbs / matheus-bagliano / commits / 157e43b4b0
Fork 0

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>

Jakub Narebski committed Aug 24, 2006 at 19:34 UTC 157e43b4b0dd5a08eb7a6838192ac58bca62fa5b
1 file changed +7 -8
gitweb/gitweb.perl
+7 -8
@@ -1539,7 +1539,7 @@ sub git_difftree_body {
1539 }
1540
1541 sub git_patchset_body {
1542 - my ($patchset, $difftree, $hash, $hash_parent) = @_;
1542 + my ($fd, $difftree, $hash, $hash_parent) = @_;
1543
1544 my $patch_idx = 0;
1545 my $in_header = 0;
@@ -1548,7 +1548,9 @@ sub git_patchset_body {
1548
1549 print "<div class=\"patchset\">\n";
1550
1551 - LINE: foreach my $patch_line (@$patchset) {
1551 + LINE:
1552 + while (my $patch_line @$fd>) {
1553 + chomp $patch_line;
1554
1555 if ($patch_line =~ m/^diff /) { # "git diff" header
1556 # beginning of patch (in patchset)
@@ -2727,7 +2729,6 @@ sub git_commitdiff {
2729 # read commitdiff
2730 my $fd;
2731 my @difftree;
2730 - my @patchset;
2732 if ($format eq 'html') {
2733 open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C',
2734 "--patch-with-raw", "--full-index", $hash_parent, $hash
@@ -2738,13 +2739,11 @@ sub git_commitdiff {
2739 last unless $line;
2740 push @difftree, $line;
2741 }
2741 - @patchset = map { chomp; $_ } <$fd>;
2742
2743 - close $fd
2744 - or die_error(undef, "Reading git-diff-tree failed");
2743 } elsif ($format eq 'plain') {
2744 open $fd, "-|", $GIT, "diff-tree", '-r', '-p', '-B', $hash_parent, $hash
2745 or die_error(undef, "Open git-diff-tree failed");
2746 +
2747 } else {
2748 die_error(undef, "Unknown commitdiff format");
2749 }
@@ -2806,8 +2805,8 @@ TEXT
2805 #git_difftree_body(\@difftree, $hash, $hash_parent);
2806 #print "<br/>\n";
2807
2809 - git_patchset_body(\@patchset, \@difftree, $hash, $hash_parent);
2810 -
2808 + git_patchset_body($fd, \@difftree, $hash, $hash_parent);
2809 + close $fd;
2810 print "</div>\n"; # class="page_body"
2811 git_footer_html();
2812