hgext/hgcia.py
changeset 14314 c322890b03e6
parent 13878 a8d13ee0ce68
child 14850 a95242af945c
--- 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)