9 use open qw{:utf8 :std};
11 hook(type => "getsetup", id => "mercurial", call => sub { #{{{
16 example => "http://example.com:8000/log/tip/[[file]]",
17 description => "url to hg serve'd repository, to show file history ([[file]] substituted)",
24 example => "http://localhost:8000/?fd=[[r2]];file=[[file]]",
25 description => "url to hg serve'd repository, to show diff ([[file]] and [[r2]] substituted)",
31 sub mercurial_log ($) { #{{{
39 if (/^description:/) {
43 # slurp everything as the description text
44 # until the next changeset
56 $infos[$#infos]{$key} = $value;
60 ($key, $value) = split /: +/, $line, 2;
62 if ($key eq "changeset") {
65 # remove the revision index, which is strictly
66 # local to the repository
70 $infos[$#infos]{$key} = $value;
77 sub rcs_update () { #{{{
78 my @cmdline = ("hg", "-q", "-R", "$config{srcdir}", "update");
79 if (system(@cmdline) != 0) {
80 warn "'@cmdline' failed: $!";
84 sub rcs_prepedit ($) { #{{{
88 sub rcs_commit ($$$;$$) { #{{{
89 my ($file, $message, $rcstoken, $user, $ipaddr) = @_;
92 $user = possibly_foolish_untaint($user);
94 elsif (defined $ipaddr) {
95 $user = "Anonymous from ".possibly_foolish_untaint($ipaddr);
101 $message = possibly_foolish_untaint($message);
102 if (! length $message) {
103 $message = "no message given";
106 my @cmdline = ("hg", "-q", "-R", $config{srcdir}, "commit",
107 "-m", $message, "-u", $user);
108 if (system(@cmdline) != 0) {
109 warn "'@cmdline' failed: $!";
112 return undef; # success
115 sub rcs_commit_staged ($$$) {
116 # Commits all staged changes. Changes can be staged using rcs_add,
117 # rcs_remove, and rcs_rename.
118 my ($message, $user, $ipaddr)=@_;
120 error("rcs_commit_staged not implemented for mercurial"); # TODO
123 sub rcs_add ($) { # {{{
126 my @cmdline = ("hg", "-q", "-R", "$config{srcdir}", "add", "$config{srcdir}/$file");
127 if (system(@cmdline) != 0) {
128 warn "'@cmdline' failed: $!";
132 sub rcs_remove ($) { # {{{
135 error("rcs_remove not implemented for mercurial"); # TODO
138 sub rcs_rename ($$) { # {{{
139 my ($src, $dest) = @_;
141 error("rcs_rename not implemented for mercurial"); # TODO
144 sub rcs_recentchanges ($) { #{{{
147 my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v", "-l", $num,
148 "--style", "default");
149 open (my $out, "@cmdline |");
151 eval q{use Date::Parse};
155 foreach my $info (mercurial_log($out)) {
159 foreach my $msgline (split(/\n/, $info->{description})) {
160 push @message, { line => $msgline };
163 foreach my $file (split / /,$info->{files}) {
164 my $diffurl = $config{'diffurl'};
165 $diffurl =~ s/\[\[file\]\]/$file/go;
166 $diffurl =~ s/\[\[r2\]\]/$info->{changeset}/go;
169 page => pagename($file),
174 my $user = $info->{"user"};
175 $user =~ s/\s*<.*>\s*$//;
179 rev => $info->{"changeset"},
181 committype => "mercurial",
182 when => str2time($info->{"date"}),
183 message => [@message],
191 sub rcs_diff ($) { #{{{
195 sub rcs_getctime ($) { #{{{
198 # XXX filename passes through the shell here, should try to avoid
200 my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v", "-l", '1',
201 "--style", "default", "$config{srcdir}/$file");
202 open (my $out, "@cmdline |");
204 my @log = mercurial_log($out);
206 if (length @log < 1) {
210 eval q{use Date::Parse};
213 my $ctime = str2time($log[0]->{"date"});