diff 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
line wrap: on
line diff
--- a/hgext/notify.py	Thu Dec 15 16:23:26 2011 +0100
+++ b/hgext/notify.py	Thu Dec 15 13:57:54 2011 +0100
@@ -108,6 +108,11 @@
 notify.mbox
   If set, append mails to this mbox file instead of sending. Default: None.
 
+notify.fromauthor
+  If set, use the first committer of the changegroup for the "From" field of
+  the notification mail. If not set, take the user from the pushing repo.
+  Default: False.
+
 If set, the following entries will also be used to customize the notifications:
 
 email.from
@@ -338,11 +343,14 @@
     ui.pushbuffer()
     data = ''
     count = 0
+    author = ''
     if hooktype == 'changegroup' or hooktype == 'outgoing':
         start, end = ctx.rev(), len(repo)
         for rev in xrange(start, end):
             if n.node(repo[rev]):
                 count += 1
+                if not author:
+                    author = repo[rev].user()
             else:
                 data += ui.popbuffer()
                 ui.note(_('notify: suppressing notification for merge %d:%s\n') %
@@ -360,5 +368,9 @@
         n.diff(ctx)
 
     data += ui.popbuffer()
+    fromauthor = ui.config('notify', 'fromauthor')
+    if author and fromauthor:
+        data = '\n'.join(['From: %s' % author, data])
+
     if count:
         n.send(ctx, count, data)