[PATCH] keyword: safeguards against global [keyword] filename patterns

Christian Ebert blacktrash at gmx.net
Wed Feb 6 16:15:35 CST 2008


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1202336073 -3600
# Node ID 379abcba8294bac9a10ccdc980eccde48cd16768
# Parent  b7f44f01a632ab4a59f276de21dc3c5d8f1b8560
keyword: safeguards against global [keyword] filename patterns

- add email to nokwcommands
- protect everything under .hg from expansion
  (tested with qcommit)
- exclude .hg_archival.txt just in case

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -88,7 +88,7 @@
 
 # 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')
+                ' log outgoing push remove rename rollback tip convert email')
 
 # hg commands that trigger expansion only when writing to working dir,
 # not when reading filelog, and unexpand when reading from working dir
@@ -410,7 +410,7 @@
     This is done for local repos only, and only if there are
     files configured at all for keyword substitution.'''
 
-    if not repo.local():
+    if not repo.local() or '.hg' in repo.root.split('/'):
         return
 
     hgcmd, func, args, opts, cmdopts = dispatch._parse(ui, sys.argv[1:])
@@ -426,7 +426,7 @@
         if node1 is not None and node1 != repo.changectx().node():
             hgcmd = 'diff1'
 
-    inc, exc = [], ['.hgtags']
+    inc, exc = [], ['.hgtags', '.hg_archival.txt']
     for pat, opt in ui.configitems('keyword'):
         if opt != 'ignore':
             inc.append(pat)
diff --git a/tests/test-keyword b/tests/test-keyword
--- a/tests/test-keyword
+++ b/tests/test-keyword
@@ -90,8 +90,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
diff --git a/tests/test-keyword.out b/tests/test-keyword.out
--- a/tests/test-keyword.out
+++ b/tests/test-keyword.out
@@ -162,7 +162,9 @@
 xxx $
 $Id: c,v ba4426d1938e 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 at example.com>


More information about the Mercurial-devel mailing list