From: joey Date: Wed, 6 Sep 2006 20:31:55 +0000 (+0000) Subject: * Add support for mercurial, contributed by Emanuele Aina. X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/commitdiff_plain/f7f3b0bb7d91c74f67023e970cee71ad2ea260da?ds=sidebyside * Add support for mercurial, contributed by Emanuele Aina. --- diff --git a/IkiWiki/Rcs/mercurial.pm b/IkiWiki/Rcs/mercurial.pm new file mode 100644 index 000000000..82a2fa642 --- /dev/null +++ b/IkiWiki/Rcs/mercurial.pm @@ -0,0 +1,143 @@ +#!/usr/bin/perl + +use warnings; +use strict; +use IkiWiki; +use Encode; +use open qw{:utf8 :std}; + +package IkiWiki; + +sub mercurial_log($) { + my $out = shift; + my @infos; + + while (<$out>) { + my $line = $_; + my ($key, $value); + + if (/^description:/) { + $key = "description"; + $value = ""; + + # slurp everything as the description text + # until the next changeset + while (<$out>) { + if (/^changeset: /) { + $line = $_; + last; + } + + $value .= $_; + } + + local $/ = ""; + chomp $value; + $infos[$#infos]{$key} = $value; + } + + chomp $line; + ($key, $value) = split /: +/, $line, 2; + + if ($key eq "changeset") { + push @infos, {}; + + # remove the revision index, which is strictly + # local to the repository + $value =~ s/^\d+://; + } + + $infos[$#infos]{$key} = $value; + } + close $out; + + return @infos; +} + +sub rcs_update () { #{{{ + my @cmdline = ("hg", "-R", "$config{srcdir}", "update"); + if (system(@cmdline) != 0) { + warn "'@cmdline' failed: $!"; + } +} #}}} + +sub rcs_prepedit ($) { #{{{ + return ""; +} #}}} + +sub rcs_commit ($$$) { #{{{ + my ($file, $message, $rcstoken) = @_; + + $message = possibly_foolish_untaint($message); + + my @cmdline = ("hg", "-R", "$config{srcdir}", "commit", "-m", "$message"); + if (system(@cmdline) != 0) { + warn "'@cmdline' failed: $!"; + } + + return undef; # success +} #}}} + +sub rcs_add ($) { # {{{ + my ($file) = @_; + + my @cmdline = ("hg", "-R", "$config{srcdir}", "add", "$file"); + if (system(@cmdline) != 0) { + warn "'@cmdline' failed: $!"; + } +} #}}} + +sub rcs_recentchanges ($) { #{{{ + my ($num) = @_; + + eval q{use CGI 'escapeHTML'}; + + my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v", "-l", $num); + open (my $out, "@cmdline |"); + + my @ret; + foreach my $info (mercurial_log($out)) { + my @pages = (); + my @message = (); + + foreach my $msgline (split(/\n/, $info->{description})) { + push @message, { line => $msgline }; + } + + foreach my $file (split / /,$info->{files}) { + my $diffurl = $config{'diffurl'}; + $diffurl =~ s/\[\[file\]\]/$file/go; + $diffurl =~ s/\[\[r2\]\]/$info->{changeset}/go; + + push @pages, { + page => pagename($file), + diffurl => $diffurl, + }; + } + + my $user = $info->{"user"}; + $user =~ s/\s*<.*>\s*$//; + $user =~ s/^\s*//; + + push @ret, { + rev => $info->{"changeset"}, + user => $user, + committype => "mercurial", + when => $info->{"date"}, + message => [@message], + pages => [@pages], + }; + } + + return @ret; +} #}}} + +sub rcs_notify () { #{{{ + # TODO +} #}}} + +sub rcs_getctime ($) { #{{{ + error "getctime not implemented"; +} #}}} + +1 diff --git a/debian/changelog b/debian/changelog index 99932e007..8f9bfe2ec 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,8 +5,9 @@ ikiwiki (1.25) UNRELEASED; urgency=low * Drop real uid/gid in the suid wrapper, thus allowing commits to remote subversion repos and fixing some other issues. * Add support for tla, contributed by Clint Adams. Closes: #385936 + * Add support for mercurial, contributed by Emanuele Aina. - -- Joey Hess Wed, 6 Sep 2006 15:47:25 -0400 + -- Joey Hess Wed, 6 Sep 2006 15:55:39 -0400 ikiwiki (1.24) unstable; urgency=low diff --git a/debian/control b/debian/control index 2b8bdbb32..05ea1bcf5 100644 --- a/debian/control +++ b/debian/control @@ -9,13 +9,13 @@ Standards-Version: 3.7.2 Package: ikiwiki Architecture: all Depends: ${perl:Depends}, libxml-simple-perl, markdown, libtimedate-perl, libhtml-template-perl, libhtml-scrubber-perl, libcgi-formbuilder-perl (>= 3.02.02), libtime-duration-perl, libcgi-session-perl, libmail-sendmail-perl, gcc | c-compiler, libc6-dev | libc-dev, libhtml-parser-perl -Recommends: subversion | git-core | tla, hyperestraier +Recommends: subversion | git-core | tla | mercurual, hyperestraier Suggests: viewcvs, librpc-xml-perl, libtext-wikiformat-perl, python-docutils, polygen, tidy, libxml-feed-perl, libmailtools-perl Description: a wiki compiler ikiwiki converts a directory full of wiki pages into html pages suitable for publishing on a website. Unlike many wikis, ikiwiki does not have its - own means of storing page history. Instead it can use Subversion (or - Git or tla). + own means of storing page history, and instead uses a revision control + system (such as Subversion). . ikiwiki implements all of the other standard features of a wiki, including web-based page editing, user registration and logins, a RecentChanges diff --git a/doc/about_rcs_backends.mdwn b/doc/about_rcs_backends.mdwn index 0a95b7f54..95d641e72 100644 --- a/doc/about_rcs_backends.mdwn +++ b/doc/about_rcs_backends.mdwn @@ -117,8 +117,33 @@ part). GIT doesn't have a similar functionality like 'svn merge -rOLD:NEW FILE' (please see the relevant comment in mergepast for more details), so I had to invent an ugly hack just for the purpose. -## [mercurial](http://www.selenic.com/mercurial/) +## [Mercurial](http://www.selenic.com/mercurial/) -Being worked on by Emanuele Aina. +The Mercurial backend is still in a early phase, so it may not be mature +enough, but it should be simple to understand and use. - +As Mercurial is a distributed RCS, it lacks the distinction between +repository and working copy (every wc is a repo). + +This means that the Mercurial backend uses directly the repository as +working copy (the master M and the working copy W described in the svn +example are the same thing). + +You only need to specify 'srcdir' (the repository M) and 'destdir' (where +the HTML will be generated). + +Master repository M. + +RCS commit from the outside are installed into M. + +M is directly used as working copy (M is also W). + +HTML is generated from the working copy in M. rcs_update() will update +to the last committed revision in M (the same as 'hg update'). +If you use an 'update' hook you can generate automatically the HTML +in the destination directory each time 'hg update' is called. + +CGI operates on M. rcs_commit() will commit directly in M. + +If you have any question or suggestion about the Mercurial backend +please refer to [Emanuele](http://nerd.ocracy.org/em/). diff --git a/doc/features.mdwn b/doc/features.mdwn index d5fa4026b..c568213bf 100644 --- a/doc/features.mdwn +++ b/doc/features.mdwn @@ -4,18 +4,18 @@ An overview of some of ikiwiki's features: ## Uses a real RCS Rather than implement its own system for storing page histories etc, -ikiwiki uses a real RCS. This isn't because we're lazy, it's because a -real RCS is a good thing to have, and there are advantages to using one -that are not possible with a standard wiki. +ikiwiki uses a real Revision Control System. This isn't because we're +lazy, it's because a real RCS is a good thing to have, and there are +advantages to using one that are not possible with a standard wiki. Instead of editing pages in a stupid web form, you can use vim and commit -changes via svn. Or work disconnected using svk and push your changes out -when you come online. Or use git or tla to work in a distributed fashion -all the time. (It's also possible to [[plugins/write]] a plugin to support -other systems.) +changes via [[Subversion]]. Or work disconnected using svk and push your +changes out when you come online. Or use [[git]], [[tla]], or [[mercurial]] +to work in a distributed fashion all the time. (It's also possible to +[[plugins/write]] a plugin to support other systems.) ikiwiki can be run from a [[post-commit]] hook to update your wiki -immediately whenever you commit. +immediately whenever you commit a change using the RCS. Note that ikiwiki does not require a RCS to function. If you want to run a simple wiki without page history, it can do that too. diff --git a/doc/ikiwiki.setup b/doc/ikiwiki.setup index 95d2d46af..ac84352df 100644 --- a/doc/ikiwiki.setup +++ b/doc/ikiwiki.setup @@ -35,6 +35,11 @@ use IkiWiki::Setup::Standard { #historyurl => ??, #diffurl => ??, + # Mercurial stuff. + #rcs => "mercurial", + #historyurl => "http://localhost:8000/", # hg serve'd local repository + #diffurl => "http://localhost:8000/?fd=[[changeset]];file=[[file]]", + wrappers => [ #{ # # The cgi wrapper. diff --git a/doc/index.mdwn b/doc/index.mdwn index 67f099210..2dd90247c 100644 --- a/doc/index.mdwn +++ b/doc/index.mdwn @@ -1,8 +1,8 @@ [[ikiwiki_logo|logo/ikiwiki.png]] ikiwiki is a **wiki compiler**. It converts wiki pages into html pages suitable for publishing on a website. Unlike a traditional -wiki, ikiwiki does not have its own means of storing page history. -Instead it can use [[Subversion]] (or [[Git]] or [[tla]]). +wiki, ikiwiki does not have its own means of storing page history, +and instead uses a revision control system (such as [[Subversion]]). * [[News]] is a blog (built using ikiwiki) of news items about ikiwiki. It's the best way to find out when there's a new version to [[Download]]. diff --git a/doc/mercurial.mdwn b/doc/mercurial.mdwn new file mode 100644 index 000000000..5eaae1997 --- /dev/null +++ b/doc/mercurial.mdwn @@ -0,0 +1,8 @@ +[Mercurial](http://selenic.com/mercurial) is a distributed revison control +system developed by Matt Mackall. Ikiwiki supports storing a wiki in a +mercurial repository. + +Ikiwiki can run as a post-update hook to update a wiki whenever commits +come in. When running as a [[cgi]] with Mercurial, ikiwiki automatically +commits edited pages, and uses the Mercurial history to generate the +[[RecentChanges]] page. diff --git a/doc/post-commit.mdwn b/doc/post-commit.mdwn index 8def3d751..84375dad0 100644 --- a/doc/post-commit.mdwn +++ b/doc/post-commit.mdwn @@ -1,5 +1,5 @@ A post-commit hook is run every time you commit a change to your -[[subversion]] (or [[git]]) repository. To make the wiki be updated each +[[subversion]] (or [[git]] or [[mercurial]]) repository. To make the wiki be updated each time a commit is made, it can be run from (or as) a post-commit hook. The best way to run ikiwiki in a post-commit hook is using a wrapper, which diff --git a/doc/roadmap.mdwn b/doc/roadmap.mdwn index 4bd9ab671..a4b4919d4 100644 --- a/doc/roadmap.mdwn +++ b/doc/roadmap.mdwn @@ -22,9 +22,8 @@ Released 29 April 2006. possible)_ * Improved [[todo/html]] stylesheets and templates. * Improved scalable [[logo]]. _(status: done)_ -* Support for at least one RCS aside from svn. Once it supports two, it should - quickly grow to support them all.. See [[about_rcs_backends]] - _(status: supports git and tla in tree)_ +* Support for at other revision control systems aside from svn. + See [[about_rcs_backends]] _(status: supports git, tla, mercurial)_ * Support for one other markup language, probably restructured text. _(status: done, but the rst plugin needs improvement)_ * No serious known [[bugs]] diff --git a/doc/setup.mdwn b/doc/setup.mdwn index e2396f777..c6a8f297e 100644 --- a/doc/setup.mdwn +++ b/doc/setup.mdwn @@ -1,6 +1,6 @@ So you want to set up your own wiki using ikiwiki? This tutorial will walk -you through setting up a wiki that is stored in [[Subversion]], [[Git]], or -[[TLA]], and that has optional support for commits from the web. +you through setting up a wiki that is stored in [[Subversion]], [[Git]], +[[TLA]] or [[Mercurial]], and that has optional support for commits from the web. 1. [[Install]] ikiwiki. See [[download]] for where to get it. @@ -26,6 +26,9 @@ you through setting up a wiki that is stored in [[Subversion]], [[Git]], or # Edit {arch}/=tagging-method and change the precious # line to add the .ikiwiki directory to the regexp. + # Mercurial + hg init /hg/wikirepo + 3. Check out the repository to make the working copy that ikiwiki will use. # Subversion @@ -41,6 +44,12 @@ you through setting up a wiki that is stored in [[Subversion]], [[Git]], or tla init-tree me@localhost--wiki/wiki--0 tla import + # Mercurial + # Mercurial uses a single repo approach, so no need to + # clone anything. Because the following examples + # refer to the ~/wikiwc working copy we symlink it: + ln -s /hg/wikirepo ~/wikiwc + 4. Build your wiki for the first time. ikiwiki --verbose ~/wikiwc/ ~/public_html/wiki/ \ @@ -70,6 +79,10 @@ you through setting up a wiki that is stored in [[Subversion]], [[Git]], or tla add index.mdwn tla commit + # Mercurial + hg add index.mdwn + hg commit -m customised index.mdwn + You can also add any files you like from scratch of course. 6. Repeat steps 4 and 5 as desired, editing or adding pages and rebuilding @@ -92,12 +105,13 @@ you through setting up a wiki that is stored in [[Subversion]], [[Git]], or that all of these are pointing to the right directories, and read through and configure the rest of the file to your liking. - If you want to use git, comment out the subversion stuff, uncomment and - edit the git stuff. + If you want to use something other than subversion, comment out the + subversion configuration, and uncomment and edit the configuration for + your chosen RCS. Note that the default file has a block to configure an [[post-commit]] wrapper to update the wiki. You need to uncomment the related block for - whatever rcs you use and comment out the other rcs blocks. + whatever RCS you use and comment out the other rcs blocks. When you're satisfied, run `ikiwiki --setup ikiwiki.setup`, and it will set everything up and update your wiki. @@ -111,7 +125,7 @@ you through setting up a wiki that is stored in [[Subversion]], [[Git]], or 9. Add [[PageHistory]] links to the top of pages. This requires you to have setup a repository browser. For Subversion, you may use [[ViewCVS]] or something similar to access your [[Subversion]] repository. For Git, - [[Gitweb]] can be used. + [[Gitweb]] can be used, etc. The `historyurl` setting makes ikiwiki add the links, and in that url, "\[[file]]" is replaced with the name of the file to view. So edit diff --git a/doc/todo/mercurial.mdwn b/doc/todo/mercurial.mdwn new file mode 100644 index 000000000..e25039b13 --- /dev/null +++ b/doc/todo/mercurial.mdwn @@ -0,0 +1,4 @@ +* Need to get post commit hook working (or an example of how to use it.) +* Need --ctime support. +* rcs_notify is not implemented +* Is the code sufficiently robust? It just warns when mercurial fails. diff --git a/doc/usage.mdwn b/doc/usage.mdwn index 4456e8c1c..0c7e7d036 100644 --- a/doc/usage.mdwn +++ b/doc/usage.mdwn @@ -120,6 +120,11 @@ configuration options of their own. If you use git, the `source` directory is assumed to be a clone of the [[git]] repository. + If you use tla, the `source` directory is assumed to be a tla import. + + If you use mercurial, the `source` directory is assumed to be the + [[mercurial]] repository. + In [[CGI]] mode, with a revision control system enabled pages edited via the web will be committed. Also, the [[RecentChanges]] link will be placed on pages.