aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/git.pm
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2010-12-29 19:58:49 -0400
committerJoey Hess <joey@kitenet.net>2010-12-29 19:58:49 -0400
commit4fb26f4e60f2df282fc972e4b8506ccd306de789 (patch)
treeba95769fbc59a296364076fd2e649f3ebc0438af /IkiWiki/Plugin/git.pm
parent7d48813166c637e5bb2e11ef690fc7521716bd31 (diff)
downloadikiwiki-4fb26f4e60f2df282fc972e4b8506ccd306de789.tar
ikiwiki-4fb26f4e60f2df282fc972e4b8506ccd306de789.tar.gz
Add a second parameter to the rcs_diff hook, and avoid bloating memory reading in enormous commits.
Diffstat (limited to 'IkiWiki/Plugin/git.pm')
-rw-r--r--IkiWiki/Plugin/git.pm35
1 files changed, 22 insertions, 13 deletions
diff --git a/IkiWiki/Plugin/git.pm b/IkiWiki/Plugin/git.pm
index 3db4af729..52b2bbd50 100644
--- a/IkiWiki/Plugin/git.pm
+++ b/IkiWiki/Plugin/git.pm
@@ -152,10 +152,11 @@ sub genwrapper {
}
sub safe_git (&@) {
- # Start a child process safely without resorting /bin/sh.
- # Return command output or success state (in scalar context).
+ # Start a child process safely without resorting to /bin/sh.
+ # Returns command output (in list content) or success state
+ # (in scalar context), or runs the specified data handler.
- my ($error_handler, @cmdline) = @_;
+ my ($error_handler, $data_handler, @cmdline) = @_;
my $pid = open my $OUT, "-|";
@@ -187,7 +188,12 @@ sub safe_git (&@) {
chomp;
- push @lines, $_;
+ if (! defined $data_handler) {
+ push @lines, $_;
+ }
+ else {
+ last unless $data_handler->($_);
+ }
}
close $OUT;
@@ -197,9 +203,9 @@ sub safe_git (&@) {
return wantarray ? @lines : ($? == 0);
}
# Convenient wrappers.
-sub run_or_die ($@) { safe_git(\&error, @_) }
-sub run_or_cry ($@) { safe_git(sub { warn @_ }, @_) }
-sub run_or_non ($@) { safe_git(undef, @_) }
+sub run_or_die ($@) { safe_git(\&error, undef, @_) }
+sub run_or_cry ($@) { safe_git(sub { warn @_ }, undef, @_) }
+sub run_or_non ($@) { safe_git(undef, undef, @_) }
sub merge_past ($$$) {
@@ -663,15 +669,18 @@ sub rcs_recentchanges ($) {
return @rets;
}
-sub rcs_diff ($) {
+sub rcs_diff ($;$) {
my $rev=shift;
+ my $maxlines=shift;
my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint
my @lines;
- foreach my $line (run_or_non("git", "show", $sha1)) {
- if (@lines || $line=~/^diff --git/) {
- push @lines, $line."\n";
- }
- }
+ my $addlines=sub {
+ my $line=shift;
+ return if defined $maxlines && @lines == $maxlines;
+ push @lines, $line."\n"
+ if (@lines || $line=~/^diff --git/);
+ };
+ safe_git(undef, $addlines, "git", "show", $sha1);
if (wantarray) {
return @lines;
}