[PATCH] keyword: move collecting of [keyword] patterns to reposetup (issue2303)
Christian Ebert
blacktrash at gmx.net
Sun Jul 25 19:44:14 CDT 2010
* Matt Mackall on Sunday, July 25, 2010 at 19:15:16 -0500
> On Mon, 2010-07-26 at 01:53 +0200, Christian Ebert wrote:
>> # HG changeset patch
>> # User Christian Ebert <blacktrash at gmx.net>
>> # Date 1280101910 -7200
>> # Node ID 6b927e49b9c4259dc870a6cb93c74f2ce087ef5a
>> # Parent 1b3b843e11002e95e8675f8028e478122e076def
>> keyword: move collecting of [keyword] patterns to reposetup (issue2303)
>
> Queued for stable, thanks.
Thank you.
If it is not too late, this has a tiny cosmetic improvement (I
hope) by doing:
-inc = []
-exc = ['.hg*']
+inc, exc = [], ['.hg*']
Sorry.
c
# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Parent 1b3b843e11002e95e8675f8028e478122e076def
keyword: move collecting of [keyword] patterns to reposetup (issue2303)
When cloning, prevent [keyword] filename patterns configured locally
in the source directory to persist during the update in the destination.
a) move [keyword] retrieval (back) to reposetup
b) remove the corresponding global kwtools attributes
Add test cases.
diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -108,7 +108,7 @@
svnutcdate = lambda x: util.datestr((x[0], 0), '%Y-%m-%d %H:%M:%SZ')
# make keyword tools accessible
-kwtools = {'templater': None, 'hgcmd': '', 'inc': [], 'exc': ['.hg*']}
+kwtools = {'templater': None, 'hgcmd': ''}
def _defaultkwmaps(ui):
@@ -141,11 +141,10 @@
provides keyword substitution functions.
'''
- def __init__(self, ui, repo):
+ def __init__(self, ui, repo, inc, exc):
self.ui = ui
self.repo = repo
- self.match = match.match(repo.root, '', [],
- kwtools['inc'], kwtools['exc'])
+ self.match = match.match(repo.root, '', [], inc, exc)
self.restrict = kwtools['hgcmd'] in restricted.split()
self.record = kwtools['hgcmd'] in recordcommands.split()
@@ -438,23 +437,15 @@
def uisetup(ui):
- '''Collects [keyword] config in kwtools.
- Monkeypatches dispatch._parse if needed.'''
+ ''' Monkeypatches dispatch._parse to retrieve user command.'''
- for pat, opt in ui.configitems('keyword'):
- if opt != 'ignore':
- kwtools['inc'].append(pat)
- else:
- kwtools['exc'].append(pat)
+ def kwdispatch_parse(orig, ui, args):
+ '''Monkeypatch dispatch._parse to obtain running hg command.'''
+ cmd, func, args, options, cmdoptions = orig(ui, args)
+ kwtools['hgcmd'] = cmd
+ return cmd, func, args, options, cmdoptions
- if kwtools['inc']:
- def kwdispatch_parse(orig, ui, args):
- '''Monkeypatch dispatch._parse to obtain running hg command.'''
- cmd, func, args, options, cmdoptions = orig(ui, args)
- kwtools['hgcmd'] = cmd
- return cmd, func, args, options, cmdoptions
-
- extensions.wrapfunction(dispatch, '_parse', kwdispatch_parse)
+ extensions.wrapfunction(dispatch, '_parse', kwdispatch_parse)
def reposetup(ui, repo):
'''Sets up repo as kwrepo for keyword substitution.
@@ -465,15 +456,23 @@
Monkeypatches patch and webcommands.'''
try:
- if (not repo.local() or not kwtools['inc']
- or kwtools['hgcmd'] in nokwcommands.split()
+ if (not repo.local() or kwtools['hgcmd'] in nokwcommands.split()
or '.hg' in util.splitpath(repo.root)
or repo._url.startswith('bundle:')):
return
except AttributeError:
pass
- kwtools['templater'] = kwt = kwtemplater(ui, repo)
+ inc, exc = [], ['.hg*']
+ for pat, opt in ui.configitems('keyword'):
+ if opt != 'ignore':
+ inc.append(pat)
+ else:
+ exc.append(pat)
+ if not inc:
+ return
+
+ kwtools['templater'] = kwt = kwtemplater(ui, repo, inc, exc)
class kwrepo(repo.__class__):
def file(self, f):
diff --git a/tests/test-keyword b/tests/test-keyword
--- a/tests/test-keyword
+++ b/tests/test-keyword
@@ -283,8 +283,17 @@
echo % cat a
cat a
+echo % clone
+cd ..
+
+echo % expansion in dest
+hg --quiet clone Test globalconf
+cat globalconf/a
+echo % no expansion in dest
+hg --quiet --config 'keyword.**=ignore' clone Test localconf
+cat localconf/a
+
echo % clone to test incoming
-cd ..
hg clone -r1 Test Test-a
cd Test-a
cat <<EOF >> .hg/hgrc
diff --git a/tests/test-keyword.out b/tests/test-keyword.out
--- a/tests/test-keyword.out
+++ b/tests/test-keyword.out
@@ -333,6 +333,17 @@
do not process $Id:
xxx $
$Xinfo: User Name <user at example.com>: firstline $
+% clone
+% expansion in dest
+expand $Id: a bb948857c743 Thu, 01 Jan 1970 00:00:02 +0000 user $
+do not process $Id:
+xxx $
+$Xinfo: User Name <user at example.com>: firstline $
+% no expansion in dest
+expand $Id$
+do not process $Id:
+xxx $
+$Xinfo$
% clone to test incoming
requesting all changes
adding changesets
More information about the Mercurial-devel
mailing list