From 83de1e4f1db63e13bda030916dfcba1ca8f75f0c Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Wed, 30 Mar 2011 16:56:15 +0200 Subject: * IkiWiki/Plugin/monotone.pm: implement rcs_getmtime --- IkiWiki/Plugin/monotone.pm | 50 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'IkiWiki') 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 -- cgit v1.2.3 From 9b5a5c1823ca35f0e9f6e8c8d3bc2b49d7af2403 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Wed, 30 Mar 2011 16:59:01 +0200 Subject: * IkiWiki/Plugin/monotone.pm: monotone v0.48 has a small error that affects rcs_getctime. A small adjustment takes care of that. --- IkiWiki/Plugin/monotone.pm | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/monotone.pm b/IkiWiki/Plugin/monotone.pm index 14c22ebca..1d89e3f6b 100644 --- a/IkiWiki/Plugin/monotone.pm +++ b/IkiWiki/Plugin/monotone.pm @@ -9,6 +9,7 @@ use Date::Parse qw(str2time); use Date::Format qw(time2str); my $sha1_pattern = qr/[0-9a-fA-F]{40}/; # pattern to validate sha1sums +my $mtn_version = undef; sub import { hook(type => "checkconfig", id => "monotone", call => \&checkconfig); @@ -40,20 +41,19 @@ sub checkconfig () { exec("mtn", "version") || error("mtn version failed to run"); } - my $version=undef; while () { if (/^monotone (\d+\.\d+)(?:(?:\.\d+){0,2}|dev)? /) { - $version=$1; + $mtn_version=$1; } } close MTN || debug("mtn version exited $?"); - if (!defined($version)) { + if (!defined($mtn_version)) { error("Cannot determine monotone version"); } - if ($version < 0.38) { - error("Monotone version too old, is $version but required 0.38"); + if ($mtn_version < 0.38) { + error("Monotone version too old, is $mtn_version but required 0.38"); } if (defined $config{mtn_wrapper} && length $config{mtn_wrapper}) { @@ -662,9 +662,11 @@ sub rcs_getctime ($) { "--brief", $file) || error("mtn log $file failed to run"); } + my $prevRev; my $firstRev; while () { if (/^($sha1_pattern)/) { + $prevRev=$firstRev; $firstRev=$1; } } @@ -678,6 +680,17 @@ sub rcs_getctime ($) { my $automator = Monotone->new(); $automator->open(undef, $config{mtnrootdir}); + # mtn 0.48 has a bug that makes it list the creation of parent + # directories as last (first) log entry... So when we're dealing + # with that version, let's check that the file we're looking for + # is actually part of the last (first) revision. Otherwise, pick + # the one before (after) that one. + if ($mtn_version == 0.48) { + my $changes = [get_changed_files($automator, $firstRev)]; + if (! exists {map { $_ => 1 } @$changes}->{$file}) { + $firstRev = $prevRev; + } + } my $certs = [read_certs($automator, $firstRev)]; $automator->close(); -- cgit v1.2.3