comparison hgext/notify.py @ 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 ff43ea94eff4
children 6e8e3dd7976e
comparison
equal deleted inserted replaced
2229:0ff326c2b286 2230:332950340788
38 # template = ... # template to use when formatting email 38 # template = ... # template to use when formatting email
39 # incoming = ... # template to use when run as incoming hook 39 # incoming = ... # template to use when run as incoming hook
40 # changegroup = ... # template when run as changegroup hook 40 # changegroup = ... # template when run as changegroup hook
41 # maxdiff = 300 # max lines of diffs to include (0=none, -1=all) 41 # maxdiff = 300 # max lines of diffs to include (0=none, -1=all)
42 # maxsubject = 67 # truncate subject line longer than this 42 # maxsubject = 67 # truncate subject line longer than this
43 # sources = serve # notify if source of incoming changes in this list
44 # # (serve == ssh or http, push, pull, bundle)
43 # [email] 45 # [email]
44 # from = user@host.com # email address to send as if none given 46 # from = user@host.com # email address to send as if none given
45 # [web] 47 # [web]
46 # baseurl = http://hgserver/... # root of hg web site for browsing commits 48 # baseurl = http://hgserver/... # root of hg web site for browsing commits
47 # 49 #
164 166
165 self.t.show(changenode=node, changes=self.repo.changelog.read(node), 167 self.t.show(changenode=node, changes=self.repo.changelog.read(node),
166 baseurl=self.ui.config('web', 'baseurl'), 168 baseurl=self.ui.config('web', 'baseurl'),
167 root=self.repo.root, 169 root=self.repo.root,
168 webroot=self.root) 170 webroot=self.root)
171
172 def skipsource(self, source):
173 '''true if incoming changes from this source should be skipped.'''
174 ok_sources = self.ui.config('notify', 'sources', 'serve').split()
175 return source not in ok_sources
169 176
170 def send(self, node, count): 177 def send(self, node, count):
171 '''send message.''' 178 '''send message.'''
172 179
173 p = email.Parser.Parser() 180 p = email.Parser.Parser()
208 msg['X-Hg-Notification'] = 'changeset ' + short(node) 215 msg['X-Hg-Notification'] = 'changeset ' + short(node)
209 if not msg['Message-Id']: 216 if not msg['Message-Id']:
210 msg['Message-Id'] = ('<hg.%s.%s.%s@%s>' % 217 msg['Message-Id'] = ('<hg.%s.%s.%s@%s>' %
211 (short(node), int(time.time()), 218 (short(node), int(time.time()),
212 hash(self.repo.root), socket.getfqdn())) 219 hash(self.repo.root), socket.getfqdn()))
213 msg['To'] = self.subs 220 msg['To'] = ', '.join(self.subs)
214 221
215 msgtext = msg.as_string(0) 222 msgtext = msg.as_string(0)
216 if self.ui.configbool('notify', 'test', True): 223 if self.ui.configbool('notify', 'test', True):
217 self.ui.write(msgtext) 224 self.ui.write(msgtext)
218 if not msgtext.endswith('\n'): 225 if not msgtext.endswith('\n'):
236 difflines = difflines[:maxdiff] 243 difflines = difflines[:maxdiff]
237 elif difflines: 244 elif difflines:
238 self.sio.write(_('\ndiffs (%d lines):\n\n') % len(difflines)) 245 self.sio.write(_('\ndiffs (%d lines):\n\n') % len(difflines))
239 self.sio.write(*difflines) 246 self.sio.write(*difflines)
240 247
241 def hook(ui, repo, hooktype, node=None, **kwargs): 248 def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
242 '''send email notifications to interested subscribers. 249 '''send email notifications to interested subscribers.
243 250
244 if used as changegroup hook, send one email for all changesets in 251 if used as changegroup hook, send one email for all changesets in
245 changegroup. else send one email per changeset.''' 252 changegroup. else send one email per changeset.'''
246 n = notifier(ui, repo, hooktype) 253 n = notifier(ui, repo, hooktype)
247 if not n.subs: return True 254 if not n.subs or n.skipsource(source):
255 return
248 node = bin(node) 256 node = bin(node)
249 if hooktype == 'changegroup': 257 if hooktype == 'changegroup':
250 start = repo.changelog.rev(node) 258 start = repo.changelog.rev(node)
251 end = repo.changelog.count() 259 end = repo.changelog.count()
252 count = end - start 260 count = end - start