[PATCH] notify: permit suppression of merge changeset notification

David Champion dgc at uchicago.edu
Wed Sep 23 18:38:54 CDT 2009


# HG changeset patch
# User David Champion <dgc at uchicago.edu>
# Date 1253691069 18000
# Node ID 23f58861b0eb86a968effbd94f0e61053d9e1a9f
# Parent  c564dbb2a6d5394c995c1ae93943a16253e7b1e5
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.

diff -r c564dbb2a6d5 -r 23f58861b0eb hgext/notify.py
--- a/hgext/notify.py	Thu Sep 17 21:52:08 2009 +0200
+++ 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 at 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):
-        '''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)
+        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)


More information about the Mercurial-devel mailing list