# HG changeset patch # User Vadim Gelfer # Date 1147132227 25200 # Node ID 33295034078849ba60c7b4422b69fbc63704c3f2 # Parent 0ff326c2b286caee999ddd01d98ad80da9867bb5 localrepository.addchangegroup: add more source infos to hooks diff --git a/hgext/notify.py b/hgext/notify.py --- a/hgext/notify.py +++ b/hgext/notify.py @@ -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 @@ class notifier(object): 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 @@ class notifier(object): msg['Message-Id'] = ('' % (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 @@ class notifier(object): 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) diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2477,7 +2477,7 @@ def serve(ui, repo, **opts): 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 @@ def unbundle(ui, repo, fname, **opts): 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): diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1079,7 +1079,7 @@ class localrepository(object): 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 @@ class localrepository(object): 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 @@ class localrepository(object): 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 @@ class localrepository(object): 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 @@ class localrepository(object): % (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 diff --git a/mercurial/sshrepo.py b/mercurial/sshrepo.py --- a/mercurial/sshrepo.py +++ b/mercurial/sshrepo.py @@ -134,7 +134,7 @@ class sshrepository(remoterepository): 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)