]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/git.pm
editpage, comments: Fix broken links in sidebar (due to forcebaseurl). (Thanks, privat)
[ikiwiki.git] / IkiWiki / Plugin / git.pm
index ad58231e0bbd897e0f65dec50cc1be451fa3c92a..aa402c04f4e461b9450a0192313de1dda8726f49 100644 (file)
@@ -25,6 +25,7 @@ sub import {
        hook(type => "rcs", id => "rcs_recentchanges", call => \&rcs_recentchanges);
        hook(type => "rcs", id => "rcs_diff", call => \&rcs_diff);
        hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime);
+       hook(type => "rcs", id => "rcs_getmtime", call => \&rcs_getmtime);
        hook(type => "rcs", id => "rcs_receive", call => \&rcs_receive);
 }
 
@@ -51,6 +52,9 @@ sub checkconfig () {
                        wrappermode => (defined $config{git_wrappermode} ? $config{git_wrappermode} : "06755"),
                };
        }
+
+       # Avoid notes, parser does not handle and they only slow things down.
+       $ENV{GIT_NOTES_REF}="";
        
        # Run receive test only if being called by the wrapper, and not
        # when generating same.
@@ -65,6 +69,7 @@ sub getsetup () {
                plugin => {
                        safe => 0, # rcs plugin
                        rebuild => undef,
+                       section => "rcs",
                },
                git_wrapper => {
                        type => "string",
@@ -419,7 +424,10 @@ sub git_sha1 (;$) {
                '--', $file);
        if ($sha1) {
                ($sha1) = $sha1 =~ m/($sha1_pattern)/; # sha1 is untainted now
-       } else { debug("Empty sha1sum for '$file'.") }
+       }
+       else {
+               debug("Empty sha1sum for '$file'.");
+       }
        return defined $sha1 ? $sha1 : q{};
 }
 
@@ -608,17 +616,51 @@ sub rcs_diff ($) {
        }
 }
 
-sub rcs_getctime ($) {
+{
+my %time_cache;
+
+sub findtimes ($$) {
        my $file=shift;
+       my $id=shift; # 0 = mtime ; 1 = ctime
+
        # Remove srcdir prefix
        $file =~ s/^\Q$config{srcdir}\E\/?//;
 
-       my @sha1s = run_or_non('git', 'rev-list', 'HEAD', '--', $file);
-       my $ci    = git_commit_info($sha1s[$#sha1s], 1);
-       my $ctime = $ci->{'author_epoch'};
-       debug("ctime for '$file': ". localtime($ctime));
+       if (! keys %time_cache) {
+               my $date;
+               foreach my $line (run_or_die('git', 'log',
+                               '--pretty=format:%ct',
+                               '--name-only', '--relative')) {
+                       if (! defined $date && $line =~ /^(\d+)$/) {
+                               $date=$line;
+                       }
+                       elsif (! length $line) {
+                               $date=undef;
+                       }
+                       else {
+                               if (! $time_cache{$line}) {
+                                       $time_cache{$line}[0]=$date; # mtime
+                               }
+                               $time_cache{$line}[1]=$date; # ctime
+                       }
+               }
+       }
+
+       return exists $time_cache{$file} ? $time_cache{$file}[$id] : 0;
+}
+
+}
+
+sub rcs_getctime ($) {
+       my $file=shift;
+
+       return findtimes($file, 1);
+}
+
+sub rcs_getmtime ($) {
+       my $file=shift;
 
-       return $ctime;
+       return findtimes($file, 0);
 }
 
 sub rcs_receive () {