[PATCH 1 of 1] notify: add 'threshold' param to differentiate large and small cgroups

David Champion dgc at uchicago.edu
Fri Oct 2 20:01:06 UTC 2009


# HG changeset patch
# User David Champion <dgc at uchicago.edu>
# Date 1254513584 18000
# Node ID b5ab07ccde877bc15ed7c8410dd6fc8feab7c9bf
# Parent  cf100ce1449d103f984b12df657c3b51380b65e2
notify: add 'threshold' param to differentiate large and small cgroups

When notify is used as a changegroup hook, the number of reportable
changesets is tallied before a report is made.  ('Reportable' means
non-merge changesets, if 'merge' is set to False.)  If this number is
less than or equal to the 'threshold' setting, the hook sends individual
reports in the manner of an 'incoming.notify' hook.  If it is higher
than threshold, a conventional changroup summary is sent.

There is no change to notify's incoming hook behavior.

diff -r cf100ce1449d -r b5ab07ccde87 hgext/notify.py
--- a/hgext/notify.py	Fri Oct 02 11:35:23 2009 -0500
+++ b/hgext/notify.py	Fri Oct 02 14:59:44 2009 -0500
@@ -44,6 +44,7 @@
   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)
+  threshold = 5          # as changegroup: below threshold, act like incoming
   [email]
   from = user at host.com   # email address to send as if none given
   [web]
@@ -113,6 +114,7 @@
         self.charsets = mail._charsets(self.ui)
         self.subs = self.subscribers()
         self.merge = self.ui.configbool('notify', 'merge', True)
+        self.threshold = int(self.ui.config('notify', 'threshold', 0))
 
         mapfile = self.ui.config('notify', 'style')
         template = (self.ui.config('notify', hooktype) or
@@ -167,14 +169,16 @@
     def url(self, path=None):
         return self.ui.config('web', 'baseurl') + (path or self.root)
 
+    def skipmerge(self, ctx):
+        if not self.merge and len(ctx.parents()) > 1:
+            return True
+        return False
+
     def node(self, ctx):
-        '''format one changeset, unless it is a suppressed merge.'''
-        if not self.merge and len(ctx.parents()) > 1:
-            return False
+        '''format one changeset.'''
         self.t.show(ctx, changes=ctx.changeset(),
                     baseurl=self.ui.config('web', 'baseurl'),
-                    root=self.repo.root, webroot=self.root, **props)
-        return True
+                    root=self.repo.root, webroot=self.root)
 
     def skipsource(self, source):
         '''true if incoming changes from this source should be skipped.'''
@@ -271,6 +275,14 @@
 
         self.ui.write("\n".join(difflines))
 
+    def sendsingle(self, ctx):
+        '''send a single changeset.'''
+        self.ui.pushbuffer()
+        self.node(ctx)
+        self.diff(ctx)
+        data = self.ui.popbuffer()
+        self.send(ctx, 1, data)
+
 def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
     '''send email notifications to interested subscribers.
 
@@ -287,30 +299,37 @@
         ui.debug('notify: changes have source "%s" - skipping\n' % source)
         return
 
-    ui.pushbuffer()
-    data = ''
-    count = 0
     if hooktype == 'changegroup':
+        mimic = False
         start, end = ctx.rev(), len(repo)
+        notify = []
+
         for rev in xrange(start, end):
-            if n.node(repo[rev]):
-                count += 1
-            else:
-                data += ui.popbuffer()
+            if n.skipmerge(repo[rev]):
                 ui.note(_('notify: suppressing notification for merge %d:%s\n') %
                         (rev, repo[rev].hex()[:12]))
-                ui.pushbuffer()
-        if count:
+            else:
+                notify.append(repo[rev])
+
+        if len(notify) == 0:
+            # all csets were skipped merges
+            pass
+        elif len(notify) <= n.threshold:
+            # send each cset individually, like an 'incoming' hook would
+            for cset in notify:
+                n.sendsingle(cset)
+        else:
+            # send all csets summarily
+            ui.pushbuffer()
+            for cset in notify:
+                n.node(cset)
             n.diff(ctx, repo['tip'])
+            data = ui.popbuffer()
+            n.send(ctx, len(notify), data)
+
     else:
-        if not n.node(ctx):
-            ui.popbuffer()
+        if n.skipmerge(ctx):
             ui.note(_('notify: suppressing notification for merge %d:%s\n') %
                     (ctx.rev(), ctx.hex()[:12]))
-            return
-        count += 1
-        n.diff(ctx)
-
-    data += ui.popbuffer()
-    if count:
-        n.send(ctx, count, data)
+        else:
+            n.sendsingle(ctx)



More information about the Mercurial-devel mailing list