Merge remote-tracking branch 'intrigeri/po'
authorJoey Hess <joey@kitenet.net>
Tue, 19 Jul 2011 18:11:36 +0000 (14:11 -0400)
committerJoey Hess <joey@kitenet.net>
Tue, 19 Jul 2011 18:11:36 +0000 (14:11 -0400)
14 files changed:
IkiWiki/Plugin/mercurial.pm
debian/changelog
doc/bugs/__33__inline_sort__61____34__meta__40__date__41____34___ignored.mdwn [new file with mode: 0644]
doc/forum/Have_creation_time_for_new_pages_fetched_from_the_VCS.mdwn [new file with mode: 0644]
doc/forum/Have_creation_time_for_new_pages_fetched_from_the_VCS/comment_1_9572dd6f7a2f6f630b12f24bb5c4a8ce._comment [new file with mode: 0644]
doc/news/version_3.20110431.mdwn [deleted file]
doc/news/version_3.20110715.mdwn [new file with mode: 0644]
doc/rcs.mdwn
doc/todo/Add_instructive_commit_messages_for_add__47__edit_pages.mdwn [new file with mode: 0644]
doc/todo/Add_instructive_commit_messages_for_removing_pages.mdwn [new file with mode: 0644]
doc/todo/Attempt_to_extend_Mercurial_backend_support.mdwn
doc/todo/po:_add_lang_name_and_code_template_variables.mdwn [new file with mode: 0644]
doc/todo/rcs__95__diff_implementation_for_Mercurial_backend__44___based_on_Git_backend.mdwn [new file with mode: 0644]
doc/todo/rcs__95__get__123__c__44__m__125__time_implementation_for_Mercurial_backend__44___based_on_Git_backend.mdwn [new file with mode: 0644]

index d7399eaf0be208730651cf55e9ba01b29979aede..102b4692b805024ec02dc78a7db09896436e3d2b 100644 (file)
@@ -69,6 +69,50 @@ sub getsetup () {
                },
 }
 
+sub safe_hg (&@) {
+       # Start a child process safely without resorting to /bin/sh.
+       # Returns command output (in list content) or success state
+       # (in scalar context), or runs the specified data handler.
+
+       my ($error_handler, $data_handler, @cmdline) = @_;
+
+       my $pid = open my $OUT, "-|";
+
+       error("Cannot fork: $!") if !defined $pid;
+
+       if (!$pid) {
+               # In child.
+               # hg commands want to be in wc.
+               chdir $config{srcdir}
+                   or error("cannot chdir to $config{srcdir}: $!");
+
+               exec @cmdline or error("Cannot exec '@cmdline': $!");
+       }
+       # In parent.
+
+       my @lines;
+       while (<$OUT>) {
+               chomp;
+
+               if (! defined $data_handler) {
+                       push @lines, $_;
+               }
+               else {
+                       last unless $data_handler->($_);
+               }
+       }
+
+       close $OUT;
+
+       $error_handler->("'@cmdline' failed: $!") if $? && $error_handler;
+
+       return wantarray ? @lines : ($? == 0);
+}
+# Convenient wrappers.
+sub run_or_die ($@) { safe_hg(\&error, undef, @_) }
+sub run_or_cry ($@) { safe_hg(sub { warn @_ }, undef, @_) }
+sub run_or_non ($@) { safe_hg(undef, undef, @_) }
+
 sub mercurial_log ($) {
        my $out = shift;
        my @infos;
@@ -116,10 +160,7 @@ sub mercurial_log ($) {
 }
 
 sub rcs_update () {
-       my @cmdline = ("hg", "-q", "-R", "$config{srcdir}", "update");
-       if (system(@cmdline) != 0) {
-               warn "'@cmdline' failed: $!";
-       }
+       run_or_cry('hg', '-q', 'update');
 }
 
 sub rcs_prepedit ($) {
@@ -129,62 +170,83 @@ sub rcs_prepedit ($) {
 sub rcs_commit (@) {
        my %params=@_;
 
+       return rcs_commit_helper(@_);
+}
+
+sub rcs_commit_helper (@) {
+       my %params=@_;
+
+       my %env=%ENV;
+       $ENV{HGENCODING} = 'utf-8';
+
        my $user="Anonymous";
+       my $nickname;
        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();
+                       $user = $params{session}->remote_addr();
+               }
+
+               if (defined $params{session}->param("nickname")) {
+                       $nickname=encode_utf8($params{session}->param("nickname"));
+                       $nickname=~s/\s+/_/g;
+                       $nickname=~s/[^-_0-9[:alnum:]]+//g;
                }
+               $ENV{HGUSER} = encode_utf8($user . ' <' . $nickname . '@web>');
        }
 
        if (! length $params{message}) {
                $params{message} = "no message given";
        }
 
-       my @cmdline = ("hg", "-q", "-R", $config{srcdir}, "commit", 
-                      "-m", IkiWiki::possibly_foolish_untaint($params{message}),
-                      "-u", IkiWiki::possibly_foolish_untaint($user));
-       if (system(@cmdline) != 0) {
-               warn "'@cmdline' failed: $!";
+       $params{message} = IkiWiki::possibly_foolish_untaint($params{message});
+
+       my @opts;
+
+       if (exists $params{file}) {
+               push @opts, '--', $params{file};
        }
+       # hg commit returns non-zero if nothing really changed.
+       # So we should ignore its exit status (hence run_or_non).
+       run_or_non('hg', 'commit', '-m', $params{message}, '-q', @opts);
 
+       %ENV=%env;
        return undef; # success
 }
 
 sub rcs_commit_staged (@) {
        # Commits all staged changes. Changes can be staged using rcs_add,
        # rcs_remove, and rcs_rename.
-       my %params=@_;
-       
-       error("rcs_commit_staged not implemented for mercurial"); # TODO
+       return rcs_commit_helper(@_);
 }
 
 sub rcs_add ($) {
        my ($file) = @_;
 
-       my @cmdline = ("hg", "-q", "-R", "$config{srcdir}", "add", "$config{srcdir}/$file");
-       if (system(@cmdline) != 0) {
-               warn "'@cmdline' failed: $!";
-       }
+       run_or_cry('hg', 'add', $file);
 }
 
 sub rcs_remove ($) {
+       # Remove file from archive.
        my ($file) = @_;
 
-       error("rcs_remove not implemented for mercurial"); # TODO
+       run_or_cry('hg', 'remove', '-f', $file);
 }
 
 sub rcs_rename ($$) {
        my ($src, $dest) = @_;
 
-       error("rcs_rename not implemented for mercurial"); # TODO
+       run_or_cry('hg', 'rename', '-f', $src, $dest);
 }
 
 sub rcs_recentchanges ($) {
        my ($num) = @_;
 
+       my %env=%ENV;
+       $ENV{HGENCODING} = 'utf-8';
+
        my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v", "-l", $num,
                "--style", "default");
        open (my $out, "@cmdline |");
@@ -196,7 +258,7 @@ sub rcs_recentchanges ($) {
        foreach my $info (mercurial_log($out)) {
                my @pages = ();
                my @message = ();
-        
+
                foreach my $msgline (split(/\n/, $info->{description})) {
                        push @message, { line => $msgline };
                }
@@ -212,49 +274,132 @@ sub rcs_recentchanges ($) {
                        };
                }
 
+               #"user <email@domain.net>": parse out "user".
                my $user = $info->{"user"};
                $user =~ s/\s*<.*>\s*$//;
                $user =~ s/^\s*//;
 
+               #"user <nickname@web>": if "@web" hits, set $web_commit=true.
+               my $web_commit = ($info->{'user'} =~ /\@web>/);
+
+               #"user <nickname@web>": if user is a URL (hits "://") and "@web"
+               #was present, parse out nick.
+               my $nickname;
+               if ($user =~ /:\/\// && $web_commit) {
+                       $nickname = $info->{'user'};
+                       $nickname =~ s/^[^<]*<([^\@]+)\@web>\s*$/$1/;
+               }
+
                push @ret, {
                        rev        => $info->{"changeset"},
                        user       => $user,
-                       committype => "hg",
+                       nickname   => $nickname,
+                       committype => $web_commit ? "web" : "hg",
                        when       => str2time($info->{"date"}),
                        message    => [@message],
                        pages      => [@pages],
                };
        }
 
+       %ENV=%env;
+
        return @ret;
 }
 
 sub rcs_diff ($;$) {
-       # TODO
+       my $rev=shift;
+       my $maxlines=shift;
+       my @lines;
+       my $addlines=sub {
+               my $line=shift;
+               return if defined $maxlines && @lines == $maxlines;
+               push @lines, $line."\n"
+                       if (@lines || $line=~/^diff --git/);
+               return 1;
+       };
+       safe_hg(undef, $addlines, "hg", "diff", "-c", $rev, "-g");
+       if (wantarray) {
+               return @lines;
+       }
+       else {
+               return join("", @lines);
+       }
 }
 
-sub rcs_getctime ($) {
-       my ($file) = @_;
+{
+my %time_cache;
+
+sub findtimes ($$) {
+       my $file=shift;
+       my $id=shift; # 0 = mtime ; 1 = ctime
+
+       if (! keys %time_cache) {
+               my $date;
+
+               # It doesn't seem possible to specify the format wanted for the
+               # changelog (same format as is generated in git.pm:findtimes(),
+               # though the date differs slightly) without using a style
+               # _file_. There is a "hg log" switch "--template" to directly
+               # control simple output formatting, but in this case, the
+               # {file} directive must be redefined, which can only be done
+               # with "--style".
+               #
+               # If {file} is not redefined, all files are output on a single
+               # line separated with a space. It is not possible to conclude
+               # if the space is part of a filename or just a separator, and
+               # thus impossible to use in this case.
+               # 
+               # Some output filters are available in hg, but they are not fit
+               # for this cause (and would slow down the process
+               # unnecessarily).
+               
+               eval q{use File::Temp};
+               error $@ if $@;
+               my ($tmpl_fh, $tmpl_filename) = File::Temp::tempfile(UNLINK => 1);
+               
+               print $tmpl_fh 'changeset = "{date}\\n{files}\\n"' . "\n";
+               print $tmpl_fh 'file = "{file}\\n"' . "\n";
+               
+               foreach my $line (run_or_die('hg', 'log', '--style', $tmpl_filename)) {
+                       # {date} gives output on the form
+                       # 1310694511.0-7200
+                       # where the first number is UTC Unix timestamp with one
+                       # decimal (decimal always 0, at least on my system)
+                       # followed by local timezone offset from UTC in
+                       # seconds.
+                       if (! defined $date && $line =~ /^\d+\.\d[+-]\d*$/) {
+                               $line =~ s/^(\d+).*/$1/;
+                               $date=$line;
+                       }
+                       elsif (! length $line) {
+                               $date=undef;
+                       }
+                       else {
+                               my $f=$line;
 
-       my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v",
-               "--style", "default", "$config{srcdir}/$file");
-       open (my $out, "-|", @cmdline);
+                               if (! $time_cache{$f}) {
+                                       $time_cache{$f}[0]=$date; # mtime
+                               }
+                               $time_cache{$f}[1]=$date; # ctime
+                       }
+               }
+       }
 
-       my @log = (mercurial_log($out));
+       return exists $time_cache{$file} ? $time_cache{$file}[$id] : 0;
+}
 
-       if (@log < 1) {
-               return 0;
-       }
+}
 
-       eval q{use Date::Parse};
-       error($@) if $@;
-       
-       my $ctime = str2time($log[$#log]->{"date"});
-       return $ctime;
+sub rcs_getctime ($) {
+       my $file = shift;
+
+       return findtimes($file, 1);
 }
 
 sub rcs_getmtime ($) {
-       error "rcs_getmtime is not implemented for mercurial\n"; # TODO
+       my $file = shift;
+
+       return findtimes($file, 0);
 }
 
 1
index 8e280f9c718f44567f5b0d74a59be045a84abb2b..6499a40b17fb747d6ea6232ed5aa782120cb7af2 100644 (file)
@@ -1,3 +1,16 @@
+ikiwiki (3.20110716) UNRELEASED; urgency=low
+
+  * mercurial: Openid nicknames are now used when committing. (Daniel Andersson)
+  * mercurial: Implement rcs_commit_staged so comments, attachments, etc
+    can be used. (Daniel Andersson)
+  * mercurial: Implement rcs_rename, rcs_remove. (Daniel Andersson)
+  * mercurial: Fix viewing of a diff containing non-utf8 changes.
+    (Daniel Andersson)
+  * mercurial: Make both rcs_getctime and rcs_getmtime fast. (Daniel Andersson)
+  * mercurial: Implement rcs_diff. (Daniel Andersson)
+
+ -- Joey Hess <joeyh@debian.org>  Tue, 19 Jul 2011 11:22:52 -0400
+
 ikiwiki (3.20110715) unstable; urgency=low
 
   * rename: Fix logic error that broke renaming pages when the attachment
diff --git a/doc/bugs/__33__inline_sort__61____34__meta__40__date__41____34___ignored.mdwn b/doc/bugs/__33__inline_sort__61____34__meta__40__date__41____34___ignored.mdwn
new file mode 100644 (file)
index 0000000..5eff90e
--- /dev/null
@@ -0,0 +1,39 @@
+I am trying to do an !inline and sort the pages after meta(date)
+
+       \[[!inline pages="blog/* and !*/Discussion" sort="meta(date)" show="0" rootpage="blog" archive="yes"]]
+
+There are a few pages inside blog/* and I would like to give the !meta line as example for two of them:
+
+page 1: blog/get_http.mdwn
+
+       \[[!meta title="HTTP GET method" date="2010-09-17 00:00:00"]]
+
+page 2: blog/nagios.mdwn
+
+       \[[!meta title="Nagios 3" date="2010-09-09 00:00:00"]]
+
+page 3: blog/using_macos.mdwn
+
+       \[[!meta title="How I am using Mac OS X" date="2010-06-10 00:00:00"]]
+
+The ordering which is created can be seen at <http://www.michael-hammer.at/blog_all> and is 
+
+page 1 -> page 3 -> page 2
+
+which is obviously not correct. I can say that the ordering is regardless of the sort="" argument inside !inline done by the ctime. This is really annoying as ctime is hard to recover if one has to move the blog from one machine to another.
+
+- What am I doing wrong? 
+- Is this a bug? If not: Why is meta(date) ignored?
+
+% ikiwiki --version
+
+ikiwiki version 3.20100815.7
+
+> You're not using the [[meta directive|ikiwiki/directive/meta]] correctly.
+> As it says at the top of that page, 
+
+>> You can have only one field
+>> per `meta` directive, use more directives if you want to specify more fields.
+
+> So, \[[!meta title="Nagios 3"]] \[[!meta date="2010-09-09 00:00:00"]]
+> and you should be good to go. --[[Joey]] [[done]]
diff --git a/doc/forum/Have_creation_time_for_new_pages_fetched_from_the_VCS.mdwn b/doc/forum/Have_creation_time_for_new_pages_fetched_from_the_VCS.mdwn
new file mode 100644 (file)
index 0000000..1ce63db
--- /dev/null
@@ -0,0 +1,7 @@
+I use ikiwiki for my blog, and I'd like the creation page of each page to be the one registered in the VCS.  However, the only way to get that is really with the --gettime flag, which gets ALL the timestamps from the VCS...  which take quite some time after a few years of writing ;-)
+
+So I'd like to suggest that ikiwiki could fetch ctime through rcs_getctime() by default when it finds a new page...
+
+mtime is a different matter, not so important to me...
+
+-- [Richard Levitte](http://journal.richard.levitte.org/)
diff --git a/doc/forum/Have_creation_time_for_new_pages_fetched_from_the_VCS/comment_1_9572dd6f7a2f6f630b12f24bb5c4a8ce._comment b/doc/forum/Have_creation_time_for_new_pages_fetched_from_the_VCS/comment_1_9572dd6f7a2f6f630b12f24bb5c4a8ce._comment
new file mode 100644 (file)
index 0000000..d9e974c
--- /dev/null
@@ -0,0 +1,8 @@
+[[!comment format=mdwn
+ username="http://joey.kitenet.net/"
+ nickname="joey"
+ subject="comment 1"
+ date="2011-07-19T15:50:41Z"
+ content="""
+This is not done for reasons of speed. `rcs_getctime` is for many VCSs still slow, requiring a new svn or whatever to be forked off (and in the case of svn, possibly make a network connection). In the case where a commit comes in that adds multiple pages, that would be a lot of work. And for the VCSs where it's not slow, it manages to not be slow by optimising for the case where *all* the times for all pages are looked up in one go .. which is still rather a lot to do when only a single new page has been added. So we lose either way, and it's not suitable for being run all the time, unfortunately.
+"""]]
diff --git a/doc/news/version_3.20110431.mdwn b/doc/news/version_3.20110431.mdwn
deleted file mode 100644 (file)
index e1409f6..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-ikiwiki 3.20110431 released with [[!toggle text="these changes"]]
-[[!toggleable text="""
-   * Danish translation update. Closes: #[625721](http://bugs.debian.org/625721)
-   * Danish underlay translation update. Closes: #[625765](http://bugs.debian.org/625765)
-     (Thanks, Jonas Smedegaard)
-   * Support YAML::XS by not passing decoded unicode to Load. Closes: #[625713](http://bugs.debian.org/625713)
-   * openid, aggregate, pinger: Use Net::INET6Glue if available to
-     support making ipv6 connections. (Note that if LWPx::ParanoidAgent
-     is installed, it defeats this for openid.)
-   * Add additional directive quoting styles, to better support nested
-     directives. Both triple-single-quote and heredoc quotes can be used.
-     (Thanks, Timo Paulssen)
-   * Changed license of madduck's python plugins from GPL-2 to BSD-2-clause.
-   * po: support language codes in the form of 'es\_AR', and 'arn'. (intrigeri)
-     Closes: #[627844](http://bugs.debian.org/627844)
-   * po: Make po4a warn, not error on a malformed document. (intrigeri)
-   * Support the Hiawatha web server which sets HTTPS=off rather than not
-     setting it. (There does not seem to be a standard here.)"""]]
\ No newline at end of file
diff --git a/doc/news/version_3.20110715.mdwn b/doc/news/version_3.20110715.mdwn
new file mode 100644 (file)
index 0000000..da291da
--- /dev/null
@@ -0,0 +1,5 @@
+ikiwiki 3.20110715 released with [[!toggle text="these changes"]]
+[[!toggleable text="""
+   * rename: Fix logic error that broke renaming pages when the attachment
+     plugin was disabled.
+   * rename: Fix logic error that bypassed the usual pagespec checks."""]]
\ No newline at end of file
index 4d75d6325e1d231c2f3859a57b794b43f89e0de9..1f6b3c24e5cd504be6bf7668252c975d60856702 100644 (file)
@@ -17,17 +17,17 @@ links to more information about each.
 feature             |[[git]]|[[svn]]|[[bzr]]   |[[monotone]]|[[mercurial]]|[[darcs]]|[[tla]]   |[[cvs]]
 [[ikiwiki-makerepo]]|yes    |yes    |yes       |yes         |yes          |yes      |no        |yes
 auto.setup          |yes    |yes    |incomplete|yes         |incomplete   |yes      |incomplete|yes
-`rcs_commit_staged` |yes    |yes    |yes       |yes         |no           |yes      |no        |yes
-`rcs_rename`        |yes    |yes    |yes       |yes         |no           |yes      |no        |yes
-`rcs_remove`        |yes    |yes    |yes       |yes         |no           |yes      |no        |yes
-`rcs_diff`          |yes    |yes    |yes       |yes         |no           |yes      |yes       |yes
-`rcs_getctime`      |fast   |slow   |slow      |slow        |slow         |slow     |slow      |slow
-`rcs_getmtime`      |fast   |slow   |slow      |slow        |no           |no       |no        |no
+`rcs_commit_staged` |yes    |yes    |yes       |yes         |yes          |yes      |no        |yes
+`rcs_rename`        |yes    |yes    |yes       |yes         |yes          |yes      |no        |yes
+`rcs_remove`        |yes    |yes    |yes       |yes         |yes          |yes      |no        |yes
+`rcs_diff`          |yes    |yes    |yes       |yes         |yes          |yes      |yes       |yes
+`rcs_getctime`      |fast   |slow   |slow      |slow        |fast         |slow     |slow      |slow
+`rcs_getmtime`      |fast   |slow   |slow      |slow        |fast         |no       |no        |no
 `rcs_preprevert`    |yes    |no     |no        |no          |no           |no       |no        |no
 `rcs_revert`        |yes    |no     |no        |no          |no           |no       |no        |no
 anonymous push      |yes    |no     |no        |no          |no           |no       |no        |no
 conflict handling   |yes    |yes    |yes       |buggy       |yes          |yes      |yes       |yes
-openid username     |yes    |no     |no        |no          |no           |no       |no        |no
+openid username     |yes    |no     |no        |no          |yes          |yes      |no        |no
 """]]
 
 Notes:
diff --git a/doc/todo/Add_instructive_commit_messages_for_add__47__edit_pages.mdwn b/doc/todo/Add_instructive_commit_messages_for_add__47__edit_pages.mdwn
new file mode 100644 (file)
index 0000000..cfb5b98
--- /dev/null
@@ -0,0 +1,43 @@
+When I added or edited a page, no commit message was written out (Mercurial backend, though I guess it shouldn't matter). This was done for e.g. the `rename` plugin. I made a naive but seemingly working change to `editpage.pm` to add a message.
+
+I modeled the message on `rename.pm`, which used a lowercase initial letter and imperative form of the verb. This is not the case for e.g. the `comment` plugin, which says "Added a comment: ", so I guess there is no strict rule on style in this case.
+
+Diff follows. --[[Daniel Andersson]]
+
+> This is somewhat intentional. It's pretty usual for changes to be made
+> to a wiki without bothering to say what changed; the change speaks for
+> itself and it would just be clutter to mention what file was changed,
+> since any reasonable interface will show the filename, or a link,
+> or some summary of what files were affected when showing a change.
+
+>> I use the Mercurial backend, and Mercurial doesn't allow empty commit messages, so if there were no message, it would default to "no message given" (hardcoded in `mercurial.pm`), which is also clutter, and non-descriptive at that. But I'm on board with your reasoning. It's a matter of taste (and somewhat backend), I guess. I might continue to locally use this patch (with the caveat below fixed when commit message is given), but I won't push for it to be included upstream. --[[Daniel Andersson]]
+
+>>> Hmm.. It would be possible to make the mercurial backend 
+>>> include the filename (or just "added" or "edited") in the commit
+>>> message. It might take some work, especially to handle
+>>> `rcs_commit_staged`, since it would probably need to cache
+>>> what files have been staged for commit. --[[Joey]] 
+
+> Also your patch stomps over any commit message that the user *does*
+> provide, so certianly cannot be applied as-is. --[[Joey]] 
+
+>> Yes, "naive" was the word :-) . --[[Daniel Andersson]]
+
+[[!tag patch]]
+
+---
+
+       diff -r ee177ca9bf36 Plugin/editpage.pm
+       --- a/Plugin/editpage.pm        Fri Jul 15 17:58:04 2011 +0200
+       +++ b/Plugin/editpage.pm        Sat Jul 16 03:01:13 2011 +0200
+       @@ -405,6 +405,10 @@
+                       if ($config{rcs}) {
+                               if (! $exists) {
+                                       rcs_add($file);
+       +                               $message = "add $file";
+       +                       }
+       +                       else {
+       +                               $message = "edit $file";
+                               }
+        
+                               # Prevent deadlock with post-commit hook by
diff --git a/doc/todo/Add_instructive_commit_messages_for_removing_pages.mdwn b/doc/todo/Add_instructive_commit_messages_for_removing_pages.mdwn
new file mode 100644 (file)
index 0000000..8b1dd74
--- /dev/null
@@ -0,0 +1,32 @@
+As [[Add instructive commit messages for add _47_ edit pages]], but for `remove.pm`.
+
+I use a `join()` since it at least looks like the plugin is able to remove several pages at once (`foreach` looping over file parameters), thus holding multiple entries in `@pages`. I haven't seen this happen, though.
+
+> I feel that anything that shows a change should show what files were
+> changed (at least as an easily accessible option), so mentioning
+> filenames in commits is almost always clutter.
+> 
+> It could be argued that there should be no message at all here, unless
+> the user provides one (which they currently cannot), as is done when
+> adding files. But the entire removal of a page from a wiki is a fairly
+> unusual circumstance that is probably best highlighted as such in
+> recentchanges. --[[Joey]]
+
+Diff follows. --[[Daniel Andersson]]
+
+[[!tag patch]]
+
+---
+
+       diff -r 4f2ad3a5377e Plugin/remove.pm
+       --- a/Plugin/remove.pm  Fri Jul 15 17:39:04 2011 +0200
+       +++ b/Plugin/remove.pm  Sat Jul 16 03:20:35 2011 +0200
+       @@ -228,7 +228,7 @@
+                                               IkiWiki::rcs_remove($file);
+                                       }
+                                       IkiWiki::rcs_commit_staged(
+       -                                       message => gettext("removed"),
+       +                                       message => sprintf(gettext("remove %s"), join(', ', @files)),
+                                               session => $session,
+                                       );
+                                       IkiWiki::enable_commit_hook();
index 868b57a17a064d5ef0cb6e96bdc49dbb974a3207..8ded94393eb4fb08e6cd6d677ed9a713950d0073 100644 (file)
@@ -22,6 +22,14 @@ Diff follows, for anyone to annotate. First code version is also available at [m
 
 > I've looked over the current version and it looks ok to me. --[[Joey]]
 
+>> I changed the by `mercurial.pm` recorded commit messages and the `rcs_recentchanges` logic to include more information, to emulate the `git.pm` behaviour regarding name presentation on RecentChanges. I don't have anything more to add at the moment, so if the code passes review, I'm done, and I tag this page as "patch". [Final patch version as per this page at my hg repo](http://510x.se/hg/program/ikiwiki/file/bc0e2f838fe3/Plugin/mercurial.pm) ([raw format](http://46.239.104.5:81/hg/program/ikiwiki/raw-file/bc0e2f838fe3/Plugin/mercurial.pm)). I keep the below conversation for reference, but it's mostly outdated. --[[Daniel Andersson]]
+
+[[merged|done]] --[[Joey]] 
+
+[[!tag patch]]
+
+***
+
        diff -r 20c61288d7bd Plugin/mercurial.pm
        --- a/Plugin/mercurial.pm       Fri Jul 15 02:55:12 2011 +0200
        +++ b/Plugin/mercurial.pm       Fri Jul 15 03:29:10 2011 +0200
@@ -166,6 +174,8 @@ Some old `mercurial.pm` logic concerning commiter name is kept instead of transp
 
 >> Yes, right now the long and ugly OpenID strings, e.g. `https://www.google.com/accounts/o8/id?id=AItOawmUIes3yDLfQME0uvZvJKDN0NsdKPx_PTw`, gets recorded as author and are shown as `id [www.google.com/accounts/o8]` in RecentChanges. I see that here on `ikiwiki.info`, my commits, identified by OpenID, are shown as authored by simply `Daniel`. I'll look into it. --[[Daniel Andersson]]
 
+>>> I adapted some logic from `git.pm`. `hg` only has a single commiter name field, whereas `git` has both `GIT_AUTHOR_NAME` and `GIT_AUTHOR_EMAIL`. The behaviour can be emulated by encoding nick and commit medium into commiter name as "`https://www.google.com/accounts/o8/id?id=AItOawmUIes3yDLfQME0uvZvJKDN0NsdKPx_PTw <Daniel@web>`" and parsing this out as necessary when `rcs_recentchanges` is called. *Done* --[[Daniel Andersson]]
+
        @@ -143,43 +206,45 @@
                        $params{message} = "no message given";
                }
diff --git a/doc/todo/po:_add_lang_name_and_code_template_variables.mdwn b/doc/todo/po:_add_lang_name_and_code_template_variables.mdwn
new file mode 100644 (file)
index 0000000..83e5d79
--- /dev/null
@@ -0,0 +1,10 @@
+My po branch adds two new template variables: `lang_code` and
+`lang_name`, that respectively display the current page's language
+codename and pretty name. Please review and pull. --[[intrigeri]]
+
+[[patch]]
+
+> I think you forgot to push that to your public repo; see no unmerged
+> changes on `intrigeri/po` --[[Joey]] 
+
+>> Right. This was fixed. --[[intrigeri]]
diff --git a/doc/todo/rcs__95__diff_implementation_for_Mercurial_backend__44___based_on_Git_backend.mdwn b/doc/todo/rcs__95__diff_implementation_for_Mercurial_backend__44___based_on_Git_backend.mdwn
new file mode 100644 (file)
index 0000000..42cfe1a
--- /dev/null
@@ -0,0 +1,40 @@
+(**Note:** this patch is built on top of [[Attempt to extend Mercurial backend support]] and [[rcs__95__get__123__c__44__m__125__time_implementation_for_Mercurial_backend__44___based_on_Git_backend]]. The former is needed for the `safe_hg()` definition. The latter only shows up in the very last line matching of this patch.)
+
+CC of `rcs_diff` implementation in `git.pm` with few changes. Mercurial provides the `hg diff -g` switch, which outputs the diff in Git-format, making the implementation easy. I think it's a good idea to base `mercurial.pm` as much as possible om `git.pm` to simplify and be able to benefit from the maintenance of `git.pm`, which probably is more used.
+
+[Patch at my hg repo](http://510x.se/hg/program/ikiwiki/diff/cc73d670bf99/Plugin/mercurial.pm) ([raw format](http://510x.se/hg/program/ikiwiki/raw-file/cc73d670bf99/Plugin/mercurial.pm)).
+
+--[[Daniel Andersson]]
+
+> Guess that makes sense, [[done]] --[[Joey]] 
+
+---
+
+       diff -r 1b6c46b62a28 -r cc73d670bf99 Plugin/mercurial.pm
+       --- a/Plugin/mercurial.pm       Tue Jul 19 13:35:17 2011 +0200
+       +++ b/Plugin/mercurial.pm       Tue Jul 19 13:35:37 2011 +0200
+       @@ -307,7 +307,23 @@
+        }
+        
+        sub rcs_diff ($;$) {
+       -       # TODO
+       +       my $rev=shift;
+       +       my $maxlines=shift;
+       +       my @lines;
+       +       my $addlines=sub {
+       +               my $line=shift;
+       +               return if defined $maxlines && @lines == $maxlines;
+       +               push @lines, $line."\n"
+       +                       if (@lines || $line=~/^diff --git/);
+       +               return 1;
+       +       };
+       +       safe_hg(undef, $addlines, "hg", "diff", "-c", $rev, "-g");
+       +       if (wantarray) {
+       +               return @lines;
+       +       }
+       +       else {
+       +               return join("", @lines);
+       +       }
+        }
+        
+        {
diff --git a/doc/todo/rcs__95__get__123__c__44__m__125__time_implementation_for_Mercurial_backend__44___based_on_Git_backend.mdwn b/doc/todo/rcs__95__get__123__c__44__m__125__time_implementation_for_Mercurial_backend__44___based_on_Git_backend.mdwn
new file mode 100644 (file)
index 0000000..54ab4ad
--- /dev/null
@@ -0,0 +1,157 @@
+(**Note:** this patch is built on top of the patch discussed at [[Attempt to extend Mercurial backend support]]. The `run_or_die()` function declared therein is needed for this patch to run.)
+
+Patch to change the Mercurial entries for `rcs_getctime` and `rcs_getmtime` from "slow"/"no" to "fast"/"fast" in [[/rcs]].
+
+The patch is mostly a slightly modified cc of the code in `git.pm`. The exception is that a Mercurial style file is needed to get a reasonable output from `hg log`. To make the file self-contained in its current state, this was solved with a generated temp file, but that section could and should be replaced with just setting `$tmpl_filename` to a path to a static file `map-cmdline.ikiwiki-log` (to conform with Mercurial's naming of its default styles) in the Ikiwiki distribution, with contents
+
+       changeset = "{date}\n{files}\n"
+       file = "{file}\n"
+
+which is based on an [example](http://hgbook.red-bean.com/read/customizing-the-output-of-mercurial.html#id417978) in [Mercurial: The Definitive Guide](http://hgbook.red-bean.com/) (and otherwise fascinatingly undocumented). A style *file* is required for this kind of formatting. There is a switch `hg log --template` to directly control simple output formatting, but in this case, the `{file}` directive must be redefined, which can only be done with `hg log --style`.
+
+If `{file}` is not redefined, all filenames are output on a single line separated with a space. It is not possible to conclude if the space is part of a filename or just a separator, and thus impossible to use in this case. Some output filters are available in hg, but they are not fit for this cause (and would slow down the process unnecessarily).
+
+In the patch listing below, I've marked the parts of the patch that should be removed when the tempfile replacement is done with **Marker# start** and **Marker# end**.
+
+[Patch at pastebin](http://pastebin.com/QBE4UH6n).
+
+[Patch at pastebin with tempfile code replaced by a path to a static file (change path accordingly)](http://pastebin.com/dmSCRkUK).
+
+[My `mercurial.pm` in raw format after this and beforementioned patches (tempfile code present)](http://510x.se/hg/program/ikiwiki/raw-file/1b6c46b62a28/Plugin/mercurial.pm).
+
+--[[Daniel Andersson]]
+
+> I have applied this, but I left the temp file in. 
+> The overhead seems small since it will only be run once per ikiwiki run,
+> and only when `ikiwiki --gettime` is run, or the first time
+> ikiwiki runs. Thanks for this! [[done]] --[[Joey]] 
+
+---
+
+       diff -r 78a217fb13f3 -r 1b6c46b62a28 Plugin/mercurial.pm
+       --- a/Plugin/mercurial.pm       Sat Jul 16 03:19:25 2011 +0200
+       +++ b/Plugin/mercurial.pm       Tue Jul 19 13:35:17 2011 +0200
+       @@ -310,28 +310,91 @@
+               # TODO
+        }
+        
+       -sub rcs_getctime ($) {
+       -       my ($file) = @_;
+       +{
+       +my %time_cache;
+        
+       -       my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v",
+       -               "--style", "default", "$config{srcdir}/$file");
+       -       open (my $out, "-|", @cmdline);
+       +sub findtimes ($$) {
+       +       my $file=shift;
+       +       my $id=shift; # 0 = mtime ; 1 = ctime
+        
+       -       my @log = (mercurial_log($out));
+       +       if (! keys %time_cache) {
+       +               my $date;
+        
+       -       if (@log < 1) {
+       -               return 0;
+
+**Marker1 start**
+
+       +               # The tempfile logic should be replaced with a file included
+       +               # with ikiwiki containing
+       +               # --
+       +               # changeset = "{date}\n{files}\n"
+       +               # file = "{file}\n"
+       +               # --
+       +               # to avoid creating a file with static contents every time this
+       +               # function is called. The path to this file should replace
+       +               # $tmpl_filename in run_or_die() below.
+       +               #
+
+**Marker1 end**
+
+       +               # It doesn't seem possible to specify the format wanted for the
+       +               # changelog (same format as is generated in git.pm:findtimes(),
+       +               # though the date differs slightly) without using a style
+       +               # _file_. There is a "hg log" switch "--template" to directly
+       +               # control simple output formatting, but in this case, the
+       +               # {file} directive must be redefined, which can only be done
+       +               # with "--style".
+       +               #
+       +               # If {file} is not redefined, all files are output on a single
+       +               # line separated with a space. It is not possible to conclude
+       +               # if the space is part of a filename or just a separator, and
+       +               # thus impossible to use in this case.
+       +               # 
+       +               # Some output filters are available in hg, but they are not fit
+       +               # for this cause (and would slow down the process
+       +               # unnecessarily).
+       +
+
+**Marker2 start**
+
+       +               use File::Temp qw(tempfile);
+       +               my ($tmpl_fh, $tmpl_filename) = tempfile(UNLINK => 1);
+       +
+       +               print $tmpl_fh 'changeset = "{date}\\n{files}\\n"' . "\n";
+       +               print $tmpl_fh 'file = "{file}\\n"' . "\n";
+       +
+
+**Marker2 end**
+
+       +               foreach my $line (run_or_die('hg', 'log', '--style',
+       +                               $tmpl_filename)) {
+       +                       # {date} gives output on the form
+       +                       # 1310694511.0-7200
+       +                       # where the first number is UTC Unix timestamp with one
+       +                       # decimal (decimal always 0, at least on my system)
+       +                       # followed by local timezone offset from UTC in
+       +                       # seconds.
+       +                       if (! defined $date && $line =~ /^\d+\.\d[+-]\d*$/) {
+       +                               $line =~ s/^(\d+).*/$1/;
+       +                               $date=$line;
+       +                       }
+       +                       elsif (! length $line) {
+       +                               $date=undef;
+       +                       }
+       +                       else {
+       +                               my $f=$line;
+       +
+       +                               if (! $time_cache{$f}) {
+       +                                       $time_cache{$f}[0]=$date; # mtime
+       +                               }
+       +                               $time_cache{$f}[1]=$date; # ctime
+       +                       }
+       +               }
+
+**Marker3 start**
+
+       +               close ($tmpl_fh);
+
+**Marker3 end**
+
+               }
+        
+       -       eval q{use Date::Parse};
+       -       error($@) if $@;
+       -       
+       -       my $ctime = str2time($log[$#log]->{"date"});
+       -       return $ctime;
+       +       return exists $time_cache{$file} ? $time_cache{$file}[$id] : 0;
+       +}
+       +
+       +}
+       +
+       +sub rcs_getctime ($) {
+       +       my $file = shift;
+       +
+       +       return findtimes($file, 1);
+        }
+        
+        sub rcs_getmtime ($) {
+       -       error "rcs_getmtime is not implemented for mercurial\n"; # TODO
+       +       my $file = shift;
+       +
+       +       return findtimes($file, 0);
+        }
+        
+        1