Subject: | Patch to allow truncation of long diff output |
Really large diff attachments were making our mail clients drag so
we added a -T (truncate diffs) option to activitymail locally to only give a limited amount (50 lines) of diff output where the diff is larger than a size given to the -T option.
Full diffs are given as usual if -T isn't specified.
I've attached a patch, it would be nice to get this added to the main distribution if you think that it would be of use to other people also.
--- activitymail.orig Sat Dec 10 08:41:24 2005
+++ activitymail Mon Dec 12 13:24:57 2005
@@ -37,9 +37,9 @@
use vars qw($opt_f $opt_r $opt_l $opt_m $opt_t $opt_n $opt_i $opt_p $opt_c
$opt_s $opt_h $opt_d $opt_a $opt_D $opt_o $opt_e $opt_u $opt_g
$opt_w $opt_H $opt_B $opt_j $opt_M $opt_S $opt_v $opt_V $opt_N
- $opt_I $opt_E $opt_q $opt_Q $opt_P $opt_U
+ $opt_I $opt_E $opt_q $opt_Q $opt_P $opt_U $opt_T
);
- getopts('f:lr:m:t:nipcs:dhaDo:e:u:gw:HB:j:M:SvVN:I:E:qQP:U');
+ getopts('f:lr:m:t:nipcs:dhaDo:e:u:gw:HB:j:M:SvVN:I:E:qQP:UT:');
}
##############################################################################
@@ -434,23 +434,33 @@
# to be passed to diff are okay when the whole argument is in
# quotation marks.
$fn =~ s/\s+/_/g if $opt_U;
+ my $fdiff;
if ($r1 eq 'NONE') {
# It's a new file.
if (-e $file) {
# Compare to /dev/null.
- $diffs .= `$opt_j $opt_o -L '$opt_N' '$opt_N' -L '$fn' '$file'`;
+ $fdiff = `$opt_j $opt_o -L '$opt_N' '$opt_N' -L '$fn' '$file'`;
} else {
# Otherwise, read the file from a non-changing update and pipe
# that to diff.
- $diffs .= `$opt_e -fn update -r $r2 -p '$file' | $opt_j $opt_o -L '$opt_N' '$opt_N' -L '$fn' -`;
+ $fdiff = `$opt_e -fn update -r $r2 -p '$file' | $opt_j $opt_o -L '$opt_N' '$opt_N' -L '$fn' -`;
}
} elsif ($r2 eq 'NONE') {
# The file has been deleted. Read it from a non-changing update
# and pipe it to diff.
- $diffs .= `$opt_e -fn update -r $r1 -p '$file' | $opt_j $opt_o -L '$fn' - -L '$opt_N' '$opt_N'`;
+ $fdiff = `$opt_e -fn update -r $r1 -p '$file' | $opt_j $opt_o -L '$fn' - -L '$opt_N' '$opt_N'`;
} else {
# We actually have CVS diff the two versions.
- $diffs .= `$opt_e -f diff -kk -L '$fn' -L '$fn' $opt_o -r $r1 -r $r2 '$file'`;
+ $fdiff = `$opt_e -f diff -kk -L '$fn' -L '$fn' $opt_o -r $r1 -r $r2 '$file'`;
+ }
+
+ if (defined($opt_T) && length($fdiff) > $opt_T) {
+ $fdiff =~ s/^((?:[^\n]*\n){50}).*$/$1/sm;
+ $fdiff .= "\n[...]\n\ndiff output truncated";
+ $fdiff .= " (exceeded maximum length of $opt_T characters)\n";
+ $diffs .= $fdiff;
+ } else {
+ $diffs .= $fdiff;
}
}
return $diffs;
@@ -957,6 +967,7 @@
-u <email> User email address from which email should be sent.
-g Use \$USER environment variable to group commits.
-M <size> Maximum size of emailed messages in kilobytes.
+ -T <size> Maximum size of diff output for any file.
-V Include revision numbers in the email message.
-H Use HTML for generated emails.
-w <url> Include links to specified CVSWeb url in email.
@@ -1183,6 +1194,12 @@
instead. This option is useful if your repository contains large binary files
not prevented from be diffed by C<-B>, or when adding many files at once.
In those cases, failing to use this option may result in broken mail clients.
+
+=item -T <size>
+
+Max length for diff output to be attached to email messages, in characters. If
+diff output greater than this size would be attached then the first 10 lines are
+returned with a message explaining that the diff output has been truncated.
=item -V