]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/monotone.pm
* IkiWiki/Plugin/monotone.pm: implement rcs_getmtime
[ikiwiki.git] / IkiWiki / Plugin / monotone.pm
index 02690b10e6388f54bb6b85fbf42a9fa5b94c6dfc..14c22ebca2f02c69f132ea581bb423aa29f20c24 100644 (file)
@@ -621,8 +621,9 @@ sub rcs_recentchanges ($) {
        return @ret;
 }
 
-sub rcs_diff ($) {
+sub rcs_diff ($;$) {
        my $rev=shift;
+       my $maxlines=shift;
        my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint
        
        chdir $config{srcdir}
@@ -633,7 +634,11 @@ sub rcs_diff ($) {
                exec("mtn", "diff", "--root=$config{mtnrootdir}", "-r", "p:".$sha1, "-r", $sha1) || error("mtn diff $sha1 failed to run");
        }
 
-       my (@lines) = <MTNDIFF>;
+       my @lines;
+       while (my $line=<MTNDIFF>) {
+               last if defined $maxlines && @lines == $maxlines;
+               push @lines, $line;
+       }
 
        close MTNDIFF || debug("mtn diff $sha1 exited $?");
 
@@ -698,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