+{
+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)) {
+ if (! defined $date && $line =~ /^(\d+)/) {
+ $date=$1;
+ }
+ elsif (! length $line) {
+ $date=undef;
+ }
+ else {
+ my $f=$line;