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}->(@_);
|
$hooks{rcs}{rcs_recentchanges}{call}->(@_);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub rcs_diff ($) {
|
sub rcs_diff ($;$) {
|
||||||
$hooks{rcs}{rcs_diff}{call}->(@_);
|
$hooks{rcs}{rcs_diff}{call}->(@_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -271,8 +271,9 @@ sub rcs_recentchanges ($) {
|
||||||
return @ret;
|
return @ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub rcs_diff ($) {
|
sub rcs_diff ($;$) {
|
||||||
my $taintedrev=shift;
|
my $taintedrev=shift;
|
||||||
|
my $maxlines=shift;
|
||||||
my ($rev) = $taintedrev =~ /^(\d+(\.\d+)*)$/; # untaint
|
my ($rev) = $taintedrev =~ /^(\d+(\.\d+)*)$/; # untaint
|
||||||
|
|
||||||
my $prevspec = "before:" . $rev;
|
my $prevspec = "before:" . $rev;
|
||||||
|
@ -281,8 +282,11 @@ sub rcs_diff ($) {
|
||||||
"--new", $config{srcdir},
|
"--new", $config{srcdir},
|
||||||
"-r", $prevspec . ".." . $revspec);
|
"-r", $prevspec . ".." . $revspec);
|
||||||
open (my $out, "@cmdline |");
|
open (my $out, "@cmdline |");
|
||||||
|
my @lines;
|
||||||
my @lines = <$out>;
|
while (my $line=<$out>) {
|
||||||
|
last if defined $maxlines && @lines == $maxlines;
|
||||||
|
push @lines, $line;
|
||||||
|
}
|
||||||
if (wantarray) {
|
if (wantarray) {
|
||||||
return @lines;
|
return @lines;
|
||||||
}
|
}
|
||||||
|
|
|
@ -436,8 +436,9 @@ sub rcs_recentchanges ($) {
|
||||||
return @ret;
|
return @ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub rcs_diff ($) {
|
sub rcs_diff ($;$) {
|
||||||
my $rev=IkiWiki::possibly_foolish_untaint(int(shift));
|
my $rev=IkiWiki::possibly_foolish_untaint(int(shift));
|
||||||
|
my $maxlines=shift;
|
||||||
|
|
||||||
local $CWD = $config{srcdir};
|
local $CWD = $config{srcdir};
|
||||||
|
|
||||||
|
|
|
@ -373,11 +373,13 @@ sub rcs_recentchanges ($) {
|
||||||
return @ret;
|
return @ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub rcs_diff ($) {
|
sub rcs_diff ($;$) {
|
||||||
my $rev=shift;
|
my $rev=shift;
|
||||||
|
my $maxlines=shift;
|
||||||
my @lines;
|
my @lines;
|
||||||
foreach my $line (silentsystem("darcs", "diff", "--match", "hash ".$rev)) {
|
foreach my $line (silentsystem("darcs", "diff", "--match", "hash ".$rev)) {
|
||||||
if (@lines || $line=~/^diff/) {
|
if (@lines || $line=~/^diff/) {
|
||||||
|
last if defined $maxlines && @lines == $maxlines;
|
||||||
push @lines, $line."\n";
|
push @lines, $line."\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,10 +152,11 @@ sub genwrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub safe_git (&@) {
|
sub safe_git (&@) {
|
||||||
# Start a child process safely without resorting /bin/sh.
|
# Start a child process safely without resorting to /bin/sh.
|
||||||
# Return command output or success state (in scalar context).
|
# 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, "-|";
|
my $pid = open my $OUT, "-|";
|
||||||
|
|
||||||
|
@ -187,7 +188,12 @@ sub safe_git (&@) {
|
||||||
|
|
||||||
chomp;
|
chomp;
|
||||||
|
|
||||||
push @lines, $_;
|
if (! defined $data_handler) {
|
||||||
|
push @lines, $_;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
last unless $data_handler->($_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close $OUT;
|
close $OUT;
|
||||||
|
@ -197,9 +203,9 @@ sub safe_git (&@) {
|
||||||
return wantarray ? @lines : ($? == 0);
|
return wantarray ? @lines : ($? == 0);
|
||||||
}
|
}
|
||||||
# Convenient wrappers.
|
# Convenient wrappers.
|
||||||
sub run_or_die ($@) { safe_git(\&error, @_) }
|
sub run_or_die ($@) { safe_git(\&error, undef, @_) }
|
||||||
sub run_or_cry ($@) { safe_git(sub { warn @_ }, @_) }
|
sub run_or_cry ($@) { safe_git(sub { warn @_ }, undef, @_) }
|
||||||
sub run_or_non ($@) { safe_git(undef, @_) }
|
sub run_or_non ($@) { safe_git(undef, undef, @_) }
|
||||||
|
|
||||||
|
|
||||||
sub merge_past ($$$) {
|
sub merge_past ($$$) {
|
||||||
|
@ -663,15 +669,18 @@ sub rcs_recentchanges ($) {
|
||||||
return @rets;
|
return @rets;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub rcs_diff ($) {
|
sub rcs_diff ($;$) {
|
||||||
my $rev=shift;
|
my $rev=shift;
|
||||||
|
my $maxlines=shift;
|
||||||
my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint
|
my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint
|
||||||
my @lines;
|
my @lines;
|
||||||
foreach my $line (run_or_non("git", "show", $sha1)) {
|
my $addlines=sub {
|
||||||
if (@lines || $line=~/^diff --git/) {
|
my $line=shift;
|
||||||
push @lines, $line."\n";
|
return if defined $maxlines && @lines == $maxlines;
|
||||||
}
|
push @lines, $line."\n"
|
||||||
}
|
if (@lines || $line=~/^diff --git/);
|
||||||
|
};
|
||||||
|
safe_git(undef, $addlines, "git", "show", $sha1);
|
||||||
if (wantarray) {
|
if (wantarray) {
|
||||||
return @lines;
|
return @lines;
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,7 +229,7 @@ sub rcs_recentchanges ($) {
|
||||||
return @ret;
|
return @ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub rcs_diff ($) {
|
sub rcs_diff ($;$) {
|
||||||
# TODO
|
# TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -621,8 +621,9 @@ sub rcs_recentchanges ($) {
|
||||||
return @ret;
|
return @ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub rcs_diff ($) {
|
sub rcs_diff ($;$) {
|
||||||
my $rev=shift;
|
my $rev=shift;
|
||||||
|
my $maxlines=shift;
|
||||||
my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint
|
my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint
|
||||||
|
|
||||||
chdir $config{srcdir}
|
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");
|
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 $?");
|
close MTNDIFF || debug("mtn diff $sha1 exited $?");
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ sub rcs_rename ($$) {
|
||||||
sub rcs_recentchanges ($) {
|
sub rcs_recentchanges ($) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub rcs_diff ($) {
|
sub rcs_diff ($;$) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub rcs_getctime ($) {
|
sub rcs_getctime ($) {
|
||||||
|
|
|
@ -121,7 +121,7 @@ sub sessioncgi ($$) {
|
||||||
}
|
}
|
||||||
elsif ($form->submitted ne 'Cancel') {
|
elsif ($form->submitted ne 'Cancel') {
|
||||||
$form->title(sprintf(gettext("confirm reversion of %s"), $rev));
|
$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);
|
$form->field(name => "rev", type => "hidden", value => $rev, force => 1);
|
||||||
IkiWiki::showform($form, $buttons, $session, $q);
|
IkiWiki::showform($form, $buttons, $session, $q);
|
||||||
exit 0;
|
exit 0;
|
||||||
|
|
|
@ -28,11 +28,10 @@ sub pagetemplate (@) {
|
||||||
my $template=$params{template};
|
my $template=$params{template};
|
||||||
if ($config{rcs} && exists $params{rev} && length $params{rev} &&
|
if ($config{rcs} && exists $params{rev} && length $params{rev} &&
|
||||||
$template->query(name => "diff")) {
|
$template->query(name => "diff")) {
|
||||||
my @lines=IkiWiki::rcs_diff($params{rev});
|
my @lines=IkiWiki::rcs_diff($params{rev}, $maxlines+1);
|
||||||
if (@lines) {
|
if (@lines) {
|
||||||
my $diff;
|
my $diff;
|
||||||
if (@lines > $maxlines) {
|
if (@lines > $maxlines) {
|
||||||
# only include so many lines of diff
|
|
||||||
$diff=join("", @lines[0..($maxlines-1)])."\n".
|
$diff=join("", @lines[0..($maxlines-1)])."\n".
|
||||||
gettext("(Diff truncated)");
|
gettext("(Diff truncated)");
|
||||||
}
|
}
|
||||||
|
|
|
@ -345,8 +345,9 @@ sub rcs_recentchanges ($) {
|
||||||
return @ret;
|
return @ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub rcs_diff ($) {
|
sub rcs_diff ($;$) {
|
||||||
my $rev=IkiWiki::possibly_foolish_untaint(int(shift));
|
my $rev=IkiWiki::possibly_foolish_untaint(int(shift));
|
||||||
|
my $maxlines=shift;
|
||||||
return `svnlook diff $config{svnrepo} -r$rev --no-diff-deleted`;
|
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)
|
versions of the monotone binary. (tommyd3mdi)
|
||||||
* highlight: Support highlight 3.2+svn19 (note that released version 3.2
|
* highlight: Support highlight 3.2+svn19 (note that released version 3.2
|
||||||
is not supported). Closes: #605779 (David Bremner)
|
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
|
-- 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
|
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($)`
|
#### `rcs_getctime($)`
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue