Mercurial > hg
annotate hgext/notify.py @ 7592:75ad51257c82
convert/gnuarch: recode cat-log parts to utf-8 to be hg.description friendly
author | Edouard Gomez <ed.gomez@free.fr> |
---|---|
date | Sun, 04 Jan 2009 18:44:39 +0100 |
parents | 64840fcb79e1 |
children | 44b3f7bbe2f3 |
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 # |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
5 # This software may be used and distributed according to the terms |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
6 # of the GNU General Public License, incorporated herein by reference. |
7127
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
7 |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
8 '''hook extension to email notifications on commits/pushes |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
9 |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
10 Subscriptions can be managed through hgrc. Default mode is to print |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
11 messages to stdout, for testing and configuring. |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
12 |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
13 To use, configure notify extension and enable in hgrc like this: |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
14 |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
15 [extensions] |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
16 hgext.notify = |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
17 |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
18 [hooks] |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
19 # one email for each incoming changeset |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
20 incoming.notify = python:hgext.notify.hook |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
21 # batch emails when many changesets incoming at one time |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
22 changegroup.notify = python:hgext.notify.hook |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
23 |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
24 [notify] |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
25 # config items go in here |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
26 |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
27 config items: |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
28 |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
29 REQUIRED: |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
30 config = /path/to/file # file containing subscriptions |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
31 |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
32 OPTIONAL: |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
33 test = True # print messages to stdout for testing |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
34 strip = 3 # number of slashes to strip for url paths |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
35 domain = example.com # domain to use if committer missing domain |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
36 style = ... # style file to use when formatting email |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
37 template = ... # template to use when formatting email |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
38 incoming = ... # template to use when run as incoming hook |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
39 changegroup = ... # template when run as changegroup hook |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
40 maxdiff = 300 # max lines of diffs to include (0=none, -1=all) |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
41 maxsubject = 67 # truncate subject line longer than this |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
42 diffstat = True # add a diffstat before the diff content |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
43 sources = serve # notify if source of incoming changes in this list |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
44 # (serve == ssh or http, push, pull, bundle) |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
45 [email] |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
46 from = user@host.com # email address to send as if none given |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
47 [web] |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
48 baseurl = http://hgserver/... # root of hg web site for browsing commits |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
49 |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
50 notify config file has same format as regular hgrc. it has two |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
51 sections so you can express subscriptions in whatever way is handier |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
52 for you. |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
53 |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
54 [usersubs] |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
55 # key is subscriber email, value is ","-separated list of glob patterns |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
56 user@host = pattern |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
57 |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
58 [reposubs] |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
59 # key is glob pattern, value is ","-separated list of subscriber emails |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
60 pattern = user@host |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
61 |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
62 glob patterns are matched against path to repo root. |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
63 |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
64 if you like, you can put notify config file in repo that users can |
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
65 push changes to, they can manage their own subscriptions.''' |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
66 |
3891 | 67 from mercurial.i18n import _ |
6211
f89fd07fc51d
Expand import * to allow Pyflakes to find problems
Joel Rosdahl <joel@rosdahl.net>
parents:
5975
diff
changeset
|
68 from mercurial.node import bin, short |
3877
abaee83ce0a6
Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents:
3876
diff
changeset
|
69 from mercurial import patch, cmdutil, templater, util, mail |
abaee83ce0a6
Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents:
3876
diff
changeset
|
70 import email.Parser, fnmatch, socket, time |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
71 |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
72 # 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
|
73 single_template = ''' |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
74 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
|
75 From: {author} |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
76 |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
77 changeset {node|short} in {root} |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
78 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
|
79 description: |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
80 \t{desc|tabindent|strip} |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
81 '''.lstrip() |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
82 |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
83 # 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
|
84 # 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
|
85 # strange. |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
86 multiple_template = ''' |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
87 changeset {node|short} in {root} |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
88 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
|
89 summary: {desc|firstline} |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
90 ''' |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
91 |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
92 deftemplates = { |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
93 'changegroup': multiple_template, |
4498
4dfb9f232a63
Fixed indentation in hgext/notify.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4479
diff
changeset
|
94 } |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
95 |
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
96 class notifier(object): |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
97 '''email notification class.''' |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
98 |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
99 def __init__(self, ui, repo, hooktype): |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
100 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
|
101 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
|
102 if cfg: |
3434
bf10cd8bc981
use ui.readsections in the notify extension
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3397
diff
changeset
|
103 self.ui.readsections(cfg, 'usersubs', 'reposubs') |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
104 self.repo = repo |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
105 self.stripcount = int(self.ui.config('notify', 'strip', 0)) |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
106 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
|
107 self.domain = self.ui.config('notify', 'domain') |
7498
64840fcb79e1
notify: no charset conversion when testing
Christian Ebert <blacktrash@gmx.net>
parents:
7369
diff
changeset
|
108 self.test = self.ui.configbool('notify', 'test', True) |
7116
e981725da3fe
notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents:
6979
diff
changeset
|
109 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
|
110 self.subs = self.subscribers() |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
111 |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
112 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
|
113 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
|
114 self.ui.config('notify', 'template')) |
3739
16f8e7d1dd54
fix notify with new ui buffering
Matt Mackall <mpm@selenic.com>
parents:
3679
diff
changeset
|
115 self.t = cmdutil.changeset_templater(self.ui, self.repo, |
3876
1e0b94cfba0e
Remove deprecated old-style branch support
Matt Mackall <mpm@selenic.com>
parents:
3739
diff
changeset
|
116 False, mapfile, False) |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
117 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
|
118 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
|
119 if template: |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
120 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
|
121 self.t.use_template(template) |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
122 |
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
123 def strip(self, path): |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
124 '''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
|
125 |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
126 path = util.pconvert(path) |
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
127 count = self.stripcount |
2326
d0ba2f6b9d97
notify: fix off by one error.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2296
diff
changeset
|
128 while count > 0: |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
129 c = path.find('/') |
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
130 if c == -1: |
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
131 break |
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
132 path = path[c+1:] |
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
133 count -= 1 |
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
134 return path |
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
135 |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
136 def fixmail(self, addr): |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
137 '''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
|
138 |
5975
75d9fe70c654
templater: move email function to util
Matt Mackall <mpm@selenic.com>
parents:
4500
diff
changeset
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 return addr + '@' + self.domain |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
146 return addr |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
147 |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
148 def subscribers(self): |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
149 '''return list of email addresses of subscribers to this repo.''' |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
150 |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
151 subs = {} |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
152 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
|
153 for pat in pats.split(','): |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
154 if fnmatch.fnmatch(self.repo.root, pat.strip()): |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
155 subs[self.fixmail(user)] = 1 |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
156 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
|
157 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
|
158 for user in users.split(','): |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
159 subs[self.fixmail(user)] = 1 |
7116
e981725da3fe
notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents:
6979
diff
changeset
|
160 subs = util.sort(subs) |
7498
64840fcb79e1
notify: no charset conversion when testing
Christian Ebert <blacktrash@gmx.net>
parents:
7369
diff
changeset
|
161 return [mail.addressencode(self.ui, s, self.charsets, self.test) |
64840fcb79e1
notify: no charset conversion when testing
Christian Ebert <blacktrash@gmx.net>
parents:
7369
diff
changeset
|
162 for s in subs] |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
163 |
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
164 def url(self, path=None): |
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
165 return self.ui.config('web', 'baseurl') + (path or self.root) |
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
166 |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
167 def node(self, node): |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
168 '''format one changeset.''' |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
169 |
7369
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7308
diff
changeset
|
170 self.t.show(self.repo[node], changes=self.repo.changelog.read(node), |
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'), |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
172 root=self.repo.root, |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
173 webroot=self.root) |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
174 |
2230
332950340788
localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2225
diff
changeset
|
175 def skipsource(self, source): |
332950340788
localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2225
diff
changeset
|
176 '''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
|
177 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
|
178 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
|
179 |
3739
16f8e7d1dd54
fix notify with new ui buffering
Matt Mackall <mpm@selenic.com>
parents:
3679
diff
changeset
|
180 def send(self, node, count, data): |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
181 '''send message.''' |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
182 |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
183 p = email.Parser.Parser() |
3739
16f8e7d1dd54
fix notify with new ui buffering
Matt Mackall <mpm@selenic.com>
parents:
3679
diff
changeset
|
184 msg = p.parsestr(data) |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
185 |
7116
e981725da3fe
notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents:
6979
diff
changeset
|
186 # store sender and subject |
e981725da3fe
notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents:
6979
diff
changeset
|
187 sender, subject = msg['From'], msg['Subject'] |
e981725da3fe
notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents:
6979
diff
changeset
|
188 # create fresh mime message from msg body |
e981725da3fe
notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents:
6979
diff
changeset
|
189 text = msg.get_payload() |
e981725da3fe
notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents:
6979
diff
changeset
|
190 # for notification prefer readability over data precision |
7498
64840fcb79e1
notify: no charset conversion when testing
Christian Ebert <blacktrash@gmx.net>
parents:
7369
diff
changeset
|
191 msg = mail.mimeencode(self.ui, text, self.charsets, self.test) |
7116
e981725da3fe
notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents:
6979
diff
changeset
|
192 |
e981725da3fe
notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents:
6979
diff
changeset
|
193 def fix_subject(subject): |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
194 '''try to make subject line exist and be useful.''' |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
195 |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
196 if not subject: |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
197 if count > 1: |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
198 subject = _('%s: %d new changesets') % (self.root, count) |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
199 else: |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
200 changes = self.repo.changelog.read(node) |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
201 s = changes[4].lstrip().split('\n', 1)[0].rstrip() |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
202 subject = '%s: %s' % (self.root, s) |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
203 maxsubject = int(self.ui.config('notify', 'maxsubject', 67)) |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
204 if maxsubject and len(subject) > maxsubject: |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
205 subject = subject[:maxsubject-3] + '...' |
7498
64840fcb79e1
notify: no charset conversion when testing
Christian Ebert <blacktrash@gmx.net>
parents:
7369
diff
changeset
|
206 msg['Subject'] = mail.headencode(self.ui, subject, |
64840fcb79e1
notify: no charset conversion when testing
Christian Ebert <blacktrash@gmx.net>
parents:
7369
diff
changeset
|
207 self.charsets, self.test) |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
208 |
7116
e981725da3fe
notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents:
6979
diff
changeset
|
209 def fix_sender(sender): |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
210 '''try to make message have proper sender.''' |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
211 |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
212 if not sender: |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
213 sender = self.ui.config('email', 'from') or self.ui.username() |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
214 if '@' not in sender or '@localhost' in sender: |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
215 sender = self.fixmail(sender) |
7498
64840fcb79e1
notify: no charset conversion when testing
Christian Ebert <blacktrash@gmx.net>
parents:
7369
diff
changeset
|
216 msg['From'] = mail.addressencode(self.ui, sender, |
64840fcb79e1
notify: no charset conversion when testing
Christian Ebert <blacktrash@gmx.net>
parents:
7369
diff
changeset
|
217 self.charsets, self.test) |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
218 |
6229
c3182eeb70ea
dates: improve timezone handling
Matt Mackall <mpm@selenic.com>
parents:
6211
diff
changeset
|
219 msg['Date'] = util.datestr(format="%a, %d %b %Y %H:%M:%S %1%2") |
7116
e981725da3fe
notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents:
6979
diff
changeset
|
220 fix_subject(subject) |
e981725da3fe
notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents:
6979
diff
changeset
|
221 fix_sender(sender) |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
222 |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
223 msg['X-Hg-Notification'] = 'changeset ' + short(node) |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
224 if not msg['Message-Id']: |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
225 msg['Message-Id'] = ('<hg.%s.%s.%s@%s>' % |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
226 (short(node), int(time.time()), |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
227 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
|
228 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
|
229 |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
230 msgtext = msg.as_string(0) |
7498
64840fcb79e1
notify: no charset conversion when testing
Christian Ebert <blacktrash@gmx.net>
parents:
7369
diff
changeset
|
231 if self.test: |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
232 self.ui.write(msgtext) |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
233 if not msgtext.endswith('\n'): |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
234 self.ui.write('\n') |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
235 else: |
2329
90368f89340a
notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2326
diff
changeset
|
236 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
|
237 (len(self.subs), count)) |
5975
75d9fe70c654
templater: move email function to util
Matt Mackall <mpm@selenic.com>
parents:
4500
diff
changeset
|
238 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
|
239 self.subs, msgtext) |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
240 |
2296
6e8e3dd7976e
notify changeset diff should be against current node instead of tip
"Aurelien Jacobs <aurel@gnuage.org>"
parents:
2230
diff
changeset
|
241 def diff(self, node, ref): |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
242 maxdiff = int(self.ui.config('notify', 'maxdiff', 300)) |
2224
e8f47dfb70f4
notify extension: generate right number of diffs
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2221
diff
changeset
|
243 prev = self.repo.changelog.parents(node)[0] |
6979 | 244 |
7308
b6f5490effbf
patch: turn patch.diff() into a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7127
diff
changeset
|
245 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
|
246 difflines = ''.join(chunks).splitlines() |
6979 | 247 |
3096
f422c8265ae5
Add support for diffstat in commit emails, and move diffstat from
Matt Doar <matt@xensource.com>
parents:
3017
diff
changeset
|
248 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
|
249 s = patch.diffstat(difflines) |
4077
1305ba7dee88
Prevent type exception on concatenation if diffstat returns None.
Sean Dague <sean@dague.net>
parents:
3739
diff
changeset
|
250 # 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
|
251 if s: |
1305ba7dee88
Prevent type exception on concatenation if diffstat returns None.
Sean Dague <sean@dague.net>
parents:
3739
diff
changeset
|
252 self.ui.write('\ndiffstat:\n\n%s' % s) |
6305
e8d447d91cdb
notify: print diffstat even if maxline == 0
Benoît Allard <benoit@aeteurope.nl>
parents:
6229
diff
changeset
|
253 if maxdiff == 0: |
e8d447d91cdb
notify: print diffstat even if maxline == 0
Benoît Allard <benoit@aeteurope.nl>
parents:
6229
diff
changeset
|
254 return |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
255 if maxdiff > 0 and len(difflines) > maxdiff: |
3739
16f8e7d1dd54
fix notify with new ui buffering
Matt Mackall <mpm@selenic.com>
parents:
3679
diff
changeset
|
256 self.ui.write(_('\ndiffs (truncated from %d to %d lines):\n\n') % |
16f8e7d1dd54
fix notify with new ui buffering
Matt Mackall <mpm@selenic.com>
parents:
3679
diff
changeset
|
257 (len(difflines), maxdiff)) |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
258 difflines = difflines[:maxdiff] |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
259 elif difflines: |
3739
16f8e7d1dd54
fix notify with new ui buffering
Matt Mackall <mpm@selenic.com>
parents:
3679
diff
changeset
|
260 self.ui.write(_('\ndiffs (%d lines):\n\n') % len(difflines)) |
6979 | 261 self.ui.write("\n".join(difflines)) |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
262 |
2230
332950340788
localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2225
diff
changeset
|
263 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
|
264 '''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
|
265 |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
266 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
|
267 changegroup. else send one email per changeset.''' |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
268 n = notifier(ui, repo, hooktype) |
2329
90368f89340a
notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2326
diff
changeset
|
269 if not n.subs: |
3679
2956948b81f3
fix warnings generated by pygettext.py.
Marcos Chaves <marcos.nospam@gmail.com>
parents:
3643
diff
changeset
|
270 ui.debug(_('notify: no subscribers to repo %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
|
271 return |
90368f89340a
notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2326
diff
changeset
|
272 if n.skipsource(source): |
90368f89340a
notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2326
diff
changeset
|
273 ui.debug(_('notify: changes have source "%s" - skipping\n') % |
4498
4dfb9f232a63
Fixed indentation in hgext/notify.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4479
diff
changeset
|
274 source) |
2230
332950340788
localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2225
diff
changeset
|
275 return |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
276 node = bin(node) |
3739
16f8e7d1dd54
fix notify with new ui buffering
Matt Mackall <mpm@selenic.com>
parents:
3679
diff
changeset
|
277 ui.pushbuffer() |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
278 if hooktype == 'changegroup': |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6305
diff
changeset
|
279 start = repo[node].rev() |
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6305
diff
changeset
|
280 end = len(repo) |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
281 count = end - start |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
282 for rev in xrange(start, end): |
6974
8997b81a33da
fix changegroup.notify hook broken by fb42030d79d6
Dennis Schoen <dennis.schoen@epublica.de>
parents:
6866
diff
changeset
|
283 n.node(repo[rev].node()) |
2296
6e8e3dd7976e
notify changeset diff should be against current node instead of tip
"Aurelien Jacobs <aurel@gnuage.org>"
parents:
2230
diff
changeset
|
284 n.diff(node, repo.changelog.tip()) |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
285 else: |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
286 count = 1 |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
287 n.node(node) |
2296
6e8e3dd7976e
notify changeset diff should be against current node instead of tip
"Aurelien Jacobs <aurel@gnuage.org>"
parents:
2230
diff
changeset
|
288 n.diff(node, node) |
3739
16f8e7d1dd54
fix notify with new ui buffering
Matt Mackall <mpm@selenic.com>
parents:
3679
diff
changeset
|
289 data = ui.popbuffer() |
16f8e7d1dd54
fix notify with new ui buffering
Matt Mackall <mpm@selenic.com>
parents:
3679
diff
changeset
|
290 n.send(node, count, data) |