implement rcs_getmtime for svn
authorJoey Hess <joey@gnu.kitenet.net>
Fri, 16 Apr 2010 22:43:51 +0000 (18:43 -0400)
committerJoey Hess <joey@gnu.kitenet.net>
Fri, 16 Apr 2010 22:46:20 +0000 (18:46 -0400)
This is a slow implementation; it runs svn log once per file
still, rather than running svn log once on the whole srcdir.

I did it this way because in my experience, svn log, run on a directory,
does not always list every change to files inside that directory.
I don't know why, and I use svn as little as possible these days.

IkiWiki/Plugin/svn.pm
debian/changelog
doc/rcs.mdwn

index 85c205f0939bd81d5f22bc7a0a19486dc4404c02..6e1d4a40f9513a93bf7955a7f9bff921fda2715c 100644 (file)
@@ -350,9 +350,18 @@ sub rcs_diff ($) {
        return `svnlook diff $config{svnrepo} -r$rev --no-diff-deleted`;
 }
 
-sub rcs_getctime ($) {
+{
+
+my ($lastfile, $lastmtime, $lastctime);
+
+sub findtimes ($) {
        my $file=shift;
 
+       if ($lastfile eq $file) {
+               return $lastmtime, $lastctime;
+       }
+       $lastfile=$file;
+
        my $svn_log_infoline=qr/^r\d+\s+\|\s+[^\s]+\s+\|\s+(\d+-\d+-\d+\s+\d+:\d+:\d+\s+[-+]?\d+).*/;
                
        my $child = open(SVNLOG, "-|");
@@ -360,28 +369,39 @@ sub rcs_getctime ($) {
                exec("svn", "log", $file) || error("svn log $file failed to run");
        }
 
-       my $date;
+       my ($cdate, $mdate);
        while (<SVNLOG>) {
                if (/$svn_log_infoline/) {
-                       $date=$1;
+                       $cdate=$1;
+                       $mdate=$1 unless defined $mdate;
                }
        }
-       close SVNLOG || warn "svn log $file exited $?";
+       close SVNLOG || error "svn log $file exited $?";
 
-       if (! defined $date) {
-               warn "failed to parse svn log for $file\n";
-               return 0;
+       if (! defined $cdate) {
+               error "failed to parse svn log for $file\n";
        }
                
        eval q{use Date::Parse};
        error($@) if $@;
-       $date=str2time($date);
-       debug("found ctime ".localtime($date)." for $file");
-       return $date;
+       
+       $lastctime=str2time($cdate);
+       $lastmtime=str2time($mdate);
+       return $lastmtime, $lastctime;
+}
+
+}
+
+sub rcs_getctime ($) {
+       my $file=shift;
+
+       return (findtimes($file))[1];
 }
 
 sub rcs_getmtime ($) {
-       error "rcs_getmtime is not implemented for svn\n"; # TODO
+       my $file=shift;
+
+       return (findtimes($file))[0];
 }
 
 1
index 60a67cbe3b618e23e210d2b856f9753bf38d38a0..774aedc403e32408655ea54c5d012d41443544d5 100644 (file)
@@ -50,7 +50,7 @@ ikiwiki (3.20100415) UNRELEASED; urgency=low
   * Automatically run --gettime the first time ikiwiki is run on 
     a given srcdir.
   * Add rcs_getmtime to plugin API; currently only implemented
-    for git.
+    for git and svn.
   * Optimise --gettime for git, so it's appropriatly screamingly
     fast. (This could be done for other backends too.)
   * However, --gettime for git no longer follows renames.
index b5bfc24148fca5662fdf163a823690aaf363d5d4..450d16800b247c275429abaffa5508f23fea0182 100644 (file)
@@ -28,7 +28,7 @@ auto.setup          |yes    |yes    |incomplete|yes         |incomplete   |yes
 `rcs_remove`        |yes    |yes    |yes       |yes         |no           |yes      |no        |yes
 `rcs_diff`          |yes    |yes    |yes       |yes         |no           |yes      |yes       |yes
 `rcs_getctime`      |fast   |slow   |slow      |slow        |slow         |slow     |slow      |slow
-`rcs_getmtime`      |fast   |no     |no        |no          |no           |no       |no        |no
+`rcs_getmtime`      |fast   |slow   |no        |no          |no           |no       |no        |no
 anonymous push      |yes    |no     |no        |no          |no           |no       |no        |no
 conflict handling   |yes    |yes    |yes       |buggy       |yes          |yes      |yes       |yes
 """]]