]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/darcs.pm
moved non-openid signin form into same page as openid selector; show/hide as buttons...
[ikiwiki.git] / IkiWiki / Plugin / darcs.pm
index 978457b2c5163c450add7fe3d0c7d2be91679982..f17fadcb10ef5a66b5530ae6d65d41b175a186b7 100644 (file)
@@ -1,42 +1,4 @@
 #!/usr/bin/perl
-# Support for the darcs rcs, <URL:http://darcs.net/>.
-# Copyright (C) 2006  Thomas Schwinge <tschwinge@gnu.org>
-#               2007  Benjamin A'Lee <bma@bmalee.eu>
-#                     Tuomo Valkonen <tuomov@iki.fi>
-#               2008  Simon Michael <simon@joyful.com>
-#                     Petr Ročkai <me@mornfall.net>
-#                     Sven M. Hallberg <pesco@khjk.org>
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation; either version 2 of the License, or (at your
-# option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-
-# History (see http://ikiwiki.info/todo/darcs/):
-#
-#  * Thomas Schwinge wrote the original file, implementing only rcs_commit.
-#  * Benjamin A'Lee contributed an alternative implementation.
-#  * Tuomo Valkonen contributed rcs_getctime and stub rcs_recentchanges.
-#  * Simon Michael contributed multiple changes.
-#  * Petr Ročkai fixed rcs_recentchanges and added caching to rcs_getctime.
-#  * Sven M. Hallberg merged the above and added missing features.
-
-
-# We're guaranteed to be the only instance of ikiwiki running at a given
-# time.  It is essential that only ikiwiki is working on a particular
-# repository.  That means one instance of ikiwiki and it also means that
-# you must not 'darcs push' into this repository, as this might create
-# race conditions, as I understand it.
-
 package IkiWiki::Plugin::darcs;
 
 use warnings;
@@ -56,6 +18,7 @@ sub import {
        hook(type => "rcs", id => "rcs_recentchanges", call => \&rcs_recentchanges);
        hook(type => "rcs", id => "rcs_diff", call => \&rcs_diff);
        hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime);
+       hook(type => "rcs", id => "rcs_getmtime", call => \&rcs_getmtime);
 }
 
 sub silentsystem (@) {
@@ -89,7 +52,7 @@ sub darcs_info ($$$) {
        return $_;
 }
 
-sub file_in_vc($$) {
+sub file_in_vc ($$) {
        my $repodir = shift;
        my $file = shift;
 
@@ -100,23 +63,23 @@ sub file_in_vc($$) {
        }
        my $found=0;
        while (<DARCS_MANIFEST>) {
-               $found = 1, last if /^(\.\/)?$file$/;
+               $found = 1 if /^(\.\/)?$file$/;
        }
        close(DARCS_MANIFEST) or error("'darcs query manifest' exited " . $?);
 
        return $found;
 }
 
-sub darcs_rev($) {
+sub darcs_rev ($) {
        my $file = shift; # Relative to the repodir.
        my $repodir = $config{srcdir};
 
-       return "" if (! file_in_vc($repodir, $file));
+       return "" unless file_in_vc($repodir, $file);
        my $hash = darcs_info('hash', $repodir, $file);
        return defined $hash ? $hash : "";
 }
 
-sub checkconfig() {
+sub checkconfig () {
        if (defined $config{darcs_wrapper} && length $config{darcs_wrapper}) {
                push @{$config{wrappers}}, {
                        wrapper => $config{darcs_wrapper},
@@ -125,11 +88,12 @@ sub checkconfig() {
        }
 }
 
-sub getsetup() {
+sub getsetup () {
        return
                plugin => {
                        safe => 0, # rcs plugin
                        rebuild => undef,
+                       section => "rcs",
                },
                darcs_wrapper => {
                        type => "string",
@@ -243,7 +207,7 @@ sub rcs_commit ($$$;$$) {
        # Update the repository by pulling from the default repository, which is
        # master repository.
        silentsystem('darcs', "pull", "--quiet", "--repodir", $config{srcdir},
-               "--all") !=0 || error("'darcs pull' failed");
+               "--all") == 0 || error("'darcs pull' failed");
 
        # If this updating yields any conflicts, we'll record them now to resolve
        # them.  If nothing is recorded, there are no conflicts.
@@ -275,7 +239,7 @@ sub rcs_commit ($$$;$$) {
        }
 }
 
-sub rcs_commit_staged($$$) {
+sub rcs_commit_staged ($$$) {
        my ($message, $user, $ipaddr) = @_;
 
        my $author;
@@ -336,8 +300,6 @@ sub rcs_recentchanges ($) {
 
        my $repodir=$config{srcdir};
 
-       debug("darcs recent changes: $num");
-
        my $child = open(LOG, "-|");
        if (! $child) {
                $ENV{"DARCS_DONT_ESCAPE_ANYTHING"}=1;
@@ -353,15 +315,14 @@ sub rcs_recentchanges ($) {
 
        my $log = XMLin($data, ForceArray => 1);
 
-       debug("parsing recent changes...");
        foreach my $patch (@{$log->{patch}}) {
                my $date=$patch->{local_date};
                my $hash=$patch->{hash};
                my $when=str2time($date);
                my (@pages, @files, @pg);
-               push @pages, $_ for (@{$patch->{summary}->[0]->{modify_file}});
-               push @pages, $_ for (@{$patch->{summary}->[0]->{add_file}});
-               push @pages, $_ for (@{$patch->{summary}->[0]->{remove_file}});
+               push @pages, $_ foreach (@{$patch->{summary}->[0]->{modify_file}});
+               push @pages, $_ foreach (@{$patch->{summary}->[0]->{add_file}});
+               push @pages, $_ foreach (@{$patch->{summary}->[0]->{remove_file}});
                foreach my $f (@pages) {
                        $f = $f->{content} if ref $f;
                        $f =~ s,^\s+,,; $f =~ s,\s+$,,; # cut whitespace
@@ -377,31 +338,30 @@ sub rcs_recentchanges ($) {
                        $d =~ s/\[\[file\]\]/$f/go;
                        $d =~ s/\[\[hash\]\]/$hash/go;
 
-                       debug("file: $f");
-                       debug("diffurl: $d");
                        push @pg, {
                                page => pagename($f),
                                diffurl => $d,
                        };
                }
                next unless (scalar @pg > 0);
-               debug("recent change: " . $patch->{name}[0] . " ("
-                       . scalar @pg . " changes)");
 
                my @message;
                push @message, { line => $_ } foreach (@{$patch->{name}});
 
                my $committype;
-               if ($patch->{author} =~ /\@web$/) {
+               my $author;
+               if ($patch->{author} =~ /(.*)\@web$/) {
+                       $author = $1;
                        $committype = "web";
                }
                else {
+                       $author=$patch->{author};
                        $committype = "darcs";
                }
 
                push @ret, {
                        rev => $patch->{hash},
-                       user => $patch->{author},
+                       user => $author,
                        committype => $committype,
                        when => $when, 
                        message => [@message],
@@ -435,16 +395,13 @@ sub rcs_getctime ($) {
        eval q{use XML::Simple};
        local $/=undef;
 
-       # Sigh... doing things the hard way again
-       my $repodir=$config{srcdir};
-
-       my $filer=substr($file, length($repodir));
+       my $filer=substr($file, length($config{srcdir}));
        $filer =~ s:^[/]+::;
 
        my $child = open(LOG, "-|");
        if (! $child) {
                exec("darcs", "changes", "--xml", "--reverse",
-                       "--repodir", "$repodir", "$filer")
+                       "--repodir", $config{srcdir}, $filer)
                || error("'darcs changes $filer' failed to run");
        }
 
@@ -471,4 +428,8 @@ sub rcs_getctime ($) {
        return $date;
 }
 
+sub rcs_getmtime ($) {
+       error "rcs_getmtime is not implemented for darcs\n"; # TODO
+}
+
 1