[Python-checkins] hooks: Remove binary diffs from commit e-mails

local-hg python-checkins at python.org
Mon Apr 16 17:58:29 CEST 2012


http://hg.python.org/hooks/rev/c3442040f1d0
changeset:   79:c3442040f1d0
user:        hg repo admin <python-dev at python.org>
date:        Mon Apr 16 17:58:29 2012 +0200
summary:
  Remove binary diffs from commit e-mails

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


diff --git a/mail.py b/mail.py
--- a/mail.py
+++ b/mail.py
@@ -30,6 +30,20 @@
     smtp.sendmail(sender, to, msg.as_string())
     smtp.close()
 
+def strip_bin_diffs(chunks):
+    stripped = []
+    for chunk in chunks:
+        lines = chunk.splitlines(True)
+        try:
+            i = lines.index('GIT binary patch\n')
+        except ValueError:
+            pass
+        else:
+            lines = lines[:i+1] + ['[stripped]\n']
+            chunk = ''.join(lines)
+        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'
@@ -67,6 +81,7 @@
     for line in iterlines([''.join(diffstat)]):
         body.append(' ' + line)
     body += ['', '']
+    diffchunks = strip_bin_diffs(diffchunks)
     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