Obtain filename matcher from function keywordmatcher
Future implementation of commands kwexpand/kwshrink will also need this.
--- a/hgkw/keyword.py Sun Jul 15 17:34:34 2007 +0200
+++ b/hgkw/keyword.py Tue Jul 17 09:17:03 2007 +0200
@@ -106,6 +106,20 @@
aliases, i = findcmd(ui, cmd)
return aliases[0]
+def keywordmatcher(ui, repo):
+ '''Collects include/exclude filename patterns for expansion
+ candidates of current configuration. Returns filename matching
+ function if include patterns exist, None otherwise.'''
+ inc, exc = [], ['.hg*']
+ for pat, opt in ui.configitems('keyword'):
+ if opt != 'ignore':
+ inc.append(pat)
+ else:
+ exc.append(pat)
+ if not inc:
+ return None
+ return util.matcher(repo.root, inc=inc, exc=exc)[1]
+
class kwtemplater(object):
'''
Sets up keyword templates, corresponding keyword regex, and
@@ -241,6 +255,7 @@
ui.debug(_('\nremoving temporary repo\n'))
shutil.rmtree(tmpdir)
+
def reposetup(ui, repo):
'''Sets up repo as kwrepo for keyword substitution.
Overrides file method to return kwfilelog instead of filelog
@@ -253,16 +268,10 @@
if not repo.local() or getcmd(repo.ui) in nokwcommands:
return
- inc, exc = [], ['.hg*']
- for pat, opt in repo.ui.configitems('keyword'):
- if opt != 'ignore':
- inc.append(pat)
- else:
- exc.append(pat)
- if not inc:
+ kwfmatcher = keywordmatcher(ui, repo)
+ if kwfmatcher is None:
return
- kwfmatcher = util.matcher(repo.root, inc=inc, exc=exc)[1]
ui = repo.ui
class kwrepo(repo.__class__):
@@ -302,7 +311,6 @@
if candidates:
kwt = kwtemplater(ui, self, node=node)
kwt.overwrite(candidates, cl[0])
-
return node
finally:
if wrelease: