[PATCH 2 of 3] keyword: safeguards against erroneous behaviour or aborts

Christian Ebert blacktrash at gmx.net
Thu Feb 7 08:59:40 CST 2008


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1202336073 -3600
# Node ID 514a4e20e12cc4fa602ced8fa2596aa6e01464f8
# Parent  bd5494d77b1a1ca30ead77eb00a1612b63ec3621
keyword: safeguards against erroneous behaviour or aborts

prevent issues due to global [keyword] filename patterns:
- add email to nokwcommands
- protect everything under .hg from expansion
  (tested with qcommit)
- exclude everything starting with .hg* just in case

prevent abort when pulling from bundlerepo:
- do not set up kwrepo for bundlerepo
  expansion inside a bundle is nonsense

bundlerepo issue spotted and test case provided by pmezard.

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,8 +410,12 @@
     This is done for local repos only, and only if there are
     files configured at all for keyword substitution.'''
 
-    if not repo.local():
-        return
+    try:
+        if (not repo.local() or '.hg' in repo.root.split('/')
+            or repo._url.startswith('bundle:')):
+            return
+    except AttributeError:
+        pass
 
     hgcmd, func, args, opts, cmdopts = dispatch._parse(ui, sys.argv[1:])
     if hgcmd in nokwcommands.split():
@@ -426,7 +430,7 @@
         if node1 is not None and node1 != repo.changectx().node():
             hgcmd = 'diff1'
 
-    inc, exc = [], ['.hgtags']
+    inc, exc = [], ['.hg*']
     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
@@ -24,8 +24,8 @@
 
 hg --quiet kwdemo "Branch = {branches}"
 
-hg init Test
-cd Test
+hg init Test-bndl
+cd Test-bndl
 
 echo % kwshrink should exit silently in empty/invalid repo
 hg kwshrink
@@ -69,6 +69,16 @@
 mv $HGRCPATH.nohook $HGRCPATH
 rm hooktest
 
+echo % bundle
+hg bundle --base null ../kw.hg
+
+cd ..
+hg init Test
+cd Test
+
+echo % pull from bundle
+hg pull -u ../kw.hg
+
 echo % touch
 touch a b
 echo % status
@@ -90,8 +100,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
@@ -138,6 +138,16 @@
 a
 % diff a hooktest
 % removing commit hook from config
+% bundle
+1 changesets found
+% pull from bundle
+pulling from ../kw.hg
+requesting all changes
+adding changesets
+adding manifests
+adding file changes
+added 1 changesets with 3 changes to 3 files
+3 files updated, 0 files merged, 0 files removed, 0 files unresolved
 % touch
 % status
 % update
@@ -162,7 +172,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