summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/git.pm
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2010-04-16 18:29:45 -0400
committerJoey Hess <joey@gnu.kitenet.net>2010-04-16 18:30:56 -0400
commitdee2940c0bc97080088c99f399cd0ff0df3bec23 (patch)
tree0710cd8f4a3d64d1dc22e52911f04954f8d22fa2 /IkiWiki/Plugin/git.pm
parent0bd6c327666e2ac747183faca483c46ee2774285 (diff)
automatically run --gettime, and optimise it for git
* Automatically run --gettime the first time ikiwiki is run on a given srcdir. * 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. * Use above to fix up timestamps on docwiki, as well as ensure that timestamps on basewiki files shipped in the deb are sane.
Diffstat (limited to 'IkiWiki/Plugin/git.pm')
-rw-r--r--IkiWiki/Plugin/git.pm48
1 files changed, 36 insertions, 12 deletions
diff --git a/IkiWiki/Plugin/git.pm b/IkiWiki/Plugin/git.pm
index 86d80186f..aa402c04f 100644
--- a/IkiWiki/Plugin/git.pm
+++ b/IkiWiki/Plugin/git.pm
@@ -616,27 +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 @raw_lines = run_or_die('git', 'log',
- '--follow', '--no-merges',
- '--pretty=raw', '--raw', '--abbrev=40', '--always', '-c',
- '-r', '--', $file);
- my @ci;
- while (my $parsed = parse_diff_tree("", \@raw_lines)) {
- push @ci, $parsed;
+ 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
+ }
+ }
}
- my $ctime = $ci[$#ci]->{'author_epoch'};
- debug("ctime for '$file': ". localtime($ctime));
- return $ctime;
+ return exists $time_cache{$file} ? $time_cache{$file}[$id] : 0;
+}
+
+}
+
+sub rcs_getctime ($) {
+ my $file=shift;
+
+ return findtimes($file, 1);
}
sub rcs_getmtime ($) {
- error "rcs_getmtime is not implemented for git\n"; # TODO
+ my $file=shift;
+
+ return findtimes($file, 0);
}
sub rcs_receive () {