use Encode;
use open qw{:utf8 :std};
-sub import { #{{{
+sub import {
hook(type => "checkconfig", id => "mercurial", call => \&checkconfig);
hook(type => "getsetup", id => "mercurial", call => \&getsetup);
hook(type => "rcs", id => "rcs_update", call => \&rcs_update);
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 checkconfig () { #{{{
+sub checkconfig () {
if (exists $config{mercurial_wrapper} && length $config{mercurial_wrapper}) {
push @{$config{wrappers}}, {
wrapper => $config{mercurial_wrapper},
wrappermode => (defined $config{mercurial_wrappermode} ? $config{mercurial_wrappermode} : "06755"),
};
}
-} #}}}
+}
-sub getsetup () { #{{{
+sub getsetup () {
return
plugin => {
safe => 0, # rcs plugin
rebuild => undef,
+ section => "rcs",
},
mercurial_wrapper => {
type => "string",
safe => 1,
rebuild => 1,
},
-} #}}}
+}
-sub mercurial_log ($) { #{{{
+sub mercurial_log ($) {
my $out = shift;
my @infos;
close $out;
return @infos;
-} #}}}
+}
-sub rcs_update () { #{{{
+sub rcs_update () {
my @cmdline = ("hg", "-q", "-R", "$config{srcdir}", "update");
if (system(@cmdline) != 0) {
warn "'@cmdline' failed: $!";
}
-} #}}}
+}
-sub rcs_prepedit ($) { #{{{
+sub rcs_prepedit ($) {
return "";
-} #}}}
+}
-sub rcs_commit ($$$;$$) { #{{{
- my ($file, $message, $rcstoken, $user, $ipaddr) = @_;
+sub rcs_commit (@) {
+ my %params=@_;
- if (defined $user) {
- $user = IkiWiki::possibly_foolish_untaint($user);
- }
- elsif (defined $ipaddr) {
- $user = "Anonymous from ".IkiWiki::possibly_foolish_untaint($ipaddr);
- }
- else {
- $user = "Anonymous";
+ my $user="Anonymous";
+ if (defined $params{session}) {
+ if (defined $params{session}->param("name")) {
+ $user = $params{session}->param("name");
+ }
+ elsif (defined $params{session}->remote_addr()) {
+ $user = "Anonymous from ".$params{session}->remote_addr();
+ }
}
- $message = IkiWiki::possibly_foolish_untaint($message);
- if (! length $message) {
- $message = "no message given";
+ if (! length $params{message}) {
+ $params{message} = "no message given";
}
my @cmdline = ("hg", "-q", "-R", $config{srcdir}, "commit",
- "-m", $message, "-u", $user);
+ "-m", IkiWiki::possibly_foolish_untaint($params{message}),
+ "-u", IkiWiki::possibly_foolish_untaint($user));
if (system(@cmdline) != 0) {
warn "'@cmdline' failed: $!";
}
return undef; # success
-} #}}}
+}
-sub rcs_commit_staged ($$$) {
+sub rcs_commit_staged (@) {
# Commits all staged changes. Changes can be staged using rcs_add,
# rcs_remove, and rcs_rename.
- my ($message, $user, $ipaddr)=@_;
+ my %params=@_;
error("rcs_commit_staged not implemented for mercurial"); # TODO
}
-sub rcs_add ($) { # {{{
+sub rcs_add ($) {
my ($file) = @_;
my @cmdline = ("hg", "-q", "-R", "$config{srcdir}", "add", "$config{srcdir}/$file");
if (system(@cmdline) != 0) {
warn "'@cmdline' failed: $!";
}
-} #}}}
+}
-sub rcs_remove ($) { # {{{
+sub rcs_remove ($) {
my ($file) = @_;
error("rcs_remove not implemented for mercurial"); # TODO
-} #}}}
+}
-sub rcs_rename ($$) { # {{{
+sub rcs_rename ($$) {
my ($src, $dest) = @_;
error("rcs_rename not implemented for mercurial"); # TODO
-} #}}}
+}
-sub rcs_recentchanges ($) { #{{{
+sub rcs_recentchanges ($) {
my ($num) = @_;
my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v", "-l", $num,
push @ret, {
rev => $info->{"changeset"},
user => $user,
- committype => "mercurial",
+ committype => "hg",
when => str2time($info->{"date"}),
message => [@message],
pages => [@pages],
}
return @ret;
-} #}}}
+}
-sub rcs_diff ($) { #{{{
+sub rcs_diff ($;$) {
# TODO
-} #}}}
+}
-sub rcs_getctime ($) { #{{{
+sub rcs_getctime ($) {
my ($file) = @_;
- # XXX filename passes through the shell here, should try to avoid
- # that just in case
- my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v", "-l", '1',
+ my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v",
"--style", "default", "$config{srcdir}/$file");
- open (my $out, "@cmdline |");
+ open (my $out, "-|", @cmdline);
- my @log = mercurial_log($out);
+ my @log = (mercurial_log($out));
- if (length @log < 1) {
+ if (@log < 1) {
return 0;
}
eval q{use Date::Parse};
error($@) if $@;
- my $ctime = str2time($log[0]->{"date"});
+ my $ctime = str2time($log[$#log]->{"date"});
return $ctime;
-} #}}}
+}
+
+sub rcs_getmtime ($) {
+ error "rcs_getmtime is not implemented for mercurial\n"; # TODO
+}
1