[PATCH] Allow notify to notify by named branches as well as files

Todd Cooper todd_cooper at yahoo.com
Tue Dec 15 11:39:12 CST 2009


# HG changeset patch

# User Todd Cooper <todd_cooper at yahoo.com>
# Date 1260898031 18000
# Node ID 1cf9f4ad77aba1ca75cd75e97a4d87e502c7c96a
# Parent  359c56728257c1d62a780f0a698e5657c14ed337
Allow notify to notify by named branches as well as files.

diff -r 359c56728257c1d62a780f0a698e5657c14ed337 -r 1cf9f4ad77aba1ca75cd75e97a4d87e502c7c96a hgext/notify.py
--- a/hgext/notify.py    Thu Dec 10 17:01:21 2009 -0600
+++ b/hgext/notify.py    Tue Dec 15 12:27:11 2009 -0500
@@ -63,7 +63,12 @@
   # key is glob pattern, value is ","-separated list of subscriber emails
   pattern = user at host

+  [branchsubs]
+  # key is glob pattern, value is ","-separated list of subscriber emails
+  pattern = user at host
+
Glob patterns are matched against path to repository root.
+Glob branch patterns are macthed against the branches in the repository.

If you like, you can put notify config file in repository that users
can push changes to, they can manage their own subscriptions.
@@ -100,18 +105,21 @@
class notifier(object):
     '''email notification class.'''

-    def __init__(self, ui, repo, hooktype):
+    def __init__(self, ui, repo, hooktype, ctx):
         self.ui = ui
         cfg = self.ui.config('notify', 'config')
         if cfg:
-            self.ui.readconfig(cfg, sections=['usersubs', 'reposubs'])
+            self.ui.readconfig(cfg, 
+                               sections=['usersubs', 'reposubs', 'branchsubs'])
         self.repo = repo
         self.stripcount = int(self.ui.config('notify', 'strip', 0))
         self.root = self.strip(self.repo.root)
         self.domain = self.ui.config('notify', 'domain')
         self.test = self.ui.configbool('notify', 'test', True)
         self.charsets = mail._charsets(self.ui)
+        self.branch = ctx.branch()
         self.subs = self.subscribers()
+        self.subs = set(self.subs + self.branchsubscribers())
         self.merge = self.ui.configbool('notify', 'merge', True)

         mapfile = self.ui.config('notify', 'style')
@@ -164,6 +172,21 @@
         return [mail.addressencode(self.ui, s, self.charsets, self.test)
                 for s in sorted(subs)]

+    def branchsubscribers(self):
+        '''return list of email addresses of branch subscribers
+        to this changeset.'''
+
+        subs = set()
+        for pat, users in self.ui.configitems('branchsubs'):
+            self.ui.debug('notify: check pat= %s\n' % pat)
+            if fnmatch.fnmatch(self.branch, pat):
+                for user in users.split(','):
+                    self.ui.debug('notify: branch match user= %s\n' % users)
+                    subs.add(self.fixmail(user))
+
+        return [mail.addressencode(self.ui, s, self.charsets, self.test)
+                for s in sorted(subs)]
+
     def url(self, path=None):
         return self.ui.config('web', 'baseurl') + (path or self.root)

@@ -277,11 +300,12 @@
     if used as changegroup hook, send one email for all changesets in
     changegroup. else send one email per changeset.'''

-    n = notifier(ui, repo, hooktype)
     ctx = repo[node]
+    n = notifier(ui, repo, hooktype, ctx)

     if not n.subs:
-        ui.debug('notify: no subscribers to repository %s\n' % n.root)
+        ui.debug('notify: no subscribers to repository %s or branch %s\n' 
+                 % (n.root, n.branch)) 
         return
     if n.skipsource(source):
         ui.debug('notify: changes have source "%s" - skipping\n' % source)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20091215/460d70f5/attachment.htm>


More information about the Mercurial-devel mailing list