Mercurial > hg
comparison hgext/notify.py @ 37777:a4cac7b0ea4f
notify: add maxdiffstat option to truncate long file lists
Large scale changes like a new GCC version can easily result in 1MB+
emails due to diffstat alone. The new maxdiffstat option truncates the
list similar to what maxdiff already provides for the diffs.
Differential Revision: https://phab.mercurial-scm.org/D3402
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Tue, 17 Apr 2018 13:46:18 +0200 |
parents | f0b6fbea00cf |
children | a07fab68621f |
comparison
equal
deleted
inserted
replaced
37776:141017c7f7a9 | 37777:a4cac7b0ea4f |
---|---|
100 ``notify.template``. | 100 ``notify.template``. |
101 | 101 |
102 notify.maxdiff | 102 notify.maxdiff |
103 Maximum number of diff lines to include in notification email. Set to 0 | 103 Maximum number of diff lines to include in notification email. Set to 0 |
104 to disable the diff, or -1 to include all of it. Default: 300. | 104 to disable the diff, or -1 to include all of it. Default: 300. |
105 | |
106 notify.maxdiffstat | |
107 Maximum number of diffstat lines to include in notification email. Set to -1 | |
108 to include all of it. Default: -1. | |
105 | 109 |
106 notify.maxsubject | 110 notify.maxsubject |
107 Maximum number of characters in email's subject line. Default: 67. | 111 Maximum number of characters in email's subject line. Default: 67. |
108 | 112 |
109 notify.diffstat | 113 notify.diffstat |
181 configitem('notify', 'incoming', | 185 configitem('notify', 'incoming', |
182 default=None, | 186 default=None, |
183 ) | 187 ) |
184 configitem('notify', 'maxdiff', | 188 configitem('notify', 'maxdiff', |
185 default=300, | 189 default=300, |
190 ) | |
191 configitem('notify', 'maxdiffstat', | |
192 default=-1, | |
186 ) | 193 ) |
187 configitem('notify', 'maxsubject', | 194 configitem('notify', 'maxsubject', |
188 default=67, | 195 default=67, |
189 ) | 196 ) |
190 configitem('notify', 'mbox', | 197 configitem('notify', 'mbox', |
416 chunks = patch.diff(self.repo, prev, ref, | 423 chunks = patch.diff(self.repo, prev, ref, |
417 opts=patch.diffallopts(self.ui)) | 424 opts=patch.diffallopts(self.ui)) |
418 difflines = ''.join(chunks).splitlines() | 425 difflines = ''.join(chunks).splitlines() |
419 | 426 |
420 if self.ui.configbool('notify', 'diffstat'): | 427 if self.ui.configbool('notify', 'diffstat'): |
428 maxdiffstat = int(self.ui.config('notify', 'maxdiffstat')) | |
421 s = patch.diffstat(difflines) | 429 s = patch.diffstat(difflines) |
422 # s may be nil, don't include the header if it is | 430 # s may be nil, don't include the header if it is |
423 if s: | 431 if s: |
424 self.ui.write(_('\ndiffstat:\n\n%s') % s) | 432 if maxdiffstat >= 0 and s.count("\n") > maxdiffstat + 1: |
433 s = s.split("\n") | |
434 msg = _('\ndiffstat (truncated from %d to %d lines):\n\n') | |
435 self.ui.write(msg % (len(s) - 2, maxdiffstat)) | |
436 self.ui.write("\n".join(s[:maxdiffstat] + s[-2:])) | |
437 else: | |
438 self.ui.write(_('\ndiffstat:\n\n%s') % s) | |
425 | 439 |
426 if maxdiff == 0: | 440 if maxdiff == 0: |
427 return | 441 return |
428 elif maxdiff > 0 and len(difflines) > maxdiff: | 442 elif maxdiff > 0 and len(difflines) > maxdiff: |
429 msg = _('\ndiffs (truncated from %d to %d lines):\n\n') | 443 msg = _('\ndiffs (truncated from %d to %d lines):\n\n') |