(stable) merge with default branch stable
authorChristian Ebert <blacktrash@gmx.net>
Tue, 12 Feb 2008 23:09:53 +0100
branchstable
changeset 403 9a93b5d66e65
parent 392 45a318c5ea20 (current diff)
parent 401 05d0c3e4efdc (diff)
child 404 45d3ea301c03
(stable) merge with default branch
--- a/hgkw/keyword.py	Sat Feb 09 20:17:09 2008 +0100
+++ b/hgkw/keyword.py	Tue Feb 12 23:09:53 2008 +0100
@@ -82,15 +82,17 @@
 
 from mercurial import commands, cmdutil, context, dispatch, filelog, revlog
 from mercurial import patch, localrepo, templater, templatefilters, util
+from mercurial.hgweb import webcommands
 from mercurial.node import *
 from mercurial.i18n import _
-import re, shutil, tempfile, time, os
+import re, shutil, tempfile, time
 
 commands.optionalrepo += ' kwdemo'
 
 # hg commands that do not act on keywords
 nokwcommands = ('add addremove bundle copy export grep identify incoming init'
-                ' log outgoing push remove rename rollback tip convert email')
+                ' log outgoing push remove rename rollback tip'
+                ' convert email glog')
 
 # hg commands that trigger expansion only when writing to working dir,
 # not when reading filelog, and unexpand when reading from working dir
@@ -101,7 +103,7 @@
     return time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(date[0]))
 
 
-_kwtemplater, _cmd, _cmdoptions = None, None, None
+_kwtemplater = _cmd = _cmdoptions = None
  
 # store originals of monkeypatches
 _patchfile_init = patch.patchfile.__init__
@@ -116,6 +118,16 @@
         kwshrunk = _kwtemplater.shrink(''.join(self.lines))
         self.lines = kwshrunk.splitlines(True)
 
+def _kwweb_changeset(web, req, tmpl):
+    '''Wraps webcommands.changeset turning off keyword expansion.'''
+    _kwtemplater.matcher = util.never
+    return web.changeset(tmpl, web.changectx(req))
+
+def _kwweb_filediff(web, req, tmpl):
+    '''Wraps webcommands.filediff turning off keyword expansion.'''
+    _kwtemplater.matcher = util.never
+    return web.filediff(tmpl, web.filectx(req))
+
 def _kwdispatch_parse(ui, args):
     '''Monkeypatch dispatch._parse to obtain
     current command and command options (global _cmd, _cmdoptions).'''
@@ -123,6 +135,7 @@
     _cmd, func, args, options, _cmdoptions = _dispatch_parse(ui, args)
     return _cmd, func, args, options, _cmdoptions
 
+# dispatch._parse is run before reposetup, so wrap it here
 dispatch._parse = _kwdispatch_parse
 
 
@@ -141,11 +154,11 @@
         'Header': '{root}/{file},v {node|short} {date|utcdate} {author|user}',
     }
 
-    def __init__(self, ui, repo, inc, exc, restrict):
+    def __init__(self, ui, repo, inc, exc, hgcmd):
         self.ui = ui
         self.repo = repo
         self.matcher = util.matcher(repo.root, inc=inc, exc=exc)[1]
-        self.restrict = restrict
+        self.restrict = hgcmd in restricted.split()
         self.commitnode = None
         self.path = ''
 
@@ -427,7 +440,7 @@
 
     try:
         if (not repo.local() or hgcmd in nokwcommands.split() 
-            or '.hg' in repo.root.split(os.sep)
+            or '.hg' in util.splitpath(repo.root)
             or repo._url.startswith('bundle:')):
             return
     except AttributeError:
@@ -451,8 +464,7 @@
         if node1 is not None and node1 != repo.changectx().node():
             hgcmd = 'diff1'
 
-    restrict = hgcmd in restricted.split()
-    _kwtemplater = kwtemplater(ui, repo, inc, exc, restrict)
+    _kwtemplater = kwtemplater(ui, repo, inc, exc, hgcmd)
 
     class kwrepo(repo.__class__):
         def file(self, f, kwmatch=False):
@@ -464,7 +476,7 @@
 
         def wread(self, filename):
             data = super(kwrepo, self).wread(filename)
-            if restrict and _kwtemplater.matcher(filename):
+            if _kwtemplater.restrict and _kwtemplater.matcher(filename):
                 return _kwtemplater.shrink(data)
             return data
 
@@ -513,6 +525,8 @@
 
     repo.__class__ = kwrepo
     patch.patchfile.__init__ = _kwpatchfile_init
+    webcommands.changeset = webcommands.rev = _kwweb_changeset
+    webcommands.filediff = webcommands.diff = _kwweb_filediff
 
 
 cmdtable = {