changeset 3739:16f8e7d1dd54

fix notify with new ui buffering
author Matt Mackall <mpm@selenic.com>
date Fri, 01 Dec 2006 01:28:20 -0600
parents cb48cd27d3f4
children aef384dbc731
files hgext/notify.py
diffstat 1 files changed, 16 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/notify.py	Fri Dec 01 01:28:19 2006 -0600
+++ b/hgext/notify.py	Fri Dec 01 01:28:20 2006 -0600
@@ -68,7 +68,7 @@
 from mercurial.demandload import *
 from mercurial.i18n import gettext as _
 from mercurial.node import *
-demandload(globals(), 'mercurial:commands,patch,cmdutil,templater,util,mail')
+demandload(globals(), 'mercurial:patch,cmdutil,templater,util,mail')
 demandload(globals(), 'email.Parser fnmatch socket time')
 
 # template for single changeset can include email headers.
@@ -107,14 +107,13 @@
         self.stripcount = int(self.ui.config('notify', 'strip', 0))
         self.root = self.strip(self.repo.root)
         self.domain = self.ui.config('notify', 'domain')
-        self.sio = cmdutil.stringio()
         self.subs = self.subscribers()
 
         mapfile = self.ui.config('notify', 'style')
         template = (self.ui.config('notify', hooktype) or
                     self.ui.config('notify', 'template'))
-        self.t = cmdutil.changeset_templater(self.ui, self.repo, mapfile,
-                                               self.sio)
+        self.t = cmdutil.changeset_templater(self.ui, self.repo,
+                                             False, None, mapfile, False)
         if not mapfile and not template:
             template = deftemplates.get(hooktype) or single_template
         if template:
@@ -177,12 +176,11 @@
         ok_sources = self.ui.config('notify', 'sources', 'serve').split()
         return source not in ok_sources
 
-    def send(self, node, count):
+    def send(self, node, count, data):
         '''send message.'''
 
         p = email.Parser.Parser()
-        self.sio.seek(0)
-        msg = p.parse(self.sio)
+        msg = p.parsestr(data)
 
         def fix_subject():
             '''try to make subject line exist and be useful.'''
@@ -237,20 +235,20 @@
         maxdiff = int(self.ui.config('notify', 'maxdiff', 300))
         if maxdiff == 0:
             return
-        fp = cmdutil.stringio()
         prev = self.repo.changelog.parents(node)[0]
-        patch.diff(self.repo, prev, ref, fp=fp)
-        difflines = fp.getvalue().splitlines(1)
+        self.ui.pushbuffer()
+        patch.diff(self.repo, prev, ref)
+        difflines = self.ui.popbuffer().splitlines(1)
         if self.ui.configbool('notify', 'diffstat', True):
             s = patch.diffstat(difflines)
-            self.sio.write('\ndiffstat:\n\n' + s)
+            self.ui.write('\ndiffstat:\n\n' + s)
         if maxdiff > 0 and len(difflines) > maxdiff:
-            self.sio.write(_('\ndiffs (truncated from %d to %d lines):\n\n') %
-                           (len(difflines), maxdiff))
+            self.ui.write(_('\ndiffs (truncated from %d to %d lines):\n\n') %
+                          (len(difflines), maxdiff))
             difflines = difflines[:maxdiff]
         elif difflines:
-            self.sio.write(_('\ndiffs (%d lines):\n\n') % len(difflines))
-        self.sio.write(*difflines)
+            self.ui.write(_('\ndiffs (%d lines):\n\n') % len(difflines))
+        self.ui.write(*difflines)
 
 def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
     '''send email notifications to interested subscribers.
@@ -266,6 +264,7 @@
                   source)
         return
     node = bin(node)
+    ui.pushbuffer()
     if hooktype == 'changegroup':
         start = repo.changelog.rev(node)
         end = repo.changelog.count()
@@ -277,4 +276,5 @@
         count = 1
         n.node(node)
         n.diff(node, node)
-    n.send(node, count)
+    data = ui.popbuffer()
+    n.send(node, count, data)