(0.9.2compat) use templatefilters module if available; bail out in mq dir 0.9.2compat
authorChristian Ebert <blacktrash@gmx.net>
Thu, 31 Jan 2008 01:06:49 +0100
branch0.9.2compat
changeset 366 b1105cc0982f
parent 360 ed06223f88fc
child 370 a8983fed9a9e
(0.9.2compat) use templatefilters module if available; bail out in mq dir Revert to always using full definition of repo._link.
hgkw/keyword.py
tests/test-keyword
tests/test-keyword.out
--- a/hgkw/keyword.py	Thu Jan 31 14:34:45 2008 +0100
+++ b/hgkw/keyword.py	Thu Jan 31 01:06:49 2008 +0100
@@ -100,6 +100,15 @@
 
 # backwards compatibility hacks
 
+try:
+    # templatefilters module introduced in 9f1e6ab76069
+    from mercurial import templatefilters
+    template_filters = templatefilters.filters
+    template_firstline = templatefilters.firstline
+except ImportError:
+    template_filters = templater.common_filters
+    template_firstline = templater.firstline
+
 def _normal(repo, files):
     '''Backwards compatible repo.dirstate.normal/update.'''
     # 6fd953d5faea introduced dirstate.normal()
@@ -109,12 +118,6 @@
     except AttributeError:
         repo.dirstate.update(files, 'n')
 
-def _link(repo, f):
-    try:
-        return repo._link(f)
-    except AttributeError:
-        return os.path.islink(repo.wjoin(f))
-
 def _pathto(repo, f, cwd=None):
     '''kwfiles behaves similar to status, using pathto since 78b6add1f966.'''
     try:
@@ -159,7 +162,7 @@
         kwpat = r'\$(%s)(: [^$\n\r]*? )??\$' % '|'.join(escaped)
         self.re_kw = re.compile(kwpat)
 
-        templater.common_filters['utcdate'] = utcdate
+        template_filters['utcdate'] = utcdate
         self.ct = self._changeset_templater()
 
     def _changeset_templater(self):
@@ -198,7 +201,8 @@
             self.ct.use_template(self.templates[kw])
             self.ui.pushbuffer()
             self.ct.show(changenode=node, root=self.repo.root, file=path)
-            return '$%s: %s $' % (kw, templater.firstline(self.ui.popbuffer()))
+            ekw = template_firstline(self.ui.popbuffer())
+            return '$%s: %s $' % (kw, ekw)
 
         return subfunc(kwsub, data)
 
@@ -412,7 +416,9 @@
     if opts.get('untracked'):
         files += unknown
     files.sort()
-    kwfiles = [f for f in files if not _link(repo, f) and repo._kwt.matcher(f)]
+    # use full def of repo._link for backwards compatibility
+    kwfiles = [f for f in files if
+               not os.path.islink(repo.wjoin(f)) and repo._kwt.matcher(f)]
     cwd = pats and repo.getcwd() or ''
     kwfstats = not opts.get('ignore') and (('K', kwfiles),) or ()
     if opts.get('all') or opts.get('ignore'):
@@ -435,7 +441,7 @@
 
 
 def reposetup(ui, repo):
-    if not repo.local():
+    if not repo.local() or repo.root.endswith('/.hg/patches'):
         return
 
     inc, exc = [], ['.hgtags', '.hg_archival.txt']
--- a/tests/test-keyword	Thu Jan 31 14:34:45 2008 +0100
+++ b/tests/test-keyword	Thu Jan 31 01:06:49 2008 +0100
@@ -91,8 +91,12 @@
 echo % compare changenodes in a c
 cat a c
 
+echo % qinit -c
+hg qinit -c
 echo % qimport
 hg qimport -r tip -n mqtest.diff
+echo % qcommit
+hg qcommit -mqtest
 echo % keywords should not be expanded in patch
 cat .hg/patches/mqtest.diff
 echo % qpop
--- a/tests/test-keyword.out	Thu Jan 31 14:34:45 2008 +0100
+++ b/tests/test-keyword.out	Thu Jan 31 01:06:49 2008 +0100
@@ -126,7 +126,9 @@
 xxx $
 $Id: c,v 7fefeeacf359 1970/01/01 00:00:01 user $
 tests for different changenodes
+% qinit -c
 % qimport
+% qcommit
 % keywords should not be expanded in patch
 # HG changeset patch
 # User User Name <user@example.com>