From 83de1e4f1db63e13bda030916dfcba1ca8f75f0c Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Wed, 30 Mar 2011 16:56:15 +0200 Subject: [PATCH] * IkiWiki/Plugin/monotone.pm: implement rcs_getmtime --- IkiWiki/Plugin/monotone.pm | 50 +++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/IkiWiki/Plugin/monotone.pm b/IkiWiki/Plugin/monotone.pm index 38313a542..14c22ebca 100644 --- a/IkiWiki/Plugin/monotone.pm +++ b/IkiWiki/Plugin/monotone.pm @@ -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 () { + 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 -- 2.26.2