hgcia: Handle URL like in notify (
issue2406)
The URL must be composed with baseurl and webroot like in notify
--- a/hgext/hgcia.py Thu May 12 16:41:56 2011 +0200
+++ b/hgext/hgcia.py Wed May 11 18:18:50 2011 +0200
@@ -18,7 +18,7 @@
# Append a diffstat to the log message (optional)
#diffstat = False
# Template to use for log messages (optional)
- #template = {desc}\\n{baseurl}/rev/{node}-- {diffstat}
+ #template = {desc}\\n{baseurl}{webroot}/rev/{node}-- {diffstat}
# Style to use (optional)
#style = foo
# The URL of the CIA notification service (optional)
@@ -28,6 +28,8 @@
#url = http://cia.vc/
# print message instead of sending it (optional)
#test = False
+ # number of slashes to strip for url paths
+ #strip = 0
[hooks]
# one of these:
@@ -66,6 +68,8 @@
self.cia = cia
self.ctx = ctx
self.url = self.cia.url
+ if self.url:
+ self.url += self.cia.root
def fileelem(self, path, uri, action):
if uri:
@@ -120,7 +124,9 @@
diffstat = self.cia.diffstat and self.diffstat() or ''
self.cia.ui.pushbuffer()
self.cia.templater.show(self.ctx, changes=self.ctx.changeset(),
- url=self.cia.url, diffstat=diffstat)
+ baseurl=self.cia.ui.config('web', 'baseurl'),
+ url=self.url, diffstat=diffstat,
+ webroot=self.cia.root)
return self.cia.ui.popbuffer()
def xml(self):
@@ -184,6 +190,8 @@
self.emailfrom = self.ui.config('email', 'from')
self.dryrun = self.ui.configbool('cia', 'test')
self.url = self.ui.config('web', 'baseurl')
+ self.stripcount = int(self.ui.config('cia', 'strip', 0))
+ self.root = self.strip(self.repo.root)
style = self.ui.config('cia', 'style')
template = self.ui.config('cia', 'template')
@@ -195,6 +203,19 @@
t.use_template(template)
self.templater = t
+ def strip(self, path):
+ '''strip leading slashes from local path, turn into web-safe path.'''
+
+ path = util.pconvert(path)
+ count = self.stripcount
+ while count > 0:
+ c = path.find('/')
+ if c == -1:
+ break
+ path = path[c + 1:]
+ count -= 1
+ return path
+
def sendrpc(self, msg):
srv = xmlrpclib.Server(self.ciaurl)
res = srv.hub.deliver(msg)
--- a/tests/test-hgcia.t Thu May 12 16:41:56 2011 +0200
+++ b/tests/test-hgcia.t Wed May 11 18:18:50 2011 +0200
@@ -7,6 +7,9 @@
> [hooks]
> changegroup.cia = python:hgext.hgcia.hook
>
+ > [web]
+ > baseurl = http://hgserver/
+ >
> [cia]
> user = testuser
> project = testproject
@@ -43,8 +46,8 @@
<author>test</author>
<version>0:e63c23eaa88a</version>
<log>foo</log>
-
- <files><file action="add">foo</file></files>
+ <url>http://hgserver/$TESTTMP/cia/rev/e63c23eaa88a</url>
+ <files><file uri="http://hgserver/$TESTTMP/cia/file/e63c23eaa88a/foo" action="add">foo</file></files>
</commit>
</body>
<timestamp>0</timestamp>