Mercurial > hg
annotate hgext/hgcia.py @ 16719:e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
For the PyPy repo with 744 branches and 843 branch heads, this brings
hg log -r default over NFS from:
CallCount Recursive Total(ms) Inline(ms) module:lineno(function)
3249 0 1.3222 1.3222 <open>
3244 0 0.6211 0.6211 <method 'close' of 'file' objects>
3243 0 0.0800 0.0800 <method 'read' of 'file' objects>
3241 0 0.0660 0.0660 <method 'seek' of 'file' objects>
3905 0 0.0476 0.0476 <zlib.decompress>
3281 0 2.6756 0.0472 mercurial.changelog:182(read)
+3281 0 2.5256 0.0453 +mercurial.revlog:881(revision)
+3276 0 0.0389 0.0196 +mercurial.changelog:28(decodeextra)
+6562 0 0.0123 0.0123 +<method 'split' of 'str' objects>
+6562 0 0.0408 0.0073 +mercurial.encoding:61(tolocal)
+3281 0 0.0054 0.0054 +<method 'index' of 'str' objects>
3241 0 2.2464 0.0456 mercurial.revlog:818(_loadchunk)
+3241 0 0.6205 0.6205 +<method 'close' of 'file' objects>
+3241 0 0.0765 0.0765 +<method 'read' of 'file' objects>
+3241 0 0.0660 0.0660 +<method 'seek' of 'file' objects>
+3241 0 1.4209 0.0135 +mercurial.store:374(__call__)
+3241 0 0.0122 0.0107 +mercurial.revlog:810(_addchunk)
3281 0 2.5256 0.0453 mercurial.revlog:881(revision)
+3280 0 0.0175 0.0175 +mercurial.revlog:305(rev)
+3281 0 2.2819 0.0119 +mercurial.revlog:847(_chunkraw)
+3281 0 0.0603 0.0083 +mercurial.revlog:945(_checkhash)
+3281 0 0.0051 0.0051 +mercurial.revlog:349(flags)
+3281 0 0.0040 0.0040 +<mercurial.mpatch.patches>
13682 0 0.0479 0.0248 <method 'decode' of 'str' objects>
+7418 0 0.0228 0.0076 +encodings.utf_8:15(decode)
+1 0 0.0003 0.0000 +encodings:71(search_function)
3248 0 1.3995 0.0246 mercurial.scmutil:218(__call__)
+3248 0 1.3222 1.3222 +<open>
+3248 0 0.0235 0.0184 +os.path:80(split)
+3248 0 0.0084 0.0068 +mercurial.scmutil:92(__call__)
Time: real 2.750 secs (user 0.680+0.000 sys 0.360+0.000)
down to:
CallCount Recursive Total(ms) Inline(ms) module:lineno(function)
55 31 0.0197 0.0163 <__import__>
+1 0 0.0006 0.0002 +mercurial.context:8(<module>)
+1 0 0.0042 0.0001 +mercurial.revlog:12(<module>)
+1 0 0.0002 0.0001 +mercurial.match:8(<module>)
+1 0 0.0003 0.0001 +mercurial.dirstate:7(<module>)
+1 0 0.0057 0.0001 +mercurial.changelog:8(<module>)
1 0 0.0117 0.0032 mercurial.localrepo:525(_readbranchcache)
+844 0 0.0015 0.0015 +<binascii.unhexlify>
+845 0 0.0010 0.0010 +<method 'split' of 'str' objects>
+843 0 0.0045 0.0009 +mercurial.encoding:61(tolocal)
+843 0 0.0004 0.0004 +<method 'setdefault' of 'dict' objects>
+1 0 0.0003 0.0003 +<method 'close' of 'file' objects>
3 0 0.0029 0.0029 <method 'read' of 'file' objects>
9 0 0.0018 0.0018 <open>
990 0 0.0017 0.0017 <binascii.unhexlify>
53 0 0.0016 0.0016 mercurial.demandimport:43(__init__)
862 0 0.0015 0.0015 <_codecs.utf_8_decode>
862 0 0.0037 0.0014 <method 'decode' of 'str' objects>
+862 0 0.0023 0.0008 +encodings.utf_8:15(decode)
981 0 0.0011 0.0011 <method 'split' of 'str' objects>
861 0 0.0046 0.0009 mercurial.encoding:61(tolocal)
+861 0 0.0037 0.0014 +<method 'decode' of 'str' objects>
862 0 0.0023 0.0008 encodings.utf_8:15(decode)
+862 0 0.0015 0.0015 +<_codecs.utf_8_decode>
4 0 0.0008 0.0008 <method 'close' of 'file' objects>
179 154 0.0202 0.0004 mercurial.demandimport:83(__getattribute__)
+36 11 0.0199 0.0003 +mercurial.demandimport:55(_load)
+72 0 0.0001 0.0001 +mercurial.demandimport:83(__getattribute__)
+36 0 0.0000 0.0000 +<getattr>
1 0 0.0015 0.0004 mercurial.tags:148(_readtagcache)
Time: real 0.060 secs (user 0.030+0.000 sys 0.010+0.000)
author | Brodie Rao <brodie@sf.io> |
---|---|
date | Sun, 13 May 2012 14:04:04 +0200 |
parents | cfb6682961b8 |
children | 38caf405d010 |
rev | line source |
---|---|
7438 | 1 # Copyright (C) 2007-8 Brendan Cully <brendan@kublai.com> |
10263 | 2 # |
3 # This software may be used and distributed according to the terms of the | |
4 # GNU General Public License version 2 or any later version. | |
7438 | 5 |
8935
f4f0e902b750
extensions: change descriptions for hook-providing extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8894
diff
changeset
|
6 """hooks for integrating with the CIA.vc notification service |
7438 | 7 |
9260
b2f37dbc5952
hgcia: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9208
diff
changeset
|
8 This is meant to be run as a changegroup or incoming hook. To |
b2f37dbc5952
hgcia: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9208
diff
changeset
|
9 configure it, set the following options in your hgrc:: |
7438 | 10 |
9208
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
11 [cia] |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
12 # your registered CIA user name |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
13 user = foo |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
14 # the name of the project in CIA |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
15 project = foo |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
16 # the module (subproject) (optional) |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
17 #module = foo |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
18 # Append a diffstat to the log message (optional) |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
19 #diffstat = False |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
20 # Template to use for log messages (optional) |
14314
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
21 #template = {desc}\\n{baseurl}{webroot}/rev/{node}-- {diffstat} |
9208
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
22 # Style to use (optional) |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
23 #style = foo |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
24 # The URL of the CIA notification service (optional) |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
25 # You can use mailto: URLs to send by email, eg |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
26 # mailto:cia@cia.vc |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
27 # Make sure to set email.from if you do this. |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
28 #url = http://cia.vc/ |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
29 # print message instead of sending it (optional) |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
30 #test = False |
14314
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
31 # number of slashes to strip for url paths |
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
32 #strip = 0 |
7438 | 33 |
9208
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
34 [hooks] |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
35 # one of these: |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
36 changegroup.cia = python:hgcia.hook |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
37 #incoming.cia = python:hgcia.hook |
7438 | 38 |
9208
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
39 [web] |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
40 # If you want hyperlinks (optional) |
12d119ae39bc
hgcia: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
41 baseurl = http://server/path/to/repo |
7438 | 42 """ |
43 | |
44 from mercurial.i18n import _ | |
11750
26e413f55b5e
hgcia/color: remove star imports
Brodie Rao <brodie@bitheap.org>
parents:
10611
diff
changeset
|
45 from mercurial.node import bin, short |
7438 | 46 from mercurial import cmdutil, patch, templater, util, mail |
47 import email.Parser | |
48 | |
16688
cfb6682961b8
cleanup: replace naked excepts with more specific ones
Brodie Rao <brodie@sf.io>
parents:
15776
diff
changeset
|
49 import socket, xmlrpclib |
7438 | 50 from xml.sax import saxutils |
51 | |
52 socket_timeout = 30 # seconds | |
16688
cfb6682961b8
cleanup: replace naked excepts with more specific ones
Brodie Rao <brodie@sf.io>
parents:
15776
diff
changeset
|
53 if util.safehasattr(socket, 'setdefaulttimeout'): |
7438 | 54 # set a timeout for the socket so you don't have to wait so looooong |
55 # when cia.vc is having problems. requires python >= 2.3: | |
56 socket.setdefaulttimeout(socket_timeout) | |
57 | |
58 HGCIA_VERSION = '0.1' | |
59 HGCIA_URL = 'http://hg.kublai.com/mercurial/hgcia' | |
60 | |
61 | |
62 class ciamsg(object): | |
63 """ A CIA message """ | |
64 def __init__(self, cia, ctx): | |
65 self.cia = cia | |
66 self.ctx = ctx | |
67 self.url = self.cia.url | |
14314
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
68 if self.url: |
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
69 self.url += self.cia.root |
7438 | 70 |
71 def fileelem(self, path, uri, action): | |
72 if uri: | |
73 uri = ' uri=%s' % saxutils.quoteattr(uri) | |
74 return '<file%s action=%s>%s</file>' % ( | |
75 uri, saxutils.quoteattr(action), saxutils.escape(path)) | |
76 | |
77 def fileelems(self): | |
78 n = self.ctx.node() | |
13878
a8d13ee0ce68
misc: replace .parents()[0] with p1()
Matt Mackall <mpm@selenic.com>
parents:
13551
diff
changeset
|
79 f = self.cia.repo.status(self.ctx.p1().node(), n) |
7438 | 80 url = self.url or '' |
14850
a95242af945c
hgcia: Set default value of strip to -1 (issue2891)
Cédric Krier <ced@b2ck.com>
parents:
14314
diff
changeset
|
81 if url and url[-1] == '/': |
a95242af945c
hgcia: Set default value of strip to -1 (issue2891)
Cédric Krier <ced@b2ck.com>
parents:
14314
diff
changeset
|
82 url = url[:-1] |
7438 | 83 elems = [] |
84 for path in f[0]: | |
85 uri = '%s/diff/%s/%s' % (url, short(n), path) | |
86 elems.append(self.fileelem(path, url and uri, 'modify')) | |
87 for path in f[1]: | |
88 # TODO: copy/rename ? | |
89 uri = '%s/file/%s/%s' % (url, short(n), path) | |
90 elems.append(self.fileelem(path, url and uri, 'add')) | |
91 for path in f[2]: | |
92 elems.append(self.fileelem(path, '', 'remove')) | |
93 | |
94 return '\n'.join(elems) | |
95 | |
96 def sourceelem(self, project, module=None, branch=None): | |
97 msg = ['<source>', '<project>%s</project>' % saxutils.escape(project)] | |
98 if module: | |
99 msg.append('<module>%s</module>' % saxutils.escape(module)) | |
100 if branch: | |
101 msg.append('<branch>%s</branch>' % saxutils.escape(branch)) | |
102 msg.append('</source>') | |
103 | |
104 return '\n'.join(msg) | |
105 | |
106 def diffstat(self): | |
8778
c5f36402daad
use new style classes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8541
diff
changeset
|
107 class patchbuf(object): |
7438 | 108 def __init__(self): |
109 self.lines = [] | |
110 # diffstat is stupid | |
111 self.name = 'cia' | |
112 def write(self, data): | |
15776
55a85a55f020
hgcia: fix diffstat support
Matt Mackall <mpm@selenic.com>
parents:
14850
diff
changeset
|
113 self.lines += data.splitlines(True) |
7438 | 114 def close(self): |
115 pass | |
116 | |
117 n = self.ctx.node() | |
118 pbuf = patchbuf() | |
10611
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10529
diff
changeset
|
119 cmdutil.export(self.cia.repo, [n], fp=pbuf) |
7438 | 120 return patch.diffstat(pbuf.lines) or '' |
121 | |
122 def logmsg(self): | |
123 diffstat = self.cia.diffstat and self.diffstat() or '' | |
124 self.cia.ui.pushbuffer() | |
125 self.cia.templater.show(self.ctx, changes=self.ctx.changeset(), | |
14314
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
126 baseurl=self.cia.ui.config('web', 'baseurl'), |
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
127 url=self.url, diffstat=diffstat, |
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
128 webroot=self.cia.root) |
7438 | 129 return self.cia.ui.popbuffer() |
130 | |
131 def xml(self): | |
132 n = short(self.ctx.node()) | |
133 src = self.sourceelem(self.cia.project, module=self.cia.module, | |
134 branch=self.ctx.branch()) | |
135 # unix timestamp | |
136 dt = self.ctx.date() | |
137 timestamp = dt[0] | |
138 | |
139 author = saxutils.escape(self.ctx.user()) | |
140 rev = '%d:%s' % (self.ctx.rev(), n) | |
141 log = saxutils.escape(self.logmsg()) | |
142 | |
14850
a95242af945c
hgcia: Set default value of strip to -1 (issue2891)
Cédric Krier <ced@b2ck.com>
parents:
14314
diff
changeset
|
143 url = self.url |
a95242af945c
hgcia: Set default value of strip to -1 (issue2891)
Cédric Krier <ced@b2ck.com>
parents:
14314
diff
changeset
|
144 if url and url[-1] == '/': |
a95242af945c
hgcia: Set default value of strip to -1 (issue2891)
Cédric Krier <ced@b2ck.com>
parents:
14314
diff
changeset
|
145 url = url[:-1] |
a95242af945c
hgcia: Set default value of strip to -1 (issue2891)
Cédric Krier <ced@b2ck.com>
parents:
14314
diff
changeset
|
146 url = url and '<url>%s/rev/%s</url>' % (saxutils.escape(url), n) or '' |
7438 | 147 |
148 msg = """ | |
149 <message> | |
150 <generator> | |
151 <name>Mercurial (hgcia)</name> | |
152 <version>%s</version> | |
153 <url>%s</url> | |
154 <user>%s</user> | |
155 </generator> | |
156 %s | |
157 <body> | |
158 <commit> | |
159 <author>%s</author> | |
160 <version>%s</version> | |
161 <log>%s</log> | |
162 %s | |
163 <files>%s</files> | |
164 </commit> | |
165 </body> | |
166 <timestamp>%d</timestamp> | |
167 </message> | |
168 """ % \ | |
169 (HGCIA_VERSION, saxutils.escape(HGCIA_URL), | |
170 saxutils.escape(self.cia.user), src, author, rev, log, url, | |
171 self.fileelems(), timestamp) | |
172 | |
173 return msg | |
174 | |
175 | |
176 class hgcia(object): | |
177 """ CIA notification class """ | |
178 | |
179 deftemplate = '{desc}' | |
180 dstemplate = '{desc}\n-- \n{diffstat}' | |
181 | |
182 def __init__(self, ui, repo): | |
183 self.ui = ui | |
184 self.repo = repo | |
185 | |
186 self.ciaurl = self.ui.config('cia', 'url', 'http://cia.vc') | |
187 self.user = self.ui.config('cia', 'user') | |
188 self.project = self.ui.config('cia', 'project') | |
189 self.module = self.ui.config('cia', 'module') | |
190 self.diffstat = self.ui.configbool('cia', 'diffstat') | |
191 self.emailfrom = self.ui.config('email', 'from') | |
192 self.dryrun = self.ui.configbool('cia', 'test') | |
193 self.url = self.ui.config('web', 'baseurl') | |
14850
a95242af945c
hgcia: Set default value of strip to -1 (issue2891)
Cédric Krier <ced@b2ck.com>
parents:
14314
diff
changeset
|
194 # Default to -1 for backward compatibility |
a95242af945c
hgcia: Set default value of strip to -1 (issue2891)
Cédric Krier <ced@b2ck.com>
parents:
14314
diff
changeset
|
195 self.stripcount = int(self.ui.config('cia', 'strip', -1)) |
14314
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
196 self.root = self.strip(self.repo.root) |
7438 | 197 |
198 style = self.ui.config('cia', 'style') | |
199 template = self.ui.config('cia', 'template') | |
200 if not template: | |
201 template = self.diffstat and self.dstemplate or self.deftemplate | |
202 template = templater.parsestring(template, quoted=False) | |
7762
fece056bf240
add --git option to commands supporting --patch (log, incoming, history, tip)
Jim Correia <jim.correia@pobox.com>
parents:
7438
diff
changeset
|
203 t = cmdutil.changeset_templater(self.ui, self.repo, False, None, |
fece056bf240
add --git option to commands supporting --patch (log, incoming, history, tip)
Jim Correia <jim.correia@pobox.com>
parents:
7438
diff
changeset
|
204 style, False) |
7438 | 205 t.use_template(template) |
206 self.templater = t | |
207 | |
14314
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
208 def strip(self, path): |
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
209 '''strip leading slashes from local path, turn into web-safe path.''' |
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
210 |
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
211 path = util.pconvert(path) |
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
212 count = self.stripcount |
14850
a95242af945c
hgcia: Set default value of strip to -1 (issue2891)
Cédric Krier <ced@b2ck.com>
parents:
14314
diff
changeset
|
213 if count < 0: |
a95242af945c
hgcia: Set default value of strip to -1 (issue2891)
Cédric Krier <ced@b2ck.com>
parents:
14314
diff
changeset
|
214 return '' |
14314
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
215 while count > 0: |
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
216 c = path.find('/') |
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
217 if c == -1: |
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
218 break |
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
219 path = path[c + 1:] |
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
220 count -= 1 |
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
221 return path |
c322890b03e6
hgcia: Handle URL like in notify (issue2406)
Cédric Krier <ced@b2ck.com>
parents:
13878
diff
changeset
|
222 |
7438 | 223 def sendrpc(self, msg): |
224 srv = xmlrpclib.Server(self.ciaurl) | |
10529
076e8a8000a3
hgcia: report RPC errors
Brendan Cully <brendan@kublai.com>
parents:
10263
diff
changeset
|
225 res = srv.hub.deliver(msg) |
13551
bbfae32f178e
hgcia: accept "queued." xmlrpc return as success
Georg Brandl <georg@python.org>
parents:
11750
diff
changeset
|
226 if res is not True and res != 'queued.': |
10529
076e8a8000a3
hgcia: report RPC errors
Brendan Cully <brendan@kublai.com>
parents:
10263
diff
changeset
|
227 raise util.Abort(_('%s returned an error: %s') % |
076e8a8000a3
hgcia: report RPC errors
Brendan Cully <brendan@kublai.com>
parents:
10263
diff
changeset
|
228 (self.ciaurl, res)) |
7438 | 229 |
230 def sendemail(self, address, data): | |
231 p = email.Parser.Parser() | |
232 msg = p.parsestr(data) | |
233 msg['Date'] = util.datestr(format="%a, %d %b %Y %H:%M:%S %1%2") | |
234 msg['To'] = address | |
235 msg['From'] = self.emailfrom | |
236 msg['Subject'] = 'DeliverXML' | |
237 msg['Content-type'] = 'text/xml' | |
9136
31177742f54a
for calls expecting bool args, pass bool instead of int
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9062
diff
changeset
|
238 msgtext = msg.as_string() |
7438 | 239 |
240 self.ui.status(_('hgcia: sending update to %s\n') % address) | |
241 mail.sendmail(self.ui, util.email(self.emailfrom), | |
242 [address], msgtext) | |
243 | |
244 | |
245 def hook(ui, repo, hooktype, node=None, url=None, **kwargs): | |
246 """ send CIA notification """ | |
247 def sendmsg(cia, ctx): | |
248 msg = ciamsg(cia, ctx).xml() | |
249 if cia.dryrun: | |
250 ui.write(msg) | |
251 elif cia.ciaurl.startswith('mailto:'): | |
252 if not cia.emailfrom: | |
253 raise util.Abort(_('email.from must be defined when ' | |
254 'sending by email')) | |
255 cia.sendemail(cia.ciaurl[7:], msg) | |
256 else: | |
257 cia.sendrpc(msg) | |
258 | |
259 n = bin(node) | |
260 cia = hgcia(ui, repo) | |
261 if not cia.user: | |
9467
4c041f1ee1b4
do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents:
9260
diff
changeset
|
262 ui.debug('cia: no user specified') |
7438 | 263 return |
264 if not cia.project: | |
9467
4c041f1ee1b4
do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents:
9260
diff
changeset
|
265 ui.debug('cia: no project specified') |
7438 | 266 return |
267 if hooktype == 'changegroup': | |
268 start = repo.changelog.rev(n) | |
269 end = len(repo.changelog) | |
270 for rev in xrange(start, end): | |
271 n = repo.changelog.node(rev) | |
272 ctx = repo.changectx(n) | |
273 sendmsg(cia, ctx) | |
274 else: | |
275 ctx = repo.changectx(n) | |
276 sendmsg(cia, ctx) |