2009-04-04 23:45:13 +02:00
|
|
|
#!/usr/bin/perl
|
2008-10-01 23:24:06 +02:00
|
|
|
package IkiWiki::Plugin::darcs;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2012-03-13 16:49:29 +01:00
|
|
|
use URI::Escape q{uri_escape_utf8};
|
2008-10-01 23:24:06 +02:00
|
|
|
use IkiWiki;
|
|
|
|
|
|
|
|
sub import {
|
2008-10-16 01:38:21 +02:00
|
|
|
hook(type => "checkconfig", id => "darcs", call => \&checkconfig);
|
|
|
|
hook(type => "getsetup", id => "darcs", call => \&getsetup);
|
|
|
|
hook(type => "rcs", id => "rcs_update", call => \&rcs_update);
|
|
|
|
hook(type => "rcs", id => "rcs_prepedit", call => \&rcs_prepedit);
|
|
|
|
hook(type => "rcs", id => "rcs_commit", call => \&rcs_commit);
|
|
|
|
hook(type => "rcs", id => "rcs_commit_staged", call => \&rcs_commit_staged);
|
|
|
|
hook(type => "rcs", id => "rcs_add", call => \&rcs_add);
|
|
|
|
hook(type => "rcs", id => "rcs_remove", call => \&rcs_remove);
|
|
|
|
hook(type => "rcs", id => "rcs_rename", call => \&rcs_rename);
|
|
|
|
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);
|
2010-04-16 23:02:29 +02:00
|
|
|
hook(type => "rcs", id => "rcs_getmtime", call => \&rcs_getmtime);
|
2008-10-01 23:24:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub silentsystem (@) {
|
2008-10-16 01:38:21 +02:00
|
|
|
open(SAVED_STDOUT, ">&STDOUT");
|
|
|
|
open(STDOUT, ">/dev/null");
|
|
|
|
my $ret = system @_;
|
|
|
|
open(STDOUT, ">&SAVED_STDOUT");
|
|
|
|
return $ret;
|
2008-10-01 23:24:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub darcs_info ($$$) {
|
2008-10-16 01:38:21 +02:00
|
|
|
my $field = shift;
|
|
|
|
my $repodir = shift;
|
|
|
|
my $file = shift; # Relative to the repodir.
|
|
|
|
|
|
|
|
my $child = open(DARCS_CHANGES, "-|");
|
|
|
|
if (! $child) {
|
|
|
|
exec('darcs', 'changes', '--repodir', $repodir, '--xml-output', $file) or
|
|
|
|
error("failed to run 'darcs changes'");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Brute force for now. :-/
|
|
|
|
while (<DARCS_CHANGES>) {
|
|
|
|
last if /^<\/created_as>$/;
|
|
|
|
}
|
|
|
|
($_) = <DARCS_CHANGES> =~ /$field=\'([^\']+)/;
|
|
|
|
$field eq 'hash' and s/\.gz//; # Strip away the '.gz' from 'hash'es.
|
|
|
|
|
2008-10-16 23:20:17 +02:00
|
|
|
close(DARCS_CHANGES);
|
2008-10-16 01:38:21 +02:00
|
|
|
|
|
|
|
return $_;
|
2008-10-01 23:24:06 +02:00
|
|
|
}
|
|
|
|
|
2010-03-19 20:09:08 +01:00
|
|
|
sub file_in_vc ($$) {
|
2009-04-04 23:45:13 +02:00
|
|
|
my $repodir = shift;
|
|
|
|
my $file = shift;
|
2008-10-16 01:38:21 +02:00
|
|
|
|
|
|
|
my $child = open(DARCS_MANIFEST, "-|");
|
|
|
|
if (! $child) {
|
|
|
|
exec('darcs', 'query', 'manifest', '--repodir', $repodir) or
|
|
|
|
error("failed to run 'darcs query manifest'");
|
|
|
|
}
|
|
|
|
my $found=0;
|
|
|
|
while (<DARCS_MANIFEST>) {
|
2010-04-20 23:49:00 +02:00
|
|
|
$found = 1 if /^(\.\/)?$file$/;
|
2008-10-16 01:38:21 +02:00
|
|
|
}
|
|
|
|
close(DARCS_MANIFEST) or error("'darcs query manifest' exited " . $?);
|
|
|
|
|
2008-10-16 23:20:17 +02:00
|
|
|
return $found;
|
|
|
|
}
|
|
|
|
|
2010-03-19 20:09:08 +01:00
|
|
|
sub darcs_rev ($) {
|
2008-10-16 23:20:17 +02:00
|
|
|
my $file = shift; # Relative to the repodir.
|
|
|
|
my $repodir = $config{srcdir};
|
|
|
|
|
2009-12-04 19:13:41 +01:00
|
|
|
return "" unless file_in_vc($repodir, $file);
|
2008-10-16 01:38:21 +02:00
|
|
|
my $hash = darcs_info('hash', $repodir, $file);
|
|
|
|
return defined $hash ? $hash : "";
|
2008-10-01 23:24:06 +02:00
|
|
|
}
|
|
|
|
|
2010-03-19 20:09:08 +01:00
|
|
|
sub checkconfig () {
|
2008-10-16 01:38:21 +02:00
|
|
|
if (defined $config{darcs_wrapper} && length $config{darcs_wrapper}) {
|
|
|
|
push @{$config{wrappers}}, {
|
|
|
|
wrapper => $config{darcs_wrapper},
|
|
|
|
wrappermode => (defined $config{darcs_wrappermode} ? $config{darcs_wrappermode} : "06755"),
|
|
|
|
};
|
|
|
|
}
|
2008-10-01 23:24:06 +02:00
|
|
|
}
|
|
|
|
|
2010-03-19 20:09:08 +01:00
|
|
|
sub getsetup () {
|
2008-10-16 01:38:21 +02:00
|
|
|
return
|
2009-04-04 23:45:13 +02:00
|
|
|
plugin => {
|
|
|
|
safe => 0, # rcs plugin
|
|
|
|
rebuild => undef,
|
2010-02-12 04:24:15 +01:00
|
|
|
section => "rcs",
|
2009-04-04 23:45:13 +02:00
|
|
|
},
|
|
|
|
darcs_wrapper => {
|
|
|
|
type => "string",
|
|
|
|
example => "/darcs/repo/_darcs/ikiwiki-wrapper",
|
|
|
|
description => "wrapper to generate (set as master repo apply hook)",
|
|
|
|
safe => 0, # file
|
|
|
|
rebuild => 0,
|
|
|
|
},
|
|
|
|
darcs_wrappermode => {
|
|
|
|
type => "string",
|
|
|
|
example => '06755',
|
|
|
|
description => "mode for darcs_wrapper (can safely be made suid)",
|
|
|
|
safe => 0,
|
|
|
|
rebuild => 0,
|
|
|
|
},
|
|
|
|
historyurl => {
|
|
|
|
type => "string",
|
|
|
|
example => "http://darcs.example.com/darcsweb.cgi?r=wiki;a=filehistory;f=[[file]]",
|
|
|
|
description => "darcsweb url to show file history ([[file]] substituted)",
|
|
|
|
safe => 1,
|
|
|
|
rebuild => 1,
|
|
|
|
},
|
|
|
|
diffurl => {
|
|
|
|
type => "string",
|
|
|
|
example => "http://darcs.example.com/darcsweb.cgi?r=wiki;a=filediff;h=[[hash]];f=[[file]]",
|
|
|
|
description => "darcsweb url to show a diff ([[hash]] and [[file]] substituted)",
|
|
|
|
safe => 1,
|
|
|
|
rebuild => 1,
|
|
|
|
},
|
2008-10-01 23:24:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub rcs_update () {
|
2008-10-16 01:38:21 +02:00
|
|
|
silentsystem('darcs', "pull", "--repodir", $config{srcdir}, "-qa")
|
2008-10-01 23:24:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub rcs_prepedit ($) {
|
2008-10-16 01:38:21 +02:00
|
|
|
# Prepares to edit a file under revision control. Returns a token that
|
|
|
|
# must be passed to rcs_commit() when the file is to be commited. For us,
|
|
|
|
# this token the hash value of the latest patch that modifies the file,
|
2009-04-04 23:45:13 +02:00
|
|
|
# i.e. something like its current revision.
|
2008-10-16 01:38:21 +02:00
|
|
|
|
|
|
|
my $file = shift; # Relative to the repodir.
|
|
|
|
my $rev = darcs_rev($file);
|
|
|
|
return $rev;
|
2008-10-01 23:24:06 +02:00
|
|
|
}
|
|
|
|
|
2010-06-23 23:35:21 +02:00
|
|
|
sub commitauthor (@) {
|
|
|
|
my %params=@_;
|
|
|
|
|
|
|
|
my $author="anon\@web";
|
|
|
|
if (defined $params{session}) {
|
|
|
|
if (defined $params{session}->param("name")) {
|
|
|
|
return $params{session}->param("name").'@web';
|
|
|
|
}
|
|
|
|
elsif (defined $params{session}->remote_addr()) {
|
|
|
|
return $params{session}->remote_addr().'@web';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 'anon@web';
|
|
|
|
}
|
|
|
|
|
|
|
|
sub rcs_commit (@) {
|
2008-10-16 01:38:21 +02:00
|
|
|
# Commit the page. Returns 'undef' on success and a version of the page
|
|
|
|
# with conflict markers on failure.
|
2010-06-23 23:35:21 +02:00
|
|
|
my %params=@_;
|
2008-10-16 01:38:21 +02:00
|
|
|
|
2010-06-23 23:35:21 +02:00
|
|
|
my ($file, $message, $token) =
|
|
|
|
($params{file}, $params{message}, $params{token});
|
2008-10-16 01:38:21 +02:00
|
|
|
|
|
|
|
# Compute if the "revision" of $file changed.
|
2010-06-23 23:35:21 +02:00
|
|
|
my $changed = darcs_rev($file) ne $token;
|
2008-10-16 01:38:21 +02:00
|
|
|
|
|
|
|
# Yes, the following is a bit convoluted.
|
|
|
|
if ($changed) {
|
2009-04-04 23:45:13 +02:00
|
|
|
# TODO. Invent a better, non-conflicting name.
|
|
|
|
rename("$config{srcdir}/$file", "$config{srcdir}/$file.save") or
|
|
|
|
error("failed to rename $file to $file.save: $!");
|
|
|
|
|
2010-06-23 23:35:21 +02:00
|
|
|
# Roll the repository back to $token.
|
2009-04-04 23:45:13 +02:00
|
|
|
|
|
|
|
# TODO. Can we be sure that no changes are lost? I think that
|
|
|
|
# we can, if we make sure that the 'darcs push' below will always
|
|
|
|
# succeed.
|
|
|
|
|
|
|
|
# We need to revert everything as 'darcs obliterate' might choke
|
|
|
|
# otherwise.
|
|
|
|
# TODO: 'yes | ...' needed? Doesn't seem so.
|
|
|
|
silentsystem('darcs', "revert", "--repodir", $config{srcdir}, "--all") == 0 ||
|
|
|
|
error("'darcs revert' failed");
|
2010-06-23 23:35:21 +02:00
|
|
|
# Remove all patches starting at $token.
|
2009-04-04 23:45:13 +02:00
|
|
|
my $child = open(DARCS_OBLITERATE, "|-");
|
|
|
|
if (! $child) {
|
|
|
|
open(STDOUT, ">/dev/null");
|
|
|
|
exec('darcs', "obliterate", "--repodir", $config{srcdir},
|
2010-06-23 23:35:21 +02:00
|
|
|
"--match", "hash " . $token) and
|
2009-04-04 23:45:13 +02:00
|
|
|
error("'darcs obliterate' failed");
|
|
|
|
}
|
|
|
|
1 while print DARCS_OBLITERATE "y";
|
|
|
|
close(DARCS_OBLITERATE);
|
2010-06-23 23:35:21 +02:00
|
|
|
# Restore the $token one.
|
2009-04-04 23:45:13 +02:00
|
|
|
silentsystem('darcs', "pull", "--quiet", "--repodir", $config{srcdir},
|
2010-06-23 23:35:21 +02:00
|
|
|
"--match", "hash " . $token, "--all") == 0 ||
|
2009-04-04 23:45:13 +02:00
|
|
|
error("'darcs pull' failed");
|
|
|
|
|
2010-06-23 23:35:21 +02:00
|
|
|
# We're back at $token. Re-install the modified file.
|
2009-04-04 23:45:13 +02:00
|
|
|
rename("$config{srcdir}/$file.save", "$config{srcdir}/$file") or
|
|
|
|
error("failed to rename $file.save to $file: $!");
|
2008-10-16 01:38:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Record the changes.
|
2010-06-23 23:35:21 +02:00
|
|
|
my $author=commitauthor(%params);
|
2008-10-16 01:38:21 +02:00
|
|
|
if (!defined $message || !length($message)) {
|
|
|
|
$message = "empty message";
|
|
|
|
}
|
|
|
|
silentsystem('darcs', 'record', '--repodir', $config{srcdir}, '--all',
|
2009-04-04 23:45:13 +02:00
|
|
|
'-m', $message, '--author', $author, $file) == 0 ||
|
2008-10-16 01:38:21 +02:00
|
|
|
error("'darcs record' failed");
|
|
|
|
|
|
|
|
# Update the repository by pulling from the default repository, which is
|
|
|
|
# master repository.
|
|
|
|
silentsystem('darcs', "pull", "--quiet", "--repodir", $config{srcdir},
|
2009-04-05 00:30:29 +02:00
|
|
|
"--all") == 0 || error("'darcs pull' failed");
|
2008-10-16 01:38:21 +02:00
|
|
|
|
|
|
|
# If this updating yields any conflicts, we'll record them now to resolve
|
|
|
|
# them. If nothing is recorded, there are no conflicts.
|
2010-06-23 23:35:21 +02:00
|
|
|
$token = darcs_rev($file);
|
2008-10-16 01:38:21 +02:00
|
|
|
# TODO: Use only the first line here, i.e. only the patch name?
|
|
|
|
writefile("$file.log", $config{srcdir}, 'resolve conflicts: ' . $message);
|
|
|
|
silentsystem('darcs', 'record', '--repodir', $config{srcdir}, '--all',
|
2009-04-04 23:45:13 +02:00
|
|
|
'-m', 'resolve conflicts: ' . $message, '--author', $author, $file) == 0 ||
|
2008-10-16 01:38:21 +02:00
|
|
|
error("'darcs record' failed");
|
2010-06-23 23:35:21 +02:00
|
|
|
my $conflicts = darcs_rev($file) ne $token;
|
2008-10-16 01:38:21 +02:00
|
|
|
unlink("$config{srcdir}/$file.log") or
|
2009-04-04 23:45:13 +02:00
|
|
|
error("failed to remove '$file.log'");
|
2008-10-16 01:38:21 +02:00
|
|
|
|
|
|
|
# Push the changes to the main repository.
|
2009-04-04 23:45:13 +02:00
|
|
|
silentsystem('darcs', 'push', '--quiet', '--repodir', $config{srcdir}, '--all') == 0 ||
|
|
|
|
error("'darcs push' failed");
|
2008-10-16 01:38:21 +02:00
|
|
|
# TODO: darcs send?
|
|
|
|
|
|
|
|
if ($conflicts) {
|
|
|
|
my $document = readfile("$config{srcdir}/$file");
|
|
|
|
# Try to leave everything in a consistent state.
|
|
|
|
# TODO: 'yes | ...' needed? Doesn't seem so.
|
2009-04-04 23:45:13 +02:00
|
|
|
silentsystem('darcs', "revert", "--repodir", $config{srcdir}, "--all") == 0 ||
|
2008-10-16 01:38:21 +02:00
|
|
|
warn("'darcs revert' failed");
|
|
|
|
return $document;
|
2009-04-04 23:45:13 +02:00
|
|
|
}
|
|
|
|
else {
|
2008-10-16 01:38:21 +02:00
|
|
|
return undef;
|
|
|
|
}
|
2008-10-01 23:24:06 +02:00
|
|
|
}
|
|
|
|
|
2010-06-23 23:35:21 +02:00
|
|
|
sub rcs_commit_staged (@) {
|
|
|
|
my %params=@_;
|
2008-10-16 01:38:21 +02:00
|
|
|
|
2010-06-23 23:35:21 +02:00
|
|
|
my $author=commitauthor(%params);
|
|
|
|
if (!defined $params{message} || !length($params{message})) {
|
|
|
|
$params{message} = "empty message";
|
2008-10-16 01:38:21 +02:00
|
|
|
}
|
|
|
|
|
2010-06-23 23:35:21 +02:00
|
|
|
silentsystem('darcs', "record", "--repodir", $config{srcdir},
|
|
|
|
"-a", "-A", $author,
|
|
|
|
"-m", $params{message},
|
|
|
|
) == 0 || error("'darcs record' failed");
|
2008-10-16 01:38:21 +02:00
|
|
|
|
|
|
|
# Push the changes to the main repository.
|
2009-04-04 23:45:13 +02:00
|
|
|
silentsystem('darcs', 'push', '--quiet', '--repodir', $config{srcdir}, '--all') == 0 ||
|
|
|
|
error("'darcs push' failed");
|
2008-10-16 01:38:21 +02:00
|
|
|
# TODO: darcs send?
|
|
|
|
|
|
|
|
return undef;
|
2008-10-01 23:24:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub rcs_add ($) {
|
2008-10-16 01:38:21 +02:00
|
|
|
my $file = shift; # Relative to the repodir.
|
2008-10-01 23:24:06 +02:00
|
|
|
|
2008-10-16 23:20:17 +02:00
|
|
|
if(! file_in_vc($config{srcdir}, $file)) {
|
|
|
|
# Intermediate directories will be added automagically.
|
|
|
|
system('darcs', 'add', '--quiet', '--repodir', $config{srcdir},
|
2009-04-04 23:45:13 +02:00
|
|
|
'--boring', $file) == 0 || error("'darcs add' failed");
|
2008-10-16 23:20:17 +02:00
|
|
|
}
|
2008-10-01 23:24:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub rcs_remove ($) {
|
2008-10-16 01:38:21 +02:00
|
|
|
my $file = shift; # Relative to the repodir.
|
2008-10-01 23:24:06 +02:00
|
|
|
|
2008-10-16 01:38:21 +02:00
|
|
|
unlink($config{srcdir}.'/'.$file);
|
2008-10-01 23:24:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub rcs_rename ($$) {
|
2008-10-16 01:38:21 +02:00
|
|
|
my $a = shift; # Relative to the repodir.
|
|
|
|
my $b = shift; # Relative to the repodir.
|
2008-10-01 23:24:06 +02:00
|
|
|
|
2009-04-04 23:45:13 +02:00
|
|
|
system('darcs', 'mv', '--repodir', $config{srcdir}, $a, $b) == 0 ||
|
|
|
|
error("'darcs mv' failed");
|
2008-10-01 23:24:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub rcs_recentchanges ($) {
|
2008-10-16 01:38:21 +02:00
|
|
|
my $num=shift;
|
|
|
|
my @ret;
|
|
|
|
|
|
|
|
eval q{use Date::Parse};
|
|
|
|
eval q{use XML::Simple};
|
|
|
|
|
|
|
|
my $repodir=$config{srcdir};
|
|
|
|
|
|
|
|
my $child = open(LOG, "-|");
|
|
|
|
if (! $child) {
|
|
|
|
$ENV{"DARCS_DONT_ESCAPE_ANYTHING"}=1;
|
|
|
|
exec("darcs", "changes", "--xml",
|
|
|
|
"--summary",
|
|
|
|
"--repodir", "$repodir",
|
|
|
|
"--last", "$num")
|
|
|
|
|| error("'darcs changes' failed to run");
|
|
|
|
}
|
|
|
|
my $data;
|
|
|
|
$data .= $_ while(<LOG>);
|
|
|
|
close LOG;
|
|
|
|
|
|
|
|
my $log = XMLin($data, ForceArray => 1);
|
|
|
|
|
|
|
|
foreach my $patch (@{$log->{patch}}) {
|
|
|
|
my $date=$patch->{local_date};
|
|
|
|
my $hash=$patch->{hash};
|
|
|
|
my $when=str2time($date);
|
|
|
|
my (@pages, @files, @pg);
|
2009-08-12 18:49:40 +02:00
|
|
|
push @pages, $_ foreach (@{$patch->{summary}->[0]->{modify_file}});
|
|
|
|
push @pages, $_ foreach (@{$patch->{summary}->[0]->{add_file}});
|
|
|
|
push @pages, $_ foreach (@{$patch->{summary}->[0]->{remove_file}});
|
2009-04-04 23:45:13 +02:00
|
|
|
foreach my $f (@pages) {
|
|
|
|
$f = $f->{content} if ref $f;
|
2008-10-16 01:38:21 +02:00
|
|
|
$f =~ s,^\s+,,; $f =~ s,\s+$,,; # cut whitespace
|
|
|
|
|
|
|
|
push @files, $f;
|
|
|
|
}
|
2009-04-04 23:45:13 +02:00
|
|
|
foreach my $p (@{$patch->{summary}->[0]->{move}}) {
|
2008-10-16 01:38:21 +02:00
|
|
|
push @files, $p->{from};
|
|
|
|
}
|
|
|
|
|
2009-04-04 23:45:13 +02:00
|
|
|
foreach my $f (@files) {
|
2008-10-16 01:38:21 +02:00
|
|
|
my $d = defined $config{'diffurl'} ? $config{'diffurl'} : "";
|
2012-03-13 16:49:29 +01:00
|
|
|
my $ef = uri_escape_utf8($f);
|
|
|
|
$d =~ s/\[\[file\]\]/$ef/go;
|
2008-10-16 01:38:21 +02:00
|
|
|
$d =~ s/\[\[hash\]\]/$hash/go;
|
|
|
|
|
|
|
|
push @pg, {
|
|
|
|
page => pagename($f),
|
|
|
|
diffurl => $d,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
next unless (scalar @pg > 0);
|
|
|
|
|
|
|
|
my @message;
|
2009-04-04 23:45:13 +02:00
|
|
|
push @message, { line => $_ } foreach (@{$patch->{name}});
|
2008-10-16 01:38:21 +02:00
|
|
|
|
|
|
|
my $committype;
|
2009-04-05 00:36:39 +02:00
|
|
|
my $author;
|
|
|
|
if ($patch->{author} =~ /(.*)\@web$/) {
|
|
|
|
$author = $1;
|
2008-10-16 01:38:21 +02:00
|
|
|
$committype = "web";
|
2009-04-04 23:45:13 +02:00
|
|
|
}
|
|
|
|
else {
|
2009-04-05 00:36:39 +02:00
|
|
|
$author=$patch->{author};
|
2008-10-16 01:38:21 +02:00
|
|
|
$committype = "darcs";
|
|
|
|
}
|
|
|
|
|
|
|
|
push @ret, {
|
|
|
|
rev => $patch->{hash},
|
2009-04-05 00:36:39 +02:00
|
|
|
user => $author,
|
2008-10-16 01:38:21 +02:00
|
|
|
committype => $committype,
|
|
|
|
when => $when,
|
|
|
|
message => [@message],
|
|
|
|
pages => [@pg],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return @ret;
|
2008-10-01 23:24:06 +02:00
|
|
|
}
|
|
|
|
|
2010-12-30 00:58:49 +01:00
|
|
|
sub rcs_diff ($;$) {
|
2008-10-16 01:38:21 +02:00
|
|
|
my $rev=shift;
|
2010-12-30 00:58:49 +01:00
|
|
|
my $maxlines=shift;
|
2008-10-16 01:38:21 +02:00
|
|
|
my @lines;
|
2011-03-02 17:39:58 +01:00
|
|
|
my $repodir=$config{srcdir};
|
|
|
|
foreach my $line (`darcs diff --repodir $repodir --match 'hash $rev'`) {
|
2008-10-16 01:38:21 +02:00
|
|
|
if (@lines || $line=~/^diff/) {
|
2010-12-30 00:58:49 +01:00
|
|
|
last if defined $maxlines && @lines == $maxlines;
|
2008-10-16 01:38:21 +02:00
|
|
|
push @lines, $line."\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wantarray) {
|
|
|
|
return @lines;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return join("", @lines);
|
|
|
|
}
|
2008-10-01 23:24:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub rcs_getctime ($) {
|
2008-10-16 01:38:21 +02:00
|
|
|
my $file=shift;
|
2008-10-01 23:24:06 +02:00
|
|
|
|
2008-10-16 01:38:21 +02:00
|
|
|
eval q{use Date::Parse};
|
|
|
|
eval q{use XML::Simple};
|
|
|
|
local $/=undef;
|
2008-10-01 23:24:06 +02:00
|
|
|
|
2008-10-16 01:38:21 +02:00
|
|
|
my $child = open(LOG, "-|");
|
|
|
|
if (! $child) {
|
|
|
|
exec("darcs", "changes", "--xml", "--reverse",
|
2010-06-24 01:32:53 +02:00
|
|
|
"--repodir", $config{srcdir}, $file)
|
|
|
|
|| error("'darcs changes $file' failed to run");
|
2008-10-16 01:38:21 +02:00
|
|
|
}
|
2008-10-01 23:24:06 +02:00
|
|
|
|
2008-10-16 01:38:21 +02:00
|
|
|
my $data;
|
2009-04-04 23:45:13 +02:00
|
|
|
{
|
|
|
|
local $/=undef;
|
|
|
|
$data = <LOG>;
|
|
|
|
}
|
2008-10-16 01:38:21 +02:00
|
|
|
close LOG;
|
2008-10-01 23:24:06 +02:00
|
|
|
|
2008-10-16 01:38:21 +02:00
|
|
|
my $log = XMLin($data, ForceArray => 1);
|
2008-10-01 23:24:06 +02:00
|
|
|
|
2009-04-04 23:45:13 +02:00
|
|
|
my $datestr = $log->{patch}[0]->{local_date};
|
2008-10-01 23:24:06 +02:00
|
|
|
|
2008-10-16 01:38:21 +02:00
|
|
|
if (! defined $datestr) {
|
2010-06-24 01:32:53 +02:00
|
|
|
warn "failed to get ctime for $file";
|
2008-10-16 01:38:21 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2008-10-01 23:24:06 +02:00
|
|
|
|
2009-04-04 23:45:13 +02:00
|
|
|
my $date = str2time($datestr);
|
|
|
|
|
|
|
|
debug("ctime for '$file': ". localtime($date));
|
2008-10-01 23:24:06 +02:00
|
|
|
|
2008-10-16 01:38:21 +02:00
|
|
|
return $date;
|
2008-10-01 23:24:06 +02:00
|
|
|
}
|
|
|
|
|
2010-04-16 23:02:29 +02:00
|
|
|
sub rcs_getmtime ($) {
|
|
|
|
error "rcs_getmtime is not implemented for darcs\n"; # TODO
|
|
|
|
}
|
|
|
|
|
2008-10-01 23:24:06 +02:00
|
|
|
1
|