Mercurial > public > mercurial-scm > hg
diff 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 |
line wrap: on
line diff
--- a/hgext/notify.py Fri Apr 13 23:45:07 2018 +0900 +++ b/hgext/notify.py Tue Apr 17 13:46:18 2018 +0200 @@ -103,6 +103,10 @@ Maximum number of diff lines to include in notification email. Set to 0 to disable the diff, or -1 to include all of it. Default: 300. +notify.maxdiffstat + Maximum number of diffstat lines to include in notification email. Set to -1 + to include all of it. Default: -1. + notify.maxsubject Maximum number of characters in email's subject line. Default: 67. @@ -184,6 +188,9 @@ configitem('notify', 'maxdiff', default=300, ) +configitem('notify', 'maxdiffstat', + default=-1, +) configitem('notify', 'maxsubject', default=67, ) @@ -418,10 +425,17 @@ difflines = ''.join(chunks).splitlines() if self.ui.configbool('notify', 'diffstat'): + maxdiffstat = int(self.ui.config('notify', 'maxdiffstat')) s = patch.diffstat(difflines) # s may be nil, don't include the header if it is if s: - self.ui.write(_('\ndiffstat:\n\n%s') % s) + if maxdiffstat >= 0 and s.count("\n") > maxdiffstat + 1: + s = s.split("\n") + msg = _('\ndiffstat (truncated from %d to %d lines):\n\n') + self.ui.write(msg % (len(s) - 2, maxdiffstat)) + self.ui.write("\n".join(s[:maxdiffstat] + s[-2:])) + else: + self.ui.write(_('\ndiffstat:\n\n%s') % s) if maxdiff == 0: return