##// END OF EJS Templates
notify: use contexts more pervasively
Dirkjan Ochtman -
r7726:2486980f default
parent child Browse files
Show More
@@ -147,7 +147,6 b' class notifier(object):'
147 147
148 148 def subscribers(self):
149 149 '''return list of email addresses of subscribers to this repo.'''
150
151 150 subs = {}
152 151 for user, pats in self.ui.configitems('usersubs'):
153 152 for pat in pats.split(','):
@@ -164,20 +163,18 b' class notifier(object):'
164 163 def url(self, path=None):
165 164 return self.ui.config('web', 'baseurl') + (path or self.root)
166 165
167 def node(self, node):
166 def node(self, ctx):
168 167 '''format one changeset.'''
169
170 self.t.show(self.repo[node], changes=self.repo.changelog.read(node),
168 self.t.show(ctx, changes=ctx.changeset(),
171 169 baseurl=self.ui.config('web', 'baseurl'),
172 root=self.repo.root,
173 webroot=self.root)
170 root=self.repo.root, webroot=self.root)
174 171
175 172 def skipsource(self, source):
176 173 '''true if incoming changes from this source should be skipped.'''
177 174 ok_sources = self.ui.config('notify', 'sources', 'serve').split()
178 175 return source not in ok_sources
179 176
180 def send(self, node, count, data):
177 def send(self, ctx, count, data):
181 178 '''send message.'''
182 179
183 180 p = email.Parser.Parser()
@@ -203,8 +200,7 b' class notifier(object):'
203 200 if count > 1:
204 201 subject = _('%s: %d new changesets') % (self.root, count)
205 202 else:
206 changes = self.repo.changelog.read(node)
207 s = changes[4].lstrip().split('\n', 1)[0].rstrip()
203 s = ctx.description().lstrip().split('\n', 1)[0].rstrip()
208 204 subject = '%s: %s' % (self.root, s)
209 205 maxsubject = int(self.ui.config('notify', 'maxsubject', 67))
210 206 if maxsubject and len(subject) > maxsubject:
@@ -220,10 +216,10 b' class notifier(object):'
220 216 msg['From'] = mail.addressencode(self.ui, sender,
221 217 self.charsets, self.test)
222 218
223 msg['X-Hg-Notification'] = 'changeset ' + short(node)
219 msg['X-Hg-Notification'] = 'changeset %s' % ctx
224 220 if not msg['Message-Id']:
225 221 msg['Message-Id'] = ('<hg.%s.%s.%s@%s>' %
226 (short(node), int(time.time()),
222 (ctx, int(time.time()),
227 223 hash(self.repo.root), socket.getfqdn()))
228 224 msg['To'] = ', '.join(self.subs)
229 225
@@ -238,10 +234,11 b' class notifier(object):'
238 234 mail.sendmail(self.ui, util.email(msg['From']),
239 235 self.subs, msgtext)
240 236
241 def diff(self, node, ref):
237 def diff(self, ctx, ref=None):
238
242 239 maxdiff = int(self.ui.config('notify', 'maxdiff', 300))
243 prev = self.repo.changelog.parents(node)[0]
244
240 prev = ctx.parents()[0].node()
241 ref = ref and ref.node() or ctx.node()
245 242 chunks = patch.diff(self.repo, prev, ref, opts=patch.diffopts(self.ui))
246 243 difflines = ''.join(chunks).splitlines()
247 244
@@ -250,14 +247,16 b' class notifier(object):'
250 247 # s may be nil, don't include the header if it is
251 248 if s:
252 249 self.ui.write('\ndiffstat:\n\n%s' % s)
250
253 251 if maxdiff == 0:
254 252 return
255 if maxdiff > 0 and len(difflines) > maxdiff:
256 self.ui.write(_('\ndiffs (truncated from %d to %d lines):\n\n') %
257 (len(difflines), maxdiff))
253 elif maxdiff > 0 and len(difflines) > maxdiff:
254 msg = _('\ndiffs (truncated from %d to %d lines):\n\n')
255 self.ui.write(msg % (len(difflines), maxdiff))
258 256 difflines = difflines[:maxdiff]
259 257 elif difflines:
260 258 self.ui.write(_('\ndiffs (%d lines):\n\n') % len(difflines))
259
261 260 self.ui.write("\n".join(difflines))
262 261
263 262 def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
@@ -265,26 +264,28 b' def hook(ui, repo, hooktype, node=None, '
265 264
266 265 if used as changegroup hook, send one email for all changesets in
267 266 changegroup. else send one email per changeset.'''
267
268 268 n = notifier(ui, repo, hooktype)
269 ctx = repo[node]
270
269 271 if not n.subs:
270 272 ui.debug(_('notify: no subscribers to repo %s\n') % n.root)
271 273 return
272 274 if n.skipsource(source):
273 ui.debug(_('notify: changes have source "%s" - skipping\n') %
274 source)
275 ui.debug(_('notify: changes have source "%s" - skipping\n') % source)
275 276 return
276 node = bin(node)
277
277 278 ui.pushbuffer()
278 279 if hooktype == 'changegroup':
279 start = repo[node].rev()
280 end = len(repo)
280 start, end = ctx.rev(), len(repo)
281 281 count = end - start
282 282 for rev in xrange(start, end):
283 n.node(repo[rev].node())
284 n.diff(node, repo.changelog.tip())
283 n.node(repo[rev])
284 n.diff(ctx, repo['tip'])
285 285 else:
286 286 count = 1
287 n.node(node)
288 n.diff(node, node)
287 n.node(ctx)
288 n.diff(ctx)
289
289 290 data = ui.popbuffer()
290 n.send(node, count, data)
291 n.send(ctx, count, data)
General Comments 0
You need to be logged in to leave comments. Login now