changeset 2230:332950340788

localrepository.addchangegroup: add more source infos to hooks
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Mon, 08 May 2006 16:50:27 -0700
parents 0ff326c2b286
children 9a2f4b2e7cf1
files hgext/notify.py mercurial/commands.py mercurial/localrepo.py mercurial/sshrepo.py
diffstat 4 files changed, 21 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/notify.py	Mon May 08 16:07:56 2006 -0700
+++ b/hgext/notify.py	Mon May 08 16:50:27 2006 -0700
@@ -40,6 +40,8 @@
 #   changegroup = ...      # template when run as changegroup hook
 #   maxdiff = 300          # max lines of diffs to include (0=none, -1=all)
 #   maxsubject = 67        # truncate subject line longer than this
+#   sources = serve        # notify if source of incoming changes in this list
+#                          # (serve == ssh or http, push, pull, bundle)
 #   [email]
 #   from = user@host.com   # email address to send as if none given
 #   [web]
@@ -167,6 +169,11 @@
                     root=self.repo.root,
                     webroot=self.root)
 
+    def skipsource(self, source):
+        '''true if incoming changes from this source should be skipped.'''
+        ok_sources = self.ui.config('notify', 'sources', 'serve').split()
+        return source not in ok_sources
+
     def send(self, node, count):
         '''send message.'''
 
@@ -210,7 +217,7 @@
             msg['Message-Id'] = ('<hg.%s.%s.%s@%s>' %
                                  (short(node), int(time.time()),
                                   hash(self.repo.root), socket.getfqdn()))
-        msg['To'] = self.subs
+        msg['To'] = ', '.join(self.subs)
 
         msgtext = msg.as_string(0)
         if self.ui.configbool('notify', 'test', True):
@@ -238,13 +245,14 @@
             self.sio.write(_('\ndiffs (%d lines):\n\n') % len(difflines))
         self.sio.write(*difflines)
 
-def hook(ui, repo, hooktype, node=None, **kwargs):
+def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
     '''send email notifications to interested subscribers.
 
     if used as changegroup hook, send one email for all changesets in
     changegroup. else send one email per changeset.'''
     n = notifier(ui, repo, hooktype)
-    if not n.subs: return True
+    if not n.subs or n.skipsource(source):
+        return
     node = bin(node)
     if hooktype == 'changegroup':
         start = repo.changelog.rev(node)
--- a/mercurial/commands.py	Mon May 08 16:07:56 2006 -0700
+++ b/mercurial/commands.py	Mon May 08 16:50:27 2006 -0700
@@ -2477,7 +2477,7 @@
                     continue
                 respond("")
 
-                r = repo.addchangegroup(fin)
+                r = repo.addchangegroup(fin, 'serve')
                 respond(str(r))
 
     optlist = ("name templates style address port ipv6"
@@ -2701,7 +2701,7 @@
         raise util.Abort(_("%s: unknown bundle compression type")
                          % fname)
     gen = generator(util.filechunkiter(f, 4096))
-    modheads = repo.addchangegroup(util.chunkbuffer(gen))
+    modheads = repo.addchangegroup(util.chunkbuffer(gen), 'unbundle')
     return postincoming(ui, repo, modheads, opts['update'])
 
 def undo(ui, repo):
--- a/mercurial/localrepo.py	Mon May 08 16:07:56 2006 -0700
+++ b/mercurial/localrepo.py	Mon May 08 16:50:27 2006 -0700
@@ -1079,7 +1079,7 @@
             cg = remote.changegroup(fetch, 'pull')
         else:
             cg = remote.changegroupsubset(fetch, heads, 'pull')
-        return self.addchangegroup(cg)
+        return self.addchangegroup(cg, 'pull')
 
     def push(self, remote, force=False, revs=None):
         lock = remote.lock()
@@ -1116,7 +1116,7 @@
             cg = self.changegroup(update, 'push')
         else:
             cg = self.changegroupsubset(update, revs, 'push')
-        return remote.addchangegroup(cg)
+        return remote.addchangegroup(cg, 'push')
 
     def changegroupsubset(self, bases, heads, source):
         """This function generates a changegroup consisting of all the nodes
@@ -1455,7 +1455,7 @@
 
         return util.chunkbuffer(gengroup())
 
-    def addchangegroup(self, source):
+    def addchangegroup(self, source, srctype):
         """add changegroup to repo.
         returns number of heads modified or added + 1."""
 
@@ -1469,7 +1469,7 @@
         if not source:
             return 0
 
-        self.hook('prechangegroup', throw=True, source=source)
+        self.hook('prechangegroup', throw=True, source=srctype)
 
         changesets = files = revisions = 0
 
@@ -1534,17 +1534,17 @@
                          % (changesets, revisions, files, heads))
 
         self.hook('pretxnchangegroup', throw=True,
-                  node=hex(self.changelog.node(cor+1)), source=source)
+                  node=hex(self.changelog.node(cor+1)), source=srctype)
 
         tr.close()
 
         if changesets > 0:
             self.hook("changegroup", node=hex(self.changelog.node(cor+1)),
-                      source=source)
+                      source=srctype)
 
             for i in range(cor + 1, cnr + 1):
                 self.hook("incoming", node=hex(self.changelog.node(i)),
-                          source=source)
+                          source=srctype)
 
         return newheads - oldheads + 1
 
--- a/mercurial/sshrepo.py	Mon May 08 16:07:56 2006 -0700
+++ b/mercurial/sshrepo.py	Mon May 08 16:50:27 2006 -0700
@@ -134,7 +134,7 @@
         f = self.do_cmd("changegroup", roots=n)
         return self.pipei
 
-    def addchangegroup(self, cg):
+    def addchangegroup(self, cg, source):
         d = self.call("addchangegroup")
         if d:
             raise hg.RepoError(_("push refused: %s"), d)