annotate hgext/notify.py @ 9513:ae88c721f916

cmdutil: service: add an optional runargs argument to pass the command to run This would be necessary for inotify launching its server: the initial command is a standard 'hg st'/'hg ci'/... but the daemon to run is 'hg inserve'
author Nicolas Dumazet <nicdumz.commits@gmail.com>
date Sun, 16 Aug 2009 11:30:24 +0900
parents 90ae579924e4
children f8048c334066
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
1 # notify.py - email notifications for mercurial
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
2 #
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
3 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
4 #
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8154
diff changeset
5 # This software may be used and distributed according to the terms of the
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8154
diff changeset
6 # GNU General Public License version 2, incorporated herein by reference.
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
7
8935
f4f0e902b750 extensions: change descriptions for hook-providing extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8894
diff changeset
8 '''hooks for sending email notifications at commit/push time
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
9
9266
0efb3360bdb3 notify: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9157
diff changeset
10 Subscriptions can be managed through a hgrc file. Default mode is to
0efb3360bdb3 notify: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9157
diff changeset
11 print messages to stdout, for testing and configuring.
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
12
9266
0efb3360bdb3 notify: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9157
diff changeset
13 To use, configure the notify extension and enable it in hgrc like
0efb3360bdb3 notify: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9157
diff changeset
14 this::
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
15
9105
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
16 [extensions]
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
17 hgext.notify =
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
18
9105
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
19 [hooks]
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
20 # one email for each incoming changeset
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
21 incoming.notify = python:hgext.notify.hook
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
22 # batch emails when many changesets incoming at one time
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
23 changegroup.notify = python:hgext.notify.hook
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
24
9105
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
25 [notify]
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
26 # config items go here
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
27
9157
9261667e9b82 commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents: 9136
diff changeset
28 Required configuration items::
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
29
9105
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
30 config = /path/to/file # file containing subscriptions
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
31
9157
9261667e9b82 commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents: 9136
diff changeset
32 Optional configuration items::
9104
c9c5aa12a46e notify: cleanup module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9068
diff changeset
33
9105
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
34 test = True # print messages to stdout for testing
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
35 strip = 3 # number of slashes to strip for url paths
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
36 domain = example.com # domain to use if committer missing domain
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
37 style = ... # style file to use when formatting email
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
38 template = ... # template to use when formatting email
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
39 incoming = ... # template to use when run as incoming hook
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
40 changegroup = ... # template when run as changegroup hook
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
41 maxdiff = 300 # max lines of diffs to include (0=none, -1=all)
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
42 maxsubject = 67 # truncate subject line longer than this
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
43 diffstat = True # add a diffstat before the diff content
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
44 sources = serve # notify if source of incoming changes in this list
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
45 # (serve == ssh or http, push, pull, bundle)
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
46 [email]
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
47 from = user@host.com # email address to send as if none given
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
48 [web]
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
49 baseurl = http://hgserver/... # root of hg web site for browsing commits
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
50
9266
0efb3360bdb3 notify: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9157
diff changeset
51 The notify config file has same format as a regular hgrc file. It has
0efb3360bdb3 notify: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9157
diff changeset
52 two sections so you can express subscriptions in whatever way is
0efb3360bdb3 notify: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9157
diff changeset
53 handier for you.
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
54
9157
9261667e9b82 commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents: 9136
diff changeset
55 ::
9261667e9b82 commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents: 9136
diff changeset
56
9105
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
57 [usersubs]
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
58 # key is subscriber email, value is ","-separated list of glob patterns
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
59 user@host = pattern
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
60
9105
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
61 [reposubs]
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
62 # key is glob pattern, value is ","-separated list of subscriber emails
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
63 pattern = user@host
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
64
9105
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
65 Glob patterns are matched against path to repository root.
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
66
9266
0efb3360bdb3 notify: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9157
diff changeset
67 If you like, you can put notify config file in repository that users
0efb3360bdb3 notify: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9157
diff changeset
68 can push changes to, they can manage their own subscriptions.
9068
27a41250a9ce notify: wrapped docstrings at 78 characters
Martin Geisler <mg@lazybytes.net>
parents: 8935
diff changeset
69 '''
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
70
3891
6b4127c7d52a Simplify i18n imports
Matt Mackall <mpm@selenic.com>
parents: 3877
diff changeset
71 from mercurial.i18n import _
3877
abaee83ce0a6 Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents: 3876
diff changeset
72 from mercurial import patch, cmdutil, templater, util, mail
9313
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
73 import email.Parser, email.Errors, fnmatch, socket, time
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
74
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
75 # template for single changeset can include email headers.
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
76 single_template = '''
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
77 Subject: changeset in {webroot}: {desc|firstline|strip}
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
78 From: {author}
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
79
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
80 changeset {node|short} in {root}
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
81 details: {baseurl}{webroot}?cmd=changeset;node={node|short}
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
82 description:
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
83 \t{desc|tabindent|strip}
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
84 '''.lstrip()
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
85
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
86 # template for multiple changesets should not contain email headers,
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
87 # because only first set of headers will be used and result will look
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
88 # strange.
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
89 multiple_template = '''
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
90 changeset {node|short} in {root}
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
91 details: {baseurl}{webroot}?cmd=changeset;node={node|short}
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
92 summary: {desc|firstline}
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
93 '''
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
94
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
95 deftemplates = {
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
96 'changegroup': multiple_template,
4498
4dfb9f232a63 Fixed indentation in hgext/notify.py
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4479
diff changeset
97 }
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
98
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
99 class notifier(object):
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
100 '''email notification class.'''
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
101
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
102 def __init__(self, ui, repo, hooktype):
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
103 self.ui = ui
2329
90368f89340a notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2326
diff changeset
104 cfg = self.ui.config('notify', 'config')
90368f89340a notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2326
diff changeset
105 if cfg:
8142
912bfef12ba6 ui: fold readsections into readconfig
Matt Mackall <mpm@selenic.com>
parents: 8029
diff changeset
106 self.ui.readconfig(cfg, sections=['usersubs', 'reposubs'])
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
107 self.repo = repo
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
108 self.stripcount = int(self.ui.config('notify', 'strip', 0))
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
109 self.root = self.strip(self.repo.root)
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
110 self.domain = self.ui.config('notify', 'domain')
7498
64840fcb79e1 notify: no charset conversion when testing
Christian Ebert <blacktrash@gmx.net>
parents: 7369
diff changeset
111 self.test = self.ui.configbool('notify', 'test', True)
7116
e981725da3fe notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents: 6979
diff changeset
112 self.charsets = mail._charsets(self.ui)
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
113 self.subs = self.subscribers()
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
114
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
115 mapfile = self.ui.config('notify', 'style')
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
116 template = (self.ui.config('notify', hooktype) or
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
117 self.ui.config('notify', 'template'))
3739
16f8e7d1dd54 fix notify with new ui buffering
Matt Mackall <mpm@selenic.com>
parents: 3679
diff changeset
118 self.t = cmdutil.changeset_templater(self.ui, self.repo,
7762
fece056bf240 add --git option to commands supporting --patch (log, incoming, history, tip)
Jim Correia <jim.correia@pobox.com>
parents: 7726
diff changeset
119 False, None, mapfile, False)
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
120 if not mapfile and not template:
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
121 template = deftemplates.get(hooktype) or single_template
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
122 if template:
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
123 template = templater.parsestring(template, quoted=False)
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
124 self.t.use_template(template)
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
125
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
126 def strip(self, path):
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
127 '''strip leading slashes from local path, turn into web-safe path.'''
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
128
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
129 path = util.pconvert(path)
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
130 count = self.stripcount
2326
d0ba2f6b9d97 notify: fix off by one error.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2296
diff changeset
131 while count > 0:
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
132 c = path.find('/')
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
133 if c == -1:
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
134 break
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
135 path = path[c+1:]
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
136 count -= 1
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
137 return path
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
138
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
139 def fixmail(self, addr):
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
140 '''try to clean up email addresses.'''
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
141
5975
75d9fe70c654 templater: move email function to util
Matt Mackall <mpm@selenic.com>
parents: 4500
diff changeset
142 addr = util.email(addr.strip())
4094
fbf0e9acfd83 notify: don't try to fix addresses if notify.domain is not set
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4077
diff changeset
143 if self.domain:
fbf0e9acfd83 notify: don't try to fix addresses if notify.domain is not set
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4077
diff changeset
144 a = addr.find('@localhost')
fbf0e9acfd83 notify: don't try to fix addresses if notify.domain is not set
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4077
diff changeset
145 if a != -1:
fbf0e9acfd83 notify: don't try to fix addresses if notify.domain is not set
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4077
diff changeset
146 addr = addr[:a]
fbf0e9acfd83 notify: don't try to fix addresses if notify.domain is not set
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4077
diff changeset
147 if '@' not in addr:
fbf0e9acfd83 notify: don't try to fix addresses if notify.domain is not set
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4077
diff changeset
148 return addr + '@' + self.domain
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
149 return addr
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
150
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
151 def subscribers(self):
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
152 '''return list of email addresses of subscribers to this repo.'''
8154
06f1e4e309ed notify: turned a set-like dict into a real set
Martin Geisler <mg@lazybytes.net>
parents: 8142
diff changeset
153 subs = set()
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
154 for user, pats in self.ui.configitems('usersubs'):
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
155 for pat in pats.split(','):
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
156 if fnmatch.fnmatch(self.repo.root, pat.strip()):
8154
06f1e4e309ed notify: turned a set-like dict into a real set
Martin Geisler <mg@lazybytes.net>
parents: 8142
diff changeset
157 subs.add(self.fixmail(user))
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
158 for pat, users in self.ui.configitems('reposubs'):
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
159 if fnmatch.fnmatch(self.repo.root, pat):
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
160 for user in users.split(','):
8154
06f1e4e309ed notify: turned a set-like dict into a real set
Martin Geisler <mg@lazybytes.net>
parents: 8142
diff changeset
161 subs.add(self.fixmail(user))
7498
64840fcb79e1 notify: no charset conversion when testing
Christian Ebert <blacktrash@gmx.net>
parents: 7369
diff changeset
162 return [mail.addressencode(self.ui, s, self.charsets, self.test)
8154
06f1e4e309ed notify: turned a set-like dict into a real set
Martin Geisler <mg@lazybytes.net>
parents: 8142
diff changeset
163 for s in sorted(subs)]
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
164
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
165 def url(self, path=None):
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
166 return self.ui.config('web', 'baseurl') + (path or self.root)
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
167
9486
dd8d10c36c9c notify: make it possible to pass extra info into templates
Bryan O'Sullivan <bos@serpentine.com>
parents: 9327
diff changeset
168 def node(self, ctx, **props):
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
169 '''format one changeset.'''
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
170 self.t.show(ctx, changes=ctx.changeset(),
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
171 baseurl=self.ui.config('web', 'baseurl'),
9486
dd8d10c36c9c notify: make it possible to pass extra info into templates
Bryan O'Sullivan <bos@serpentine.com>
parents: 9327
diff changeset
172 root=self.repo.root, webroot=self.root, **props)
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
173
2230
332950340788 localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2225
diff changeset
174 def skipsource(self, source):
332950340788 localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2225
diff changeset
175 '''true if incoming changes from this source should be skipped.'''
332950340788 localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2225
diff changeset
176 ok_sources = self.ui.config('notify', 'sources', 'serve').split()
332950340788 localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2225
diff changeset
177 return source not in ok_sources
332950340788 localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2225
diff changeset
178
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
179 def send(self, ctx, count, data):
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
180 '''send message.'''
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
181
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
182 p = email.Parser.Parser()
9313
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
183 try:
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
184 msg = p.parsestr(data)
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
185 except email.Errors.MessageParseError, inst:
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
186 raise util.Abort(inst)
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
187
7116
e981725da3fe notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents: 6979
diff changeset
188 # store sender and subject
e981725da3fe notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents: 6979
diff changeset
189 sender, subject = msg['From'], msg['Subject']
7658
44b3f7bbe2f3 notify: fix neglect of custom headers set via template
Christian Ebert <blacktrash@gmx.net>
parents: 7498
diff changeset
190 del msg['From'], msg['Subject']
9313
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
191
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
192 if not msg.is_multipart():
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
193 # create fresh mime message from scratch
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
194 # (multipart templates must take care of this themselves)
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
195 headers = msg.items()
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
196 payload = msg.get_payload()
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
197 # for notification prefer readability over data precision
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
198 msg = mail.mimeencode(self.ui, payload, self.charsets, self.test)
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
199 # reinstate custom headers
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
200 for k, v in headers:
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
201 msg[k] = v
7116
e981725da3fe notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents: 6979
diff changeset
202
7705
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
203 msg['Date'] = util.datestr(format="%a, %d %b %Y %H:%M:%S %1%2")
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
204
7705
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
205 # try to make subject line exist and be useful
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
206 if not subject:
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
207 if count > 1:
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
208 subject = _('%s: %d new changesets') % (self.root, count)
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
209 else:
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
210 s = ctx.description().lstrip().split('\n', 1)[0].rstrip()
7705
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
211 subject = '%s: %s' % (self.root, s)
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
212 maxsubject = int(self.ui.config('notify', 'maxsubject', 67))
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
213 if maxsubject and len(subject) > maxsubject:
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
214 subject = subject[:maxsubject-3] + '...'
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
215 msg['Subject'] = mail.headencode(self.ui, subject,
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
216 self.charsets, self.test)
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
217
7705
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
218 # try to make message have proper sender
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
219 if not sender:
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
220 sender = self.ui.config('email', 'from') or self.ui.username()
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
221 if '@' not in sender or '@localhost' in sender:
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
222 sender = self.fixmail(sender)
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
223 msg['From'] = mail.addressencode(self.ui, sender,
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
224 self.charsets, self.test)
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
225
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
226 msg['X-Hg-Notification'] = 'changeset %s' % ctx
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
227 if not msg['Message-Id']:
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
228 msg['Message-Id'] = ('<hg.%s.%s.%s@%s>' %
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
229 (ctx, int(time.time()),
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
230 hash(self.repo.root), socket.getfqdn()))
2230
332950340788 localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2225
diff changeset
231 msg['To'] = ', '.join(self.subs)
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
232
9136
31177742f54a for calls expecting bool args, pass bool instead of int
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9105
diff changeset
233 msgtext = msg.as_string()
7498
64840fcb79e1 notify: no charset conversion when testing
Christian Ebert <blacktrash@gmx.net>
parents: 7369
diff changeset
234 if self.test:
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
235 self.ui.write(msgtext)
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
236 if not msgtext.endswith('\n'):
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
237 self.ui.write('\n')
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
238 else:
2329
90368f89340a notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2326
diff changeset
239 self.ui.status(_('notify: sending %d subscribers %d changes\n') %
4498
4dfb9f232a63 Fixed indentation in hgext/notify.py
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4479
diff changeset
240 (len(self.subs), count))
5975
75d9fe70c654 templater: move email function to util
Matt Mackall <mpm@selenic.com>
parents: 4500
diff changeset
241 mail.sendmail(self.ui, util.email(msg['From']),
2889
20b95aef3fe0 Move ui.sendmail to mail.connect/sendmail
Matt Mackall <mpm@selenic.com>
parents: 2874
diff changeset
242 self.subs, msgtext)
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
243
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
244 def diff(self, ctx, ref=None):
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
245
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
246 maxdiff = int(self.ui.config('notify', 'maxdiff', 300))
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
247 prev = ctx.parents()[0].node()
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
248 ref = ref and ref.node() or ctx.node()
7308
b6f5490effbf patch: turn patch.diff() into a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7127
diff changeset
249 chunks = patch.diff(self.repo, prev, ref, opts=patch.diffopts(self.ui))
b6f5490effbf patch: turn patch.diff() into a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7127
diff changeset
250 difflines = ''.join(chunks).splitlines()
6979
a3fd4aa154af notify: fix diffstat printing
divy@chelsio.com
parents: 6974
diff changeset
251
3096
f422c8265ae5 Add support for diffstat in commit emails, and move diffstat from
Matt Doar <matt@xensource.com>
parents: 3017
diff changeset
252 if self.ui.configbool('notify', 'diffstat', True):
f422c8265ae5 Add support for diffstat in commit emails, and move diffstat from
Matt Doar <matt@xensource.com>
parents: 3017
diff changeset
253 s = patch.diffstat(difflines)
4077
1305ba7dee88 Prevent type exception on concatenation if diffstat returns None.
Sean Dague <sean@dague.net>
parents: 3739
diff changeset
254 # s may be nil, don't include the header if it is
1305ba7dee88 Prevent type exception on concatenation if diffstat returns None.
Sean Dague <sean@dague.net>
parents: 3739
diff changeset
255 if s:
1305ba7dee88 Prevent type exception on concatenation if diffstat returns None.
Sean Dague <sean@dague.net>
parents: 3739
diff changeset
256 self.ui.write('\ndiffstat:\n\n%s' % s)
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
257
6305
e8d447d91cdb notify: print diffstat even if maxline == 0
Benoît Allard <benoit@aeteurope.nl>
parents: 6229
diff changeset
258 if maxdiff == 0:
e8d447d91cdb notify: print diffstat even if maxline == 0
Benoît Allard <benoit@aeteurope.nl>
parents: 6229
diff changeset
259 return
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
260 elif maxdiff > 0 and len(difflines) > maxdiff:
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
261 msg = _('\ndiffs (truncated from %d to %d lines):\n\n')
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
262 self.ui.write(msg % (len(difflines), maxdiff))
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
263 difflines = difflines[:maxdiff]
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
264 elif difflines:
3739
16f8e7d1dd54 fix notify with new ui buffering
Matt Mackall <mpm@selenic.com>
parents: 3679
diff changeset
265 self.ui.write(_('\ndiffs (%d lines):\n\n') % len(difflines))
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
266
6979
a3fd4aa154af notify: fix diffstat printing
divy@chelsio.com
parents: 6974
diff changeset
267 self.ui.write("\n".join(difflines))
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
268
2230
332950340788 localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2225
diff changeset
269 def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
270 '''send email notifications to interested subscribers.
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
271
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
272 if used as changegroup hook, send one email for all changesets in
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
273 changegroup. else send one email per changeset.'''
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
274
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
275 n = notifier(ui, repo, hooktype)
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
276 ctx = repo[node]
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
277
2329
90368f89340a notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2326
diff changeset
278 if not n.subs:
9467
4c041f1ee1b4 do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents: 9327
diff changeset
279 ui.debug('notify: no subscribers to repository %s\n' % n.root)
2329
90368f89340a notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2326
diff changeset
280 return
90368f89340a notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2326
diff changeset
281 if n.skipsource(source):
9467
4c041f1ee1b4 do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents: 9327
diff changeset
282 ui.debug('notify: changes have source "%s" - skipping\n' % source)
2230
332950340788 localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2225
diff changeset
283 return
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
284
3739
16f8e7d1dd54 fix notify with new ui buffering
Matt Mackall <mpm@selenic.com>
parents: 3679
diff changeset
285 ui.pushbuffer()
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
286 if hooktype == 'changegroup':
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
287 start, end = ctx.rev(), len(repo)
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
288 count = end - start
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
289 for rev in xrange(start, end):
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
290 n.node(repo[rev])
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
291 n.diff(ctx, repo['tip'])
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
292 else:
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
293 count = 1
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
294 n.node(ctx)
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
295 n.diff(ctx)
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
296
3739
16f8e7d1dd54 fix notify with new ui buffering
Matt Mackall <mpm@selenic.com>
parents: 3679
diff changeset
297 data = ui.popbuffer()
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
298 n.send(ctx, count, data)