9 use open qw{:utf8 :std};
11 hook(type => "checkconfig", id => "mercurial", call => sub { #{{{
12 if (! defined $config{diffurl}) {
15 if (length $config{mercurial_wrapper}) {
16 push @{$config{wrappers}}, {
17 wrapper => $config{mercurial_wrapper},
18 wrappermode => (defined $config{mercurial_wrappermode} ? $config{mercurial_wrappermode} : "06755"),
23 hook(type => "getsetup", id => "mercurial", call => sub { #{{{
25 mercurial_wrapper => {
27 #example => # FIXME add example
28 description => "mercurial post-commit executable to generate",
32 mercurial_wrappermode => {
35 description => "mode for mercurial_wrapper (can safely be made suid)",
41 example => "http://example.com:8000/log/tip/[[file]]",
42 description => "url to hg serve'd repository, to show file history ([[file]] substituted)",
48 example => "http://localhost:8000/?fd=[[r2]];file=[[file]]",
49 description => "url to hg serve'd repository, to show diff ([[file]] and [[r2]] substituted)",
55 sub mercurial_log ($) { #{{{
63 if (/^description:/) {
67 # slurp everything as the description text
68 # until the next changeset
80 $infos[$#infos]{$key} = $value;
84 ($key, $value) = split /: +/, $line, 2;
86 if ($key eq "changeset") {
89 # remove the revision index, which is strictly
90 # local to the repository
94 $infos[$#infos]{$key} = $value;
101 sub rcs_update () { #{{{
102 my @cmdline = ("hg", "-q", "-R", "$config{srcdir}", "update");
103 if (system(@cmdline) != 0) {
104 warn "'@cmdline' failed: $!";
108 sub rcs_prepedit ($) { #{{{
112 sub rcs_commit ($$$;$$) { #{{{
113 my ($file, $message, $rcstoken, $user, $ipaddr) = @_;
116 $user = possibly_foolish_untaint($user);
118 elsif (defined $ipaddr) {
119 $user = "Anonymous from ".possibly_foolish_untaint($ipaddr);
125 $message = possibly_foolish_untaint($message);
126 if (! length $message) {
127 $message = "no message given";
130 my @cmdline = ("hg", "-q", "-R", $config{srcdir}, "commit",
131 "-m", $message, "-u", $user);
132 if (system(@cmdline) != 0) {
133 warn "'@cmdline' failed: $!";
136 return undef; # success
139 sub rcs_commit_staged ($$$) {
140 # Commits all staged changes. Changes can be staged using rcs_add,
141 # rcs_remove, and rcs_rename.
142 my ($message, $user, $ipaddr)=@_;
144 error("rcs_commit_staged not implemented for mercurial"); # TODO
147 sub rcs_add ($) { # {{{
150 my @cmdline = ("hg", "-q", "-R", "$config{srcdir}", "add", "$config{srcdir}/$file");
151 if (system(@cmdline) != 0) {
152 warn "'@cmdline' failed: $!";
156 sub rcs_remove ($) { # {{{
159 error("rcs_remove not implemented for mercurial"); # TODO
162 sub rcs_rename ($$) { # {{{
163 my ($src, $dest) = @_;
165 error("rcs_rename not implemented for mercurial"); # TODO
168 sub rcs_recentchanges ($) { #{{{
171 my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v", "-l", $num,
172 "--style", "default");
173 open (my $out, "@cmdline |");
175 eval q{use Date::Parse};
179 foreach my $info (mercurial_log($out)) {
183 foreach my $msgline (split(/\n/, $info->{description})) {
184 push @message, { line => $msgline };
187 foreach my $file (split / /,$info->{files}) {
188 my $diffurl = $config{'diffurl'};
189 $diffurl =~ s/\[\[file\]\]/$file/go;
190 $diffurl =~ s/\[\[r2\]\]/$info->{changeset}/go;
193 page => pagename($file),
198 my $user = $info->{"user"};
199 $user =~ s/\s*<.*>\s*$//;
203 rev => $info->{"changeset"},
205 committype => "mercurial",
206 when => str2time($info->{"date"}),
207 message => [@message],
215 sub rcs_diff ($) { #{{{
219 sub rcs_getctime ($) { #{{{
222 # XXX filename passes through the shell here, should try to avoid
224 my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v", "-l", '1',
225 "--style", "default", "$config{srcdir}/$file");
226 open (my $out, "@cmdline |");
228 my @log = mercurial_log($out);
230 if (length @log < 1) {
234 eval q{use Date::Parse};
237 my $ctime = str2time($log[0]->{"date"});