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.
master
Joey Hess 2010-04-16 18:29:45 -04:00
parent 0bd6c32766
commit dee2940c0b
9 changed files with 76 additions and 19 deletions

View File

@ -442,7 +442,6 @@ sub getsetup () {
},
gettime => {
type => "internal",
default => 0,
description => "running in gettime mode",
safe => 0,
rebuild => 0,
@ -1512,6 +1511,7 @@ sub loadindex () {
open ($in, "<", "$config{wikistatedir}/indexdb") || return;
}
else {
$config{gettime}=1; # first build
return;
}
}

View File

@ -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 () {

View File

@ -352,6 +352,8 @@ sub find_new_files ($) {
my @new;
my @internal_new;
my $times_noted;
foreach my $file (@$files) {
my $page=pagename($file);
if (exists $pagesources{$page} && $pagesources{$page} ne $file) {
@ -363,7 +365,12 @@ sub find_new_files ($) {
if (isinternal($page)) {
push @internal_new, $file;
}
else {
elsif ($config{rcs}) {
if (! $times_noted) {
debug(sprintf(gettext("querying %s for file creation and modification times.."), $config{rcs}));
$times_noted=1;
}
push @new, $file;
if ($config{gettime} && -e "$config{srcdir}/$file") {
eval {
@ -377,7 +384,7 @@ sub find_new_files ($) {
}
my $mtime;
eval {
my $mtime=rcs_getmtime("$config{srcdir}/$file");
$mtime=rcs_getmtime("$config{srcdir}/$file");
};
if ($@) {
print STDERR $@;

7
debian/changelog vendored
View File

@ -47,8 +47,15 @@ ikiwiki (3.20100415) UNRELEASED; urgency=low
* Rename --getctime to --gettime. (The old name still works for
backwards compatability.)
* --gettime now also looks up last modification time.
* Automatically run --gettime the first time ikiwiki is run on
a given srcdir.
* Add rcs_getmtime to plugin API; currently only implemented
for git.
* 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.
-- Joey Hess <joeyh@debian.org> Sun, 04 Apr 2010 12:17:11 -0400

2
debian/control vendored
View File

@ -7,7 +7,7 @@ Build-Depends-Indep: dpkg-dev (>= 1.9.0), libxml-simple-perl,
libtimedate-perl, libhtml-template-perl,
libhtml-scrubber-perl, wdg-html-validator,
libhtml-parser-perl, liburi-perl, perlmagick, po4a (>= 0.34),
libfile-chdir-perl
libfile-chdir-perl,
Maintainer: Joey Hess <joeyh@debian.org>
Uploaders: Josh Triplett <josh@freedesktop.org>
Standards-Version: 3.8.4

View File

@ -1085,6 +1085,8 @@ it up in the history.
It's ok if this is not implemented, and throws an error.
If the RCS cannot determine a ctime for the file, return 0.
#### `rcs_getmtime($)`
This is used to get the page modification time for a file from the RCS, by
@ -1092,6 +1094,8 @@ looking it up in the history.
It's ok if this is not implemented, and throws an error.
If the RCS cannot determine a mtime for the file, return 0.
#### `rcs_receive()`
This is called when ikiwiki is running as a pre-receive hook (or

View File

@ -320,7 +320,7 @@ also be configured using a setup file.
intercepted. If you enable this option then you must run at least the
CGI portion of ikiwiki over SSL.
* --gettime
* --gettime, --no-gettime
Extract creation and modification times for each new page from the
the revision control's log. This is done automatically when building a

View File

@ -1,6 +1,18 @@
#!/usr/bin/perl
# Configuration file for ikiwiki to build its documentation wiki.
# Use git during the build, if it's available and if we're building
# from a git checkout. This ensures ikiwiki gets the right mtimes and
# ctimes for files in the doc wiki.
our $rcs="norcs";
BEGIN {
my $git=`which git 2>&1`;
chomp $git;
if (-x $git && -d ".git") {
$rcs="git";
}
}
use IkiWiki::Setup::Standard {
wikiname => "ikiwiki",
srcdir => "doc",
@ -9,7 +21,7 @@ use IkiWiki::Setup::Standard {
underlaydirbase => "underlays",
underlaydir => "underlays/basewiki",
discussion => 0,
exclude => qr/\/discussion|bugs\/*|todo\/*|forum\/*/,
exclude => qr/\/discussion|bugs\/*|todo\/*|forum\/*/, # save space
locale => '',
verbose => 1,
syslog => 0,
@ -17,4 +29,7 @@ use IkiWiki::Setup::Standard {
usedirs => 0,
prefix_directives => 1,
add_plugins => [qw{goodstuff version haiku polygen fortune table}],
disable_plugins => [qw{recentchanges}], # not appropriate for doc dir
rcs => $rcs,
gitorigin_branch => '', # don't pull during build
}

View File

@ -45,7 +45,7 @@ sub getconfig () {
"usedirs!" => \$config{usedirs},
"prefix-directives!" => \$config{prefix_directives},
"getctime" => \$config{gettime},
"gettime" => \$config{gettime},
"gettime!" => \$config{gettime},
"numbacklinks=i" => \$config{numbacklinks},
"rcs=s" => \$config{rcs},
"no-rcs" => sub { $config{rcs}="" },