# HG changeset patch # User Cédric Krier # Date 1305130730 -7200 # Node ID c322890b03e6f584ec062ebf644b8af063009bd4 # Parent a389dd2852825d153ad96af4fbf71fe157a0e04d hgcia: Handle URL like in notify (issue2406) The URL must be composed with baseurl and webroot like in notify diff -r a389dd285282 -r c322890b03e6 hgext/hgcia.py --- 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) diff -r a389dd285282 -r c322890b03e6 tests/test-hgcia.t --- 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 @@ test 0:e63c23eaa88a foo - - foo + http://hgserver/$TESTTMP/cia/rev/e63c23eaa88a + foo 0