# HG changeset patch # User Christian Ebert # Date 1184656623 -7200 # Node ID de32fbee75a4a914256bb5b071258ace89da5746 # Parent 8019554adbb28a31a5756b0df969cd5ef972a73d Obtain filename matcher from function keywordmatcher Future implementation of commands kwexpand/kwshrink will also need this. diff -r 8019554adbb2 -r de32fbee75a4 hgkw/keyword.py --- 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: