[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] mailer.py: truncate_diff_lines feature

From: Alan Barrett <apb_at_cequrux.com>
Date: 2005-11-02 14:00:08 CET

[[[
Add truncate_diff_lines feature to mailer.py hook script. If this
is set to a non-zero value, then diffs longer than the specified
number of lines will be truncated in email messages.

mailer.py (TextCommitRenderer::generate_content): Obtain
truncate_diff_lines value from cfg, and pass it through in the data sent
to renderer.render().
(TextCommitRenderer::render): Pass data.truncate_diff_lines through to
self._render_diffs().
(TextCommitRenderer::render::_render_diffs): New truncate_diff_lines
arg, and new logic to implement the truncation.
mailer.conf.example: Add commented-out example for truncate_diff_lines.
]]]
=== tools/hook-scripts/mailer.py
==================================================================
--- mailer.py (revision 18531)
+++ mailer.py (revision 18532)
@@ -589,6 +589,12 @@
   show_nonmatching_paths = cfg.get('show_nonmatching_paths', group, params) \
       or 'yes'
 
+ try:
+ truncate_diff_lines = int(
+ cfg.get('truncate_diff_lines', group, params))
+ except ValueError:
+ truncate_diff_lines = 0
+
   # figure out the lists of changes outside the selected path-space
   other_added_data = other_removed_data = other_modified_data = [ ]
   if len(paths) != len(changelist) and show_nonmatching_paths != 'no':
@@ -617,6 +623,7 @@
     diffs=DiffGenerator(changelist, paths, True, cfg, repos, date, group,
                         params, diffsels, diffurls, pool),
     other_diffs=other_diffs,
+ truncate_diff_lines=truncate_diff_lines,
     )
   renderer.render(data)
 
@@ -900,10 +907,10 @@
 
     w('\nLog:\n%s\n' % data.log)
 
- self._render_diffs(data.diffs)
+ self._render_diffs(data.diffs, data.truncate_diff_lines)
     if data.other_diffs:
       w('\nDiffs of changes in other areas also in this revision:\n')
- self._render_diffs(data.other_diffs)
+ self._render_diffs(data.other_diffs, data.truncate_diff_lines)
 
   def _render_list(self, header, data_list):
     if not data_list:
@@ -934,7 +941,7 @@
         w(' - copied%s from r%d, %s%s\n'
           % (text, d.base_rev, d.base_path, is_dir))
 
- def _render_diffs(self, diffs):
+ def _render_diffs(self, diffs, truncate_diff_lines):
     w = self.output.write
 
     for diff in diffs:
@@ -971,8 +978,15 @@
           w('Binary files. No diff available.\n')
         continue
 
+ nlines = 0
       for line in diff.content:
- w(line.raw)
+ if truncate_diff_lines > 0 and nlines >= truncate_diff_lines:
+ w('*** Diff too large. Truncated after %d lines.\n' \
+ % (truncate_diff_lines))
+ break
+ else:
+ w(line.raw)
+ nlines = nlines + 1
 
 
 class Repository:
=== tools/hook-scripts/mailer.conf.example
==================================================================
--- mailer.conf.example (revision 18531)
+++ mailer.conf.example (revision 18532)
@@ -224,6 +224,12 @@
 # Set to 0 to turn off.
 #truncate_subject = 200
 
+# Diff length limit. The generated diff will be truncated after this many
+# lines. The limit applies independently to each file for which a diff
+# is generated.
+# Set to 0 to turn off.
+#truncate_diff_lines = 200
+
 # --------------------------------------------------------------------------
 
 [maps]

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Nov 2 14:11:52 2005

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.