* IkiWiki/Plugin/monotone.pm: implement rcs_getmtime

master
Richard Levitte 2011-03-30 16:56:15 +02:00
parent 0204dabccf
commit 83de1e4f1d
1 changed files with 49 additions and 1 deletions

View File

@ -703,7 +703,55 @@ sub rcs_getctime ($) {
}
sub rcs_getmtime ($) {
error "rcs_getmtime is not implemented for monotone\n"; # TODO
my $file=shift;
chdir $config{srcdir}
or error("Cannot chdir to $config{srcdir}: $!");
my $child = open(MTNLOG, "-|");
if (! $child) {
exec("mtn", "log", "--root=$config{mtnrootdir}", "--no-graph",
"--brief", $file) || error("mtn log $file failed to run");
}
my $lastRev = "";
while (<MTNLOG>) {
if (/^($sha1_pattern)/ && $lastRev eq "") {
$lastRev=$1;
}
}
close MTNLOG || debug("mtn log $file exited $?");
if (! defined $lastRev) {
debug "failed to parse mtn log for $file";
return 0;
}
my $automator = Monotone->new();
$automator->open(undef, $config{mtnrootdir});
my $certs = [read_certs($automator, $lastRev)];
$automator->close();
my $date;
foreach my $cert (@$certs) {
if ($cert->{signature} eq "ok" && $cert->{trust} eq "trusted") {
if ($cert->{name} eq "date") {
$date = $cert->{value};
}
}
}
if (! defined $date) {
debug "failed to find date cert for revision $lastRev when looking for creation time of $file";
return 0;
}
$date=str2time($date, 'UTC');
debug("found mtime ".localtime($date)." for $file");
return $date;
}
1