notify: permit suppression of merge changeset notification
authorDavid Champion <dgc@uchicago.edu>
Wed, 23 Sep 2009 02:31:09 -0500
changeset 9516 f8048c334066
parent 9515 f7d85980261c
child 9517 4368f582c806
notify: permit suppression of merge changeset notification In some environments merges occur regularly but with no conflicts, and committers find merge notifications more of a bother than a help. By setting merge=False in [notify], merge notifications are suppressed. This works both for incoming and for changegroup hooks.
hgext/notify.py
--- a/hgext/notify.py	Thu Aug 27 10:21:32 2009 -0400
+++ b/hgext/notify.py	Wed Sep 23 02:31:09 2009 -0500
@@ -43,6 +43,7 @@
   diffstat = True        # add a diffstat before the diff content
   sources = serve        # notify if source of incoming changes in this list
                          # (serve == ssh or http, push, pull, bundle)
+  merge = False          # send notification for merges (default True)
   [email]
   from = user@host.com   # email address to send as if none given
   [web]
@@ -111,6 +112,7 @@
         self.test = self.ui.configbool('notify', 'test', True)
         self.charsets = mail._charsets(self.ui)
         self.subs = self.subscribers()
+        self.merge = self.ui.configbool('notify', 'merge', True)
 
         mapfile = self.ui.config('notify', 'style')
         template = (self.ui.config('notify', hooktype) or
@@ -166,10 +168,13 @@
         return self.ui.config('web', 'baseurl') + (path or self.root)
 
     def node(self, ctx, **props):
-        '''format one changeset.'''
+        '''format one changeset, unless it is a suppressed merge.'''
+        if not self.merge and len(ctx.parents()) > 1:
+            return False
         self.t.show(ctx, changes=ctx.changeset(),
                     baseurl=self.ui.config('web', 'baseurl'),
                     root=self.repo.root, webroot=self.root, **props)
+        return True
 
     def skipsource(self, source):
         '''true if incoming changes from this source should be skipped.'''
@@ -283,16 +288,29 @@
         return
 
     ui.pushbuffer()
+    data = ''
+    count = 0
     if hooktype == 'changegroup':
         start, end = ctx.rev(), len(repo)
-        count = end - start
         for rev in xrange(start, end):
-            n.node(repo[rev])
-        n.diff(ctx, repo['tip'])
+            if n.node(repo[rev]):
+                count += 1
+            else:
+                data += ui.popbuffer()
+                ui.note(_('notify: suppressing notification for merge %d:%s\n') %
+                        (rev, repo[rev].hex()[:12]))
+                ui.pushbuffer()
+        if count:
+            n.diff(ctx, repo['tip'])
     else:
-        count = 1
-        n.node(ctx)
+        if not n.node(ctx):
+            ui.popbuffer()
+            ui.note(_('notify: suppressing notification for merge %d:%s\n') %
+                    (ctx.rev(), ctx.hex()[:12]))
+            return
+        count += 1
         n.diff(ctx)
 
-    data = ui.popbuffer()
-    n.send(ctx, count, data)
+    data += ui.popbuffer()
+    if count:
+        n.send(ctx, count, data)