From: Joey Hess Date: Mon, 3 Mar 2008 20:53:34 +0000 (-0500) Subject: * Add recentchangesdiff plugin that adds diffs to the recentchanges feeds. X-Git-Tag: 2.41~204 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d93aaed7919f0449d387aed6c6ee3aaff85a12eb;p=ikiwiki.git * Add recentchangesdiff plugin that adds diffs to the recentchanges feeds. * rcs_diff is a new function that rcs modules should implement. * Implemented rcs_diff for git, svn, and tla (tla version untested). Mercurial and monotone still todo. --- diff --git a/IkiWiki/Plugin/recentchanges.pm b/IkiWiki/Plugin/recentchanges.pm index 22f934f2e..e591df79f 100644 --- a/IkiWiki/Plugin/recentchanges.pm +++ b/IkiWiki/Plugin/recentchanges.pm @@ -133,7 +133,7 @@ sub store ($$$) { #{{{ ); } - # escape wikilinks and preprocessor stuff in commit messages + # escape wikilinks and preprocessor stuff in commit messages if (ref $change->{message}) { foreach my $field (@{$change->{message}}) { if (exists $field->{line}) { @@ -150,7 +150,8 @@ sub store ($$$) { #{{{ wikiname => $config{wikiname}, ); IkiWiki::run_hooks(pagetemplate => sub { - shift->(page => $page, destpage => $page, template => $template); + shift->(page => $page, destpage => $page, + template => $template, rev => $change->{rev}); }); my $file=$page."._change"; diff --git a/IkiWiki/Plugin/recentchangesdiff.pm b/IkiWiki/Plugin/recentchangesdiff.pm new file mode 100644 index 000000000..bd2826f76 --- /dev/null +++ b/IkiWiki/Plugin/recentchangesdiff.pm @@ -0,0 +1,27 @@ +#!/usr/bin/perl +package IkiWiki::Plugin::recentchangesdiff; + +use warnings; +use strict; +use IkiWiki 2.00; + +sub import { #{{{ + hook(type => "pagetemplate", id => "recentchangesdiff", + call => \&pagetemplate); +} #}}} + +sub pagetemplate (@) { #{{{ + my %params=@_; + 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) { + # escape links and preprocessor stuff + $diff =~ s/(?param(diff => $diff); + } + } +} #}}} + +1 diff --git a/IkiWiki/Rcs/Stub.pm b/IkiWiki/Rcs/Stub.pm index df347f6a9..d94daf8bc 100644 --- a/IkiWiki/Rcs/Stub.pm +++ b/IkiWiki/Rcs/Stub.pm @@ -57,6 +57,12 @@ sub rcs_recentchanges ($) { # } } +sub rcs_diff ($) { + # Optional, used to get diffs for recentchanges. + # The parameter is the rev from rcs_recentchanges. + return ""; +} + sub rcs_getctime ($) { # Optional, used to get the page creation time from the RCS. error gettext("getctime not implemented"); diff --git a/IkiWiki/Rcs/git.pm b/IkiWiki/Rcs/git.pm index 26a6f4266..376d03c78 100644 --- a/IkiWiki/Rcs/git.pm +++ b/IkiWiki/Rcs/git.pm @@ -419,6 +419,12 @@ sub rcs_recentchanges ($) { #{{{ return @rets; } #}}} +sub rcs_diff ($) { #{{{ + my $rev=shift; + my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint + return join("\n", run_or_non("git", "diff", "$sha1^", $sha1)); +} #}}} + sub rcs_getctime ($) { #{{{ my $file=shift; # Remove srcdir prefix diff --git a/IkiWiki/Rcs/mercurial.pm b/IkiWiki/Rcs/mercurial.pm index 8b1f2c6a1..a042f4a45 100644 --- a/IkiWiki/Rcs/mercurial.pm +++ b/IkiWiki/Rcs/mercurial.pm @@ -148,6 +148,10 @@ sub rcs_recentchanges ($) { #{{{ return @ret; } #}}} +sub rcs_diff ($) { #{{{ + # TODO +} #}}} + sub rcs_getctime ($) { #{{{ my ($file) = @_; diff --git a/IkiWiki/Rcs/monotone.pm b/IkiWiki/Rcs/monotone.pm index 6a156892a..06615da11 100644 --- a/IkiWiki/Rcs/monotone.pm +++ b/IkiWiki/Rcs/monotone.pm @@ -475,6 +475,10 @@ sub rcs_recentchanges ($) { #{{{ return @ret; } #}}} +sub rcs_diff ($) { #{{{ + # TODO +} #}}} + sub rcs_getctime ($) { #{{{ my $file=shift; diff --git a/IkiWiki/Rcs/svn.pm b/IkiWiki/Rcs/svn.pm index f7d2242f0..7bad40747 100644 --- a/IkiWiki/Rcs/svn.pm +++ b/IkiWiki/Rcs/svn.pm @@ -217,6 +217,11 @@ sub rcs_recentchanges ($) { #{{{ return @ret; } #}}} +sub rcs_diff ($) { #{{{ + my $rev=possibly_foolish_untaint(int(shift)); + return scalar `svnlook diff $config{svnrepo} -r$rev --no-diff-deleted`; +} #}}} + sub rcs_getctime ($) { #{{{ my $file=shift; diff --git a/IkiWiki/Rcs/tla.pm b/IkiWiki/Rcs/tla.pm index 231496445..2890ff8c7 100644 --- a/IkiWiki/Rcs/tla.pm +++ b/IkiWiki/Rcs/tla.pm @@ -160,6 +160,20 @@ sub rcs_recentchanges ($) { return @ret; } +sub rcs_diff ($) { #{{{ + my $rev=shift; + my $logs = `tla logs -d $config{srcdir}`; + my @changesets = reverse split(/\n/, $logs); + my $i; + + for($i=0;$i<$#changesets;$i++) { + last if $changesets[$i] eq $rev; + } + + my $revminusone = $changesets[$i+1]; + return scalar `tla diff -d $config{srcdir} $revminusone`; +} #}}} + sub rcs_getctime ($) { #{{{ my $file=shift; eval q{use Date::Parse}; diff --git a/debian/changelog b/debian/changelog index 30416ecdd..a9d530c1e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,6 +9,12 @@ ikiwiki (2.41) UNRELEASED; urgency=low * The meta plugin now allows for the robots tag to be specified without the risk of it being scrubbed. + [ Joey Hess ] + * Add recentchangesdiff plugin that adds diffs to the recentchanges feeds. + * rcs_diff is a new function that rcs modules should implement. + * Implemented rcs_diff for git, svn, and tla (tla version untested). + Mercurial and monotone still todo. + -- martin f. krafft Sun, 02 Mar 2008 17:46:38 +0100 ikiwiki (2.40) unstable; urgency=low diff --git a/doc/plugins/recentchangesdiff.mdwn b/doc/plugins/recentchangesdiff.mdwn new file mode 100644 index 000000000..f805eabe1 --- /dev/null +++ b/doc/plugins/recentchangesdiff.mdwn @@ -0,0 +1,6 @@ +[[template id=plugin name=recentchangesdiff core=0 author="[[Joey]]"]] + +This plugin extends the [[recentchanges]] plugin, adding a diff for each +change. The diffs are by default hidden from display on the recentchanges +page, but will display in its feeds. The [[rcs]] must have implemented +support for the `rcs_diff()` function for any diffs to be generated. diff --git a/doc/style.css b/doc/style.css index 026d2c881..f9a69c4f1 100644 --- a/doc/style.css +++ b/doc/style.css @@ -92,6 +92,9 @@ div.recentchanges { .recentchanges .desc { display: none; } +.recentchanges .diff { + display: none; +} .recentchanges .committer { float: left; margin: 0; diff --git a/po/ikiwiki.pot b/po/ikiwiki.pot index 8be9e2734..4a1c32053 100644 --- a/po/ikiwiki.pot +++ b/po/ikiwiki.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2008-02-24 16:02-0500\n" +"POT-Creation-Date: 2008-03-03 15:41-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -508,7 +508,7 @@ msgstr "" msgid "(not toggleable in preview mode)" msgstr "" -#: ../IkiWiki/Rcs/Stub.pm:62 +#: ../IkiWiki/Rcs/Stub.pm:68 msgid "getctime not implemented" msgstr "" diff --git a/templates/change.tmpl b/templates/change.tmpl index e476a7439..55aabe201 100644 --- a/templates/change.tmpl +++ b/templates/change.tmpl @@ -33,4 +33,11 @@ + +
+
+
+
+
+