]> sipb.mit.edu Git - ikiwiki.git/commitdiff
truncate recentchangesdiffs after 200 lines
authorJoey Hess <joey@kodama.kitenet.net>
Wed, 12 Mar 2008 19:45:10 +0000 (15:45 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Wed, 12 Mar 2008 19:45:10 +0000 (15:45 -0400)
This works around a perl crasher bug, and also avoids bloating pages
with enormous diffs.

rcs_recentchanges modified to return a list in an array context.

IkiWiki/Plugin/recentchangesdiff.pm
IkiWiki/Rcs/Stub.pm
IkiWiki/Rcs/git.pm
IkiWiki/Rcs/svn.pm
IkiWiki/Rcs/tla.pm
doc/bugs/recentchangesdiff_crashes_on_commits_which_remove_a_lot_of_files.mdwn
po/ikiwiki.pot

index bd2826f76518fc2c1a7060d21110331ce744ac2d..3942f308b05a86b5d4e7f0524fd756534a492391 100644 (file)
@@ -5,6 +5,8 @@ use warnings;
 use strict;
 use IkiWiki 2.00;
 
+my $maxlines=200;
+
 sub import { #{{{
        hook(type => "pagetemplate", id => "recentchangesdiff",
                call => \&pagetemplate);
@@ -15,8 +17,17 @@ sub pagetemplate (@) { #{{{
        my $template=$params{template};
        if ($config{rcs} && exists $params{rev} && length $params{rev} &&
            $template->query(name => "diff")) {
-               my $diff=IkiWiki::rcs_diff($params{rev});
-               if (defined $diff && length $diff) {
+               my @lines=IkiWiki::rcs_diff($params{rev});
+               if (@lines) {
+                       my $diff;
+                       if (@lines > $maxlines) {
+                               # only include so many lines of diff
+                               $diff=join("", @lines[0..($maxlines-1)])."\n".
+                                       gettext("(Diff truncated)");
+                       }
+                       else {
+                               $diff=join("", @lines);
+                       }
                        # escape links and preprocessor stuff
                        $diff =~ s/(?<!\\)\[\[/\\\[\[/g;
                        $template->param(diff => $diff);
index d94daf8bc9522b31db221c162bab410a5e16a2ed..a460f29a2ee34f9580ba9ad5a81c3b2159a32acf 100644 (file)
@@ -60,7 +60,8 @@ sub rcs_recentchanges ($) {
 sub rcs_diff ($) {
        # Optional, used to get diffs for recentchanges.
        # The parameter is the rev from rcs_recentchanges.
-       return "";
+       # Should return a list of lines of the diff (including \n) in list
+       # context, and the whole diff in scalar context.
 }
 
 sub rcs_getctime ($) {
index 9306a513eb01b0bb6e013e7aad5523d341cb195b..1882b43ef5f1c8e642b429785ca9e55af556ae48 100644 (file)
@@ -414,16 +414,18 @@ sub rcs_recentchanges ($) { #{{{
 sub rcs_diff ($) { #{{{
        my $rev=shift;
        my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint
-       my $ret;
+       my @lines;
        foreach my $line (run_or_non("git", "show", $sha1)) {
-               if (defined $ret) {
-                       $ret.=$line."\n";
-               }
-               elsif ($line=~/^diff --git/) {
-                       $ret=$line."\n";
+               if (@lines || $line=~/^diff --git/) {
+                       push @lines, $line."\n";
                }
        }
-       return $ret;
+       if (wantarray) {
+               return @lines;
+       }
+       else {
+               return join("", @lines);
+       }
 } #}}}
 
 sub rcs_getctime ($) { #{{{
index 7bad407475808588654551c52cfd82dd7228ceac..ea193e08f33418ab7be3f91819fade367dda7092 100644 (file)
@@ -219,7 +219,7 @@ sub rcs_recentchanges ($) { #{{{
 
 sub rcs_diff ($) { #{{{
        my $rev=possibly_foolish_untaint(int(shift));
-       return scalar `svnlook diff $config{svnrepo} -r$rev --no-diff-deleted`;
+       return `svnlook diff $config{svnrepo} -r$rev --no-diff-deleted`;
 } #}}}
 
 sub rcs_getctime ($) { #{{{
index 2890ff8c73d68e1609cb18f1f313d66336bdfbde..47579c15b756252e1054efe77901c22568ce7c4e 100644 (file)
@@ -171,7 +171,7 @@ sub rcs_diff ($) { #{{{
        }
 
        my $revminusone = $changesets[$i+1];
-       return scalar `tla diff -d $config{srcdir} $revminusone`;
+       return `tla diff -d $config{srcdir} $revminusone`;
 } #}}}
 
 sub rcs_getctime ($) { #{{{
index 5872275b5c40b3de73546ba4215c4f99b5a183f7..eaf6c95e9619fb3b8c1f6cb250f7ebca212ca6ed 100644 (file)
@@ -23,3 +23,24 @@ The tarball is at http://scratch.madduck.net/__tmp__recentchanges-segfault.tgz -
     rm -rf wc/recentchanges
     ikiwiki --setup ikiwiki.setup
     # works
+
+> I can reproduce it fine with that, thanks, and it's really looking like a
+> pure perl bug, that is triggered by markdown. Here's a simpler test case:
+
+       joey@kodama:/tmp>markdown < f
+       zsh: segmentation fault  markdown < f
+
+> Where f is a 6.3 mb file that I
+> extracted from ikiwiki's rendering pipeline.
+
+> It seems to be crashing at markdown line 345, which is a big nasty
+> `s///` statement.
+
+> The good news: markdown version 1.0.2~b8-2 does not trigger this perl bug.
+> I only see it with 1.0.1. (Bad news: Newer versions of markdown are
+> slooooooow, especially on such large files.)
+
+> I'm calling this [[done]] since I've filed [[debbug 470676]] on perl, and
+> also have modified recentchangesdiff to only show the first 200 lines of
+> diff, which should be enough without bloating the recentchanges into
+> perl-crashing territory. --[[Joey]]
index 76baba228f9f64028be032263d6fb69d16e6e045..7ba12899a0f9e706efd2e4137faa729870973f4b 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2008-03-12 13:53-0400\n"
+"POT-Creation-Date: 2008-03-12 15:42-0400\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -40,30 +40,30 @@ msgstr ""
 msgid "Preferences saved."
 msgstr ""
 
-#: ../IkiWiki/CGI.pm:291
+#: ../IkiWiki/CGI.pm:293
 #, perl-format
 msgid "%s is not an editable page"
 msgstr ""
 
-#: ../IkiWiki/CGI.pm:384 ../IkiWiki/Plugin/brokenlinks.pm:24
+#: ../IkiWiki/CGI.pm:385 ../IkiWiki/Plugin/brokenlinks.pm:24
 #: ../IkiWiki/Plugin/inline.pm:237 ../IkiWiki/Plugin/opendiscussion.pm:17
 #: ../IkiWiki/Plugin/orphans.pm:28 ../IkiWiki/Render.pm:95
 #: ../IkiWiki/Render.pm:172
 msgid "discussion"
 msgstr ""
 
-#: ../IkiWiki/CGI.pm:440
+#: ../IkiWiki/CGI.pm:441
 #, perl-format
 msgid "creating %s"
 msgstr ""
 
-#: ../IkiWiki/CGI.pm:458 ../IkiWiki/CGI.pm:476 ../IkiWiki/CGI.pm:486
-#: ../IkiWiki/CGI.pm:520 ../IkiWiki/CGI.pm:564
+#: ../IkiWiki/CGI.pm:459 ../IkiWiki/CGI.pm:477 ../IkiWiki/CGI.pm:487
+#: ../IkiWiki/CGI.pm:521 ../IkiWiki/CGI.pm:566
 #, perl-format
 msgid "editing %s"
 msgstr ""
 
-#: ../IkiWiki/CGI.pm:653
+#: ../IkiWiki/CGI.pm:656
 msgid "You are banned."
 msgstr ""
 
@@ -500,7 +500,7 @@ msgstr ""
 msgid "code includes disallowed latex commands"
 msgstr ""
 
-#: ../IkiWiki/Plugin/teximg.pm:96
+#: ../IkiWiki/Plugin/teximg.pm:88
 msgid "failed to generate image from code"
 msgstr ""
 
@@ -508,7 +508,7 @@ msgstr ""
 msgid "(not toggleable in preview mode)"
 msgstr ""
 
-#: ../IkiWiki/Rcs/Stub.pm:68
+#: ../IkiWiki/Rcs/Stub.pm:69
 msgid "getctime not implemented"
 msgstr ""