[Python-checkins] hooks: Ensure that no terminal-specific formatting occurs in notification emails

local-hg python-checkins at python.org
Sun Mar 6 09:05:47 CET 2011


http://hg.python.org/hooks/rev/13ce3071824d
changeset:   49:13ce3071824d
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Sun Mar 06 09:05:47 2011 +0100
summary:
  Ensure that no terminal-specific formatting occurs in notification emails

files:
  hgbuildbot.py
  mail.py

diff --git a/hgbuildbot.py b/hgbuildbot.py
--- a/hgbuildbot.py
+++ b/hgbuildbot.py
@@ -54,7 +54,7 @@
         for k, v in change.items():
             # Yikes!
             if isinstance(v, localstr):
-                change[k] = fromlocal(v).decode('utf8')
+                change[k] = fromlocal(v).decode('utf8', 'replace')
         d.addCallback(send, change)
     d.addCallbacks(s.printSuccess, s.printFailure)
     d.addBoth(s.stop)
@@ -88,10 +88,11 @@
             # Explicitly compare current with its first parent (otherwise
             # some files might be "forgotten" if they are copied as-is from the
             # second parent).
-            modified, added, removed, deleted = repo.status(rev, p[0])[:4]
+            p1 = repo[hex(p[0])]
+            modified, added, removed, deleted = repo.status(rev, p1)[:4]
             files = set()
             for l in (modified, added, removed, deleted):
-                files.extend(l)
+                files.update(l)
             files = sorted(files)
             if not files:
                 # dummy merge, but at least one file is required by buildbot
@@ -101,7 +102,7 @@
         changes.append({
             'user': user,
             'revision': hex(node),
-            'comments': desc.decode('utf8', 'replace'),
+            'comments': desc,
             'revlink': (url % {'rev': hex(node)}) if url else '',
             'files': files,
             'branch': branch,
diff --git a/mail.py b/mail.py
--- a/mail.py
+++ b/mail.py
@@ -28,6 +28,10 @@
     smtp.close()
 
 def incoming(ui, repo, **kwargs):
+    # Ensure that no fancying of output is enabled (e.g. coloring)
+    os.environ['TERM'] = 'dumb'
+    ui.setconfig('ui', 'interactive', 'False')
+    ui.setconfig('ui', 'formatted', 'False')
 
     displayer = cmdutil.changeset_printer(ui, repo, False, False, True)
     ctx = repo[kwargs['node']]

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


More information about the Python-checkins mailing list