[darcs-users] using posthook to generate HTML documentation
Nathan Gray
kolibrie at graystudios.org
Tue Jun 12 15:05:24 UTC 2007
On Mon, Jun 11, 2007 at 10:29:03AM -0400, Max Battcher wrote:
> You could try to check the patch timestamp... I hadn't thought to try
> that before so I'm not sure how well it works or if darcs guarantees
> anything about the timestamps. You can then take the file name, which
> is also the patch's hash and pass that to ``darcs changes -s
> --xml-output --matches="hash {filename}"``... That should work. I'm
> surprised I didn't think of checking patch timestamps before, it
> certainly might simplify a couple of my own posthooks...
I wrote a little perl script to read through the patches and set up a
posthook to write the affected files to _darcs/prefs/applied_files.
Here is my posthook:
apply posthook /usr/local/bin/applied_patches.pl 15 > _darcs/prefs/applied_patches; /usr/local/bin/applied_patches.pl --files 15 > _darcs/prefs/applied_files
apply run-posthook
The '15' means to list all files with timestamps less than 15 seconds
old. Not perfect, but accurate enough for what I am doing.
If I start using these files for obliterating (during failed
deployment, for instance), I may need them to be more exact.
Below is my 'applied_patches.pl' perl script (also not perfect, but I
wanted to send it out before I forget).
-kolibrie
#!/usr/bin/perl
use Getopt::Long;
my %param = ();
GetOptions(\%param, 'files!', 'h|help!');
usage() if $param{h};
sub usage {
print qq{Usage: $0 [--files] [AGE]
--files list files affected instead of patch ids
AGE only list patches applied within the last AGE seconds\n\n};
exit;
}
my $age = shift(@ARGV) || 0;
my $time = time - $age;
my %shown = ();
my $recent_patches = interesting_files(sub { $_[0] =~ /\.gz$/ and (stat($_[0]))[9] >= $time }, '_darcs/patches');
while (my $patch_file = $recent_patches->()) {
#print $patch_file . "\n";
(my $patch_id = $patch_file) =~ s/^.*\///;
if ($param{files}) {
my $summary = `darcs changes -s --matches "hash $patch_id"`;
my @files = $summary =~ m/\s+[AM]\s(\S+)/g;
foreach my $file (@files) {
print "$file\n" unless ($shown{$file}++);
}
} else {
print $patch_id . "\n";
}
}
sub interesting_files {
# from 'Higher-Order Perl' by Mark Jason Dominus
my $is_interesting = shift;
my @queue = @_;
return sub {
while (@queue) {
my $file = shift(@queue);
if (-d $file) {
opendir my $dh, $file or next;
my @newfiles = grep { $_ ne '.' and $_ ne '..' } readdir $dh;
push @queue, map { "$file/$_" } @newfiles;
}
return $file if $is_interesting->($file);
}
return;
};
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.osuosl.org/pipermail/darcs-users/attachments/20070612/72ba87ae/attachment.pgp
More information about the darcs-users
mailing list