[Python-checkins] hooks: Add a diff-blacklist option to omit selected files from email notification

local-hg python-checkins at python.org
Tue Jun 19 16:34:15 CEST 2012


http://hg.python.org/hooks/rev/885b48eeae7d
changeset:   81:885b48eeae7d
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Tue Jun 19 16:34:15 2012 +0200
summary:
  Add a diff-blacklist option to omit selected files from email notification diffs.

files:
  mail.py |  17 +++++++++++++++++
  1 files changed, 17 insertions(+), 0 deletions(-)


diff --git a/mail.py b/mail.py
--- a/mail.py
+++ b/mail.py
@@ -19,6 +19,7 @@
 BASE = 'http://hg.python.org/'
 CSET_URL = BASE + '%s/rev/%s'
 
+
 def send(sub, sender, to, body):
     msg = MIMEMultipart()
     msg['Subject'] = Header(sub, 'utf8')
@@ -45,6 +46,19 @@
         stripped.append(chunk)
     return stripped
 
+def strip_blacklisted_files(chunks, blacklisted):
+    stripped = []
+    for chunk in chunks:
+        lines = chunk.splitlines(True)
+        for i, line in enumerate(lines[:4]):
+            if (line.startswith('+++ b/') and
+                line[6:].rstrip() in blacklisted):
+                lines = lines[:i+1] + ['[stripped]\n']
+                chunk = ''.join(lines)
+                break
+        stripped.append(chunk)
+    return stripped
+
 def _incoming(ui, repo, **kwargs):
     # Ensure that no fancying of output is enabled (e.g. coloring)
     os.environ['TERM'] = 'dumb'
@@ -57,6 +71,8 @@
     else:
         colormod._styles.clear()
 
+    blacklisted = ui.config('mail', 'diff-blacklist', '').split()
+
     displayer = cmdutil.changeset_printer(ui, repo, False, False, True)
     ctx = repo[kwargs['node']]
     displayer.show(ctx)
@@ -83,6 +99,7 @@
         body.append(' ' + line)
     body += ['', '']
     diffchunks = strip_bin_diffs(diffchunks)
+    diffchunks = strip_blacklisted_files(diffchunks, blacklisted)
     body.append(''.join(chunk for chunk in diffchunks))
 
     body.append('-- ')

-- 
Repository URL: http://hg.python.org/hooks


More information about the Python-checkins mailing list