View difference between Paste ID: AcDHjbK6 and
SHOW: | | - or go back to the newest paste.
1-
1+
diff -r b08179653c00 IkiWiki.pm
2
--- a/IkiWiki.pm	Wed Jul 20 16:56:09 2011 +0200
3
+++ b/IkiWiki.pm	Wed Jul 20 19:28:21 2011 +0200
4
@@ -2059,6 +2059,10 @@
5
 	$hooks{rcs}{rcs_getmtime}{call}->(@_);
6
 }
7
 
8
+sub rcs_wrapper_postcall (@) {
9
+	$hooks{rcs}{rcs_wrapper_postcall}{call}->(@_);
10
+}
11
+
12
 sub rcs_receive () {
13
 	$hooks{rcs}{rcs_receive}{call}->();
14
 }
15
diff -r b08179653c00 IkiWiki/Plugin/mercurial.pm
16
--- a/IkiWiki/Plugin/mercurial.pm	Wed Jul 20 16:56:09 2011 +0200
17
+++ b/IkiWiki/Plugin/mercurial.pm	Wed Jul 20 19:28:21 2011 +0200
18
@@ -21,6 +21,7 @@
19
 	hook(type => "rcs", id => "rcs_diff", call => \&rcs_diff);
20
 	hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime);
21
 	hook(type => "rcs", id => "rcs_getmtime", call => \&rcs_getmtime);
22
+	hook(type => "rcs", id => "rcs_wrapper_postcall", call => \&rcs_wrapper_postcall);
23
 }
24
 
25
 sub checkconfig () {
26
@@ -28,6 +29,7 @@
27
 		push @{$config{wrappers}}, {
28
 			wrapper => $config{mercurial_wrapper},
29
 			wrappermode => (defined $config{mercurial_wrappermode} ? $config{mercurial_wrappermode} : "06755"),
30
+			wrapper_postcall => (defined $config{mercurial_wrapper_hgrc_update} ? $config{mercurial_wrapper_hgrc_update} : "1"),
31
 		};
32
 	}
33
 }
34
@@ -53,6 +55,13 @@
35
 			safe => 0,
36
 			rebuild => 0,
37
 		},
38
+		mercurial_wrapper_hgrc_update => {
39
+			type => "string",
40
+			example => "1",
41
+			description => "updates existing hgrc to reflect path changes for mercurial_wrapper",
42
+			safe => 0,
43
+			rebuild => 0,
44
+		},
45
 		historyurl => {
46
 			type => "string",
47
 			example => "http://example.com:8000/log/tip/[[file]]",
48
@@ -402,4 +411,23 @@
49
 	return findtimes($file, 0);
50
 }
51
 
52
+sub rcs_wrapper_postcall($) {
53
+	# Update hgrc if it exists. Change post-commit/incoming hooks with the
54
+	# .ikiwiki suffix to point to the wrapper path given in the setup file.
55
+	# Work with a tempfile to not delete hgrc if the loop is interrupted
56
+	# midway.
57
+	my $hgrc=$config{srcdir}.'/.hg/hgrc';
58
+	my $backup_suffix='.ikiwiki.bak';
59
+	if (-e $hgrc) {
60
+		use File::Spec;
61
+		my $mercurial_wrapper_abspath=File::Spec->rel2abs($config{mercurial_wrapper}, $config{srcdir});
62
+		local ($^I, @ARGV)=($backup_suffix, $hgrc);
63
+		while (<>) {
64
+			s/^(post-commit|incoming)(\.ikiwiki[ \t]*=[ \t]*).*$/$1$2$mercurial_wrapper_abspath/;
65
+			print;
66
+		}
67
+		unlink($hgrc.$backup_suffix);
68
+	}
69
+}
70
+
71
 1
72
diff -r b08179653c00 IkiWiki/Setup/Automator.pm
73
--- a/IkiWiki/Setup/Automator.pm	Wed Jul 20 16:56:09 2011 +0200
74
+++ b/IkiWiki/Setup/Automator.pm	Wed Jul 20 19:28:21 2011 +0200
75
@@ -75,8 +75,7 @@
76
 			print STDERR "warning: do not know how to set up the bzr_wrapper hook!\n";
77
 		}
78
 		elsif ($config{rcs} eq 'mercurial') {
79
-			# TODO
80
-			print STDERR "warning: do not know how to set up the mercurial_wrapper hook!\n";
81
+			$config{mercurial_wrapper}=$config{srcdir}."/.hg/ikiwiki-wrapper";
82
 		}
83
 		elsif ($config{rcs} eq 'tla') {
84
 			# TODO
85
@@ -182,6 +181,19 @@
86
 		}
87
 	}
88
 	
89
+	# Setup initial config file for Mercurial to hook up the wrapper. The
90
+	# path to the wrapper will be automatically added when it is generated.
91
+	if ($config{rcs} eq 'mercurial' && exists $config{mercurial_wrapper}
92
+		&& length $config{mercurial_wrapper}) {
93
+		open (HGRC, '>', $config{srcdir}.'/.hg/hgrc');
94
+		print HGRC <<EOF;
95
+[hooks]
96
+post-commit.ikiwiki = 
97
+incoming.ikiwiki = 
98
+EOF
99
+		close (HGRC);
100
+	}
101
+
102
 	# Add wrappers, make live.
103
 	if (system("ikiwiki", "--wrappers", "--setup", $config{dumpsetup}) != 0) {
104
 		die "ikiwiki --wrappers --setup $config{dumpsetup} failed";
105
diff -r b08179653c00 IkiWiki/Wrapper.pm
106
--- a/IkiWiki/Wrapper.pm	Wed Jul 20 16:56:09 2011 +0200
107
+++ b/IkiWiki/Wrapper.pm	Wed Jul 20 19:28:21 2011 +0200
108
@@ -238,6 +238,10 @@
109
 	}
110
 	#translators: The parameter is a filename.
111
 	debug(sprintf(gettext("successfully generated %s"), $wrapper));
112
+
113
+	if (defined $config{wrapper_postcall} && $config{wrapper_postcall} ) {
114
+		IkiWiki::rcs_wrapper_postcall();
115
+	}
116
 }
117
 
118
 1