Add a second parameter to the rcs_diff hook, and avoid bloating memory reading in enormous commits.
parent
7d48813166
commit
4fb26f4e60
|
@ -2033,7 +2033,7 @@ sub rcs_recentchanges ($) {
|
|||
$hooks{rcs}{rcs_recentchanges}{call}->(@_);
|
||||
}
|
||||
|
||||
sub rcs_diff ($) {
|
||||
sub rcs_diff ($;$) {
|
||||
$hooks{rcs}{rcs_diff}{call}->(@_);
|
||||
}
|
||||
|
||||
|
|
|
@ -271,8 +271,9 @@ sub rcs_recentchanges ($) {
|
|||
return @ret;
|
||||
}
|
||||
|
||||
sub rcs_diff ($) {
|
||||
sub rcs_diff ($;$) {
|
||||
my $taintedrev=shift;
|
||||
my $maxlines=shift;
|
||||
my ($rev) = $taintedrev =~ /^(\d+(\.\d+)*)$/; # untaint
|
||||
|
||||
my $prevspec = "before:" . $rev;
|
||||
|
@ -281,8 +282,11 @@ sub rcs_diff ($) {
|
|||
"--new", $config{srcdir},
|
||||
"-r", $prevspec . ".." . $revspec);
|
||||
open (my $out, "@cmdline |");
|
||||
|
||||
my @lines = <$out>;
|
||||
my @lines;
|
||||
while (my $line=<$out>) {
|
||||
last if defined $maxlines && @lines == $maxlines;
|
||||
push @lines, $line;
|
||||
}
|
||||
if (wantarray) {
|
||||
return @lines;
|
||||
}
|
||||
|
|
|
@ -436,8 +436,9 @@ sub rcs_recentchanges ($) {
|
|||
return @ret;
|
||||
}
|
||||
|
||||
sub rcs_diff ($) {
|
||||
sub rcs_diff ($;$) {
|
||||
my $rev=IkiWiki::possibly_foolish_untaint(int(shift));
|
||||
my $maxlines=shift;
|
||||
|
||||
local $CWD = $config{srcdir};
|
||||
|
||||
|
|
|
@ -373,11 +373,13 @@ sub rcs_recentchanges ($) {
|
|||
return @ret;
|
||||
}
|
||||
|
||||
sub rcs_diff ($) {
|
||||
sub rcs_diff ($;$) {
|
||||
my $rev=shift;
|
||||
my $maxlines=shift;
|
||||
my @lines;
|
||||
foreach my $line (silentsystem("darcs", "diff", "--match", "hash ".$rev)) {
|
||||
if (@lines || $line=~/^diff/) {
|
||||
last if defined $maxlines && @lines == $maxlines;
|
||||
push @lines, $line."\n";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -229,7 +229,7 @@ sub rcs_recentchanges ($) {
|
|||
return @ret;
|
||||
}
|
||||
|
||||
sub rcs_diff ($) {
|
||||
sub rcs_diff ($;$) {
|
||||
# TODO
|
||||
}
|
||||
|
||||
|
|
|
@ -621,8 +621,9 @@ sub rcs_recentchanges ($) {
|
|||
return @ret;
|
||||
}
|
||||
|
||||
sub rcs_diff ($) {
|
||||
sub rcs_diff ($;$) {
|
||||
my $rev=shift;
|
||||
my $maxlines=shift;
|
||||
my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint
|
||||
|
||||
chdir $config{srcdir}
|
||||
|
@ -633,7 +634,11 @@ sub rcs_diff ($) {
|
|||
exec("mtn", "diff", "--root=$config{mtnrootdir}", "-r", "p:".$sha1, "-r", $sha1) || error("mtn diff $sha1 failed to run");
|
||||
}
|
||||
|
||||
my (@lines) = <MTNDIFF>;
|
||||
my @lines;
|
||||
while (my $line=<MTNDIFF>) {
|
||||
last if defined $maxlines && @lines == $maxlines;
|
||||
push @lines, $line;
|
||||
}
|
||||
|
||||
close MTNDIFF || debug("mtn diff $sha1 exited $?");
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ sub rcs_rename ($$) {
|
|||
sub rcs_recentchanges ($) {
|
||||
}
|
||||
|
||||
sub rcs_diff ($) {
|
||||
sub rcs_diff ($;$) {
|
||||
}
|
||||
|
||||
sub rcs_getctime ($) {
|
||||
|
|
|
@ -121,7 +121,7 @@ sub sessioncgi ($$) {
|
|||
}
|
||||
elsif ($form->submitted ne 'Cancel') {
|
||||
$form->title(sprintf(gettext("confirm reversion of %s"), $rev));
|
||||
$form->tmpl_param(diff => encode_entities(scalar IkiWiki::rcs_diff($rev)));
|
||||
$form->tmpl_param(diff => encode_entities(scalar IkiWiki::rcs_diff($rev, 200)));
|
||||
$form->field(name => "rev", type => "hidden", value => $rev, force => 1);
|
||||
IkiWiki::showform($form, $buttons, $session, $q);
|
||||
exit 0;
|
||||
|
|
|
@ -28,11 +28,10 @@ sub pagetemplate (@) {
|
|||
my $template=$params{template};
|
||||
if ($config{rcs} && exists $params{rev} && length $params{rev} &&
|
||||
$template->query(name => "diff")) {
|
||||
my @lines=IkiWiki::rcs_diff($params{rev});
|
||||
my @lines=IkiWiki::rcs_diff($params{rev}, $maxlines+1);
|
||||
if (@lines) {
|
||||
my $diff;
|
||||
if (@lines > $maxlines) {
|
||||
# only include so many lines of diff
|
||||
$diff=join("", @lines[0..($maxlines-1)])."\n".
|
||||
gettext("(Diff truncated)");
|
||||
}
|
||||
|
|
|
@ -345,8 +345,9 @@ sub rcs_recentchanges ($) {
|
|||
return @ret;
|
||||
}
|
||||
|
||||
sub rcs_diff ($) {
|
||||
sub rcs_diff ($;$) {
|
||||
my $rev=IkiWiki::possibly_foolish_untaint(int(shift));
|
||||
my $maxlines=shift;
|
||||
return `svnlook diff $config{svnrepo} -r$rev --no-diff-deleted`;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ ikiwiki (3.20101202) UNRELEASED; urgency=low
|
|||
versions of the monotone binary. (tommyd3mdi)
|
||||
* highlight: Support highlight 3.2+svn19 (note that released version 3.2
|
||||
is not supported). Closes: #605779 (David Bremner)
|
||||
* Add a second parameter to the rcs_diff hook, and avoid bloating memory
|
||||
reading in enormous commits.
|
||||
|
||||
-- Joey Hess <joeyh@debian.org> Mon, 29 Nov 2010 14:44:13 -0400
|
||||
|
||||
|
|
|
@ -1151,11 +1151,13 @@ The data structure returned for each change is:
|
|||
],
|
||||
}
|
||||
|
||||
#### `rcs_diff($)`
|
||||
#### `rcs_diff($;$)`
|
||||
|
||||
The first parameter is the rev from `rcs_recentchanges`.
|
||||
The optional second parameter is how many lines to return (default: all).
|
||||
|
||||
The parameter is the rev from `rcs_recentchanges`.
|
||||
Should return a list of lines of the diff (including \n) in list
|
||||
context, and the whole diff in scalar context.
|
||||
context, and a string containing the whole diff in scalar context.
|
||||
|
||||
#### `rcs_getctime($)`
|
||||
|
||||
|
|
Loading…
Reference in New Issue