comparison hgext/notify.py @ 15654:2a7fa7c641d8

notify: change behavior of "changegroup" hook Change the behavior so that the sender (the "From" header in the notification mail) in case of the "changegroup" hook is the user that did the first commit in the changegroup. The option is configurable, if you set "notify.fromauthor" to "True" in your config, the new behavior is activated. If you do not set the option, the behavior is as before. The commit adds to an existing test to show various aspects of the changed behavior.
author Nikolaus Schueler <nikolaus.schueler@lantiq.com>
date Thu, 15 Dec 2011 13:57:54 +0100
parents ca572e94d8e7
children 8436a4e21417
comparison
equal deleted inserted replaced
15653:93c77d5b9752 15654:2a7fa7c641d8
105 notify.merge 105 notify.merge
106 If True, send notifications for merge changesets. Default: True. 106 If True, send notifications for merge changesets. Default: True.
107 107
108 notify.mbox 108 notify.mbox
109 If set, append mails to this mbox file instead of sending. Default: None. 109 If set, append mails to this mbox file instead of sending. Default: None.
110
111 notify.fromauthor
112 If set, use the first committer of the changegroup for the "From" field of
113 the notification mail. If not set, take the user from the pushing repo.
114 Default: False.
110 115
111 If set, the following entries will also be used to customize the notifications: 116 If set, the following entries will also be used to customize the notifications:
112 117
113 email.from 118 email.from
114 Email ``From`` address to use if none can be found in generated email content. 119 Email ``From`` address to use if none can be found in generated email content.
336 return 341 return
337 342
338 ui.pushbuffer() 343 ui.pushbuffer()
339 data = '' 344 data = ''
340 count = 0 345 count = 0
346 author = ''
341 if hooktype == 'changegroup' or hooktype == 'outgoing': 347 if hooktype == 'changegroup' or hooktype == 'outgoing':
342 start, end = ctx.rev(), len(repo) 348 start, end = ctx.rev(), len(repo)
343 for rev in xrange(start, end): 349 for rev in xrange(start, end):
344 if n.node(repo[rev]): 350 if n.node(repo[rev]):
345 count += 1 351 count += 1
352 if not author:
353 author = repo[rev].user()
346 else: 354 else:
347 data += ui.popbuffer() 355 data += ui.popbuffer()
348 ui.note(_('notify: suppressing notification for merge %d:%s\n') % 356 ui.note(_('notify: suppressing notification for merge %d:%s\n') %
349 (rev, repo[rev].hex()[:12])) 357 (rev, repo[rev].hex()[:12]))
350 ui.pushbuffer() 358 ui.pushbuffer()
358 return 366 return
359 count += 1 367 count += 1
360 n.diff(ctx) 368 n.diff(ctx)
361 369
362 data += ui.popbuffer() 370 data += ui.popbuffer()
371 fromauthor = ui.config('notify', 'fromauthor')
372 if author and fromauthor:
373 data = '\n'.join(['From: %s' % author, data])
374
363 if count: 375 if count:
364 n.send(ctx, count, data) 376 n.send(ctx, count, data)