Attempt to fix a `TODO` in `Automator.pm` in combination with the Mercurial backend.
1. To define hooks, Mercurial uses paths given in the config file `.hg/hgrc`. To enable Mercurial to call `ikiwiki-wrapper` automatically after blog/wiki setup, ikiwiki thus needs to create `hgrc`.
2. To reflect changes in `$config{srcdir}` and/or `$config{mercurial_wrapper}`, relevant lines in `hgrc` need to be updated on wrapper creation.
ikiwiki can keep track of lines in `hgrc` for which it is responsible by adding a `.ikiwiki` suffix to its hooks. This is correct and recommended markup, Mercurial-wise.
Two ways follow below. I prefer the long one. --[[Daniel Andersson]]
2011-07-26 17:43:44 +02:00
> I comment myself: this can probably be solved without adding ad-hoc hooks and stuff (maybe not as "correct" as changing the config file only directly after wrappers have been generated, but good enough). I have a large rewrite of `mercurial.pm` ready, currently under local testing before I upload it for comments, trying to make it equal in function to `git.pm`. Comments below are of course welcome, but I will look into other ways of solving it later. Maybe `rcs_checkconfig` or `rcs_genwrapper` should host the `hgrc`-changing code. --[[Daniel Andersson]]
2011-07-26 14:36:27 +02:00
2011-07-20 19:53:11 +02:00
Compact way (addresses only point 1)
------------------------------------
[This patch at pastebin](http://pastebin.com/by9f4dwX) ([raw version](http://pastebin.com/raw.php?i=by9f4dwX)).
Create `$config{srcdir}/.hg/hgrc` with hook info during auto-installation script. Use relative paths to not require manual `hgrc` intervention if `$config{srcdir}` is changed. If `$config{mercurial_wrapper}` is changed, manual edit of `hgrc` is needed to catch the new wrapper path.
(Is there a security risk with relative paths?)
@@ -187,6 +186,22 @@
die "ikiwiki --wrappers --setup $config{dumpsetup} failed";
}
+ # Setup initial config file for Mercurial to hook up the wrapper.
+ if ($config{rcs} eq 'mercurial' && exists $config{mercurial_wrapper}
+ && length $config{mercurial_wrapper}) {
+ # Use a relative path to avoid having to manually change the
+ # autogenerated hgrc if the user changes $config{srcdir}.
+ use File::Spec;
+ my $mercurial_wrapper_relpath=File::Spec->abs2rel($config{mercurial_wrapper}, $config{srcdir});
+ open (HGRC, '>', $config{srcdir}.'/.hg/hgrc');
+ print HGRC <<EOF;
+[hooks]
+post-commit.ikiwiki = $mercurial_wrapper_relpath
+incoming.ikiwiki = $mercurial_wrapper_relpath
+EOF
+ close (HGRC);
+ }
+
# Add it to the wikilist.
mkpath("$ENV{HOME}/.ikiwiki");
open (WIKILIST, ">>$ENV{HOME}/.ikiwiki/wikilist") || die "$ENV{HOME}/.ikiwiki/wikilist: $!";
Less compact but more robust way (addresses point 1 and 2)
[This complete patch at pastebin](http://pastebin.com/AcDHjbK6) ([raw version](http://pastebin.com/raw.php?i=AcDHjbK6)).
This way leaks onto additional files and adds general functionality that may or may not be wanted. The main part of the extra code is contained within `mercurial.pm`, though.
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);
+ hook(type => "rcs", id => "rcs_wrapper_postcall", call => \&rcs_wrapper_postcall);
}
sub checkconfig () {
Pass variable to `gen_wrapper()` to decide if `rcs_wrapper_postcall()` should run. Default is `1` to update `hgrc`, since it is done non-intrusive (won't create `hgrc` if it doesn't exist, won't overwrite anything unless it is set by ikiwiki itself).