--- a/hgkw/keyword.py Thu Dec 20 17:08:43 2007 +0100
+++ b/hgkw/keyword.py Thu Dec 20 22:15:43 2007 +0100
@@ -174,49 +174,48 @@
Subclass of filelog to hook into its read, add, cmp methods.
Keywords are "stored" unexpanded, and processed on reading.
'''
- def __init__(self, opener, path, kwtemplater):
+ def __init__(self, opener, path):
super(kwfilelog, self).__init__(opener, path)
- self.kwtemplater = kwtemplater
- self.kwtemplater.path = path
+ _kwtemplater.path = path
def kwctread(self, node, expand):
'''Reads expanding and counting keywords
(only called from kwtemplater.overwrite).'''
data = super(kwfilelog, self).read(node)
- return self.kwtemplater.process(node, data, expand)
+ return _kwtemplater.process(node, data, expand)
def read(self, node):
'''Expands keywords when reading filelog.'''
data = super(kwfilelog, self).read(node)
- return self.kwtemplater.expand(node, data)
+ return _kwtemplater.expand(node, data)
def add(self, text, meta, tr, link, p1=None, p2=None):
'''Removes keyword substitutions when adding to filelog.'''
- text = self.kwtemplater.shrink(text)
+ text = _kwtemplater.shrink(text)
return super(kwfilelog, self).add(text, meta, tr, link, p1=p1, p2=p2)
def cmp(self, node, text):
'''Removes keyword substitutions for comparison.'''
- text = self.kwtemplater.shrink(text)
+ text = _kwtemplater.shrink(text)
if self.renamed(node):
t2 = super(kwfilelog, self).read(node)
return t2 != text
return revlog.revlog.cmp(self, node, text)
-def _iskwfile(f, kwtemplater, link):
- return not link(f) and kwtemplater.matcher(f)
+def _iskwfile(f, link):
+ return not link(f) and _kwtemplater.matcher(f)
-def _status(ui, repo, kwtemplater, *pats, **opts):
+def _status(ui, repo, *pats, **opts):
'''Bails out if [keyword] configuration is not active.
Returns status of working directory.'''
- if kwtemplater:
+ if _kwtemplater:
files, match, anypats = cmdutil.matchpats(repo, pats, opts)
return repo.status(files=files, match=match, list_clean=True)
if ui.configitems('keyword'):
raise util.Abort(_('[keyword] patterns cannot match'))
raise util.Abort(_('no [keyword] patterns configured'))
-def _overwrite(ui, repo, kwtemplater, node=None, expand=True, files=None):
+def _overwrite(ui, repo, node=None, expand=True, files=None):
'''Overwrites selected files expanding/shrinking keywords.'''
ctx = repo.changectx(node)
mf = ctx.manifest()
@@ -225,11 +224,11 @@
files = [f for f in ctx.files() if mf.has_key(f)]
else:
notify = ui.note # kwexpand/kwshrink
- candidates = [f for f in files if _iskwfile(f, kwtemplater, mf.linkf)]
+ candidates = [f for f in files if _iskwfile(f, mf.linkf)]
if candidates:
candidates.sort()
action = expand and 'expanding' or 'shrinking'
- kwtemplater.node = node or ctx.node()
+ _kwtemplater.node = node or ctx.node()
for f in candidates:
fp = repo.file(f, kwmatch=True)
data, kwfound = fp.kwctread(mf[f], expand)
@@ -240,8 +239,7 @@
def _kwfwrite(ui, repo, expand, *pats, **opts):
'''Selects files and passes them to _overwrite.'''
- global _kwtemplater
- status = _status(ui, repo, _kwtemplater, *pats, **opts)
+ status = _status(ui, repo, *pats, **opts)
modified, added, removed, deleted, unknown, ignored, clean = status
if modified or added or removed or deleted:
raise util.Abort(_('outstanding uncommitted changes in given files'))
@@ -249,7 +247,7 @@
try:
wlock = repo.wlock()
lock = repo.lock()
- _overwrite(ui, repo, _kwtemplater, expand=expand, files=clean)
+ _overwrite(ui, repo, expand=expand, files=clean)
finally:
del wlock, lock
@@ -352,15 +350,14 @@
keyword expansion.
That is, files matched by [keyword] config patterns but not symlinks.
'''
- global _kwtemplater
- status = _status(ui, repo, _kwtemplater, *pats, **opts)
+ status = _status(ui, repo, *pats, **opts)
modified, added, removed, deleted, unknown, ignored, clean = status
if opts['untracked']:
files = modified + added + unknown + clean
else:
files = modified + added + clean
files.sort()
- kwfiles = [f for f in files if _iskwfile(f, _kwtemplater, repo._link)]
+ kwfiles = [f for f in files if _iskwfile(f, repo._link)]
cwd = pats and repo.getcwd() or ''
allf = opts['all']
ignore = opts['ignore']
@@ -427,7 +424,7 @@
if f[0] == '/':
f = f[1:]
if kwmatch or _kwtemplater.matcher(f):
- return kwfilelog(self.sopener, f, _kwtemplater)
+ return kwfilelog(self.sopener, f)
return filelog.filelog(self.sopener, f)
def commit(self, files=None, text='', user=None, date=None,
@@ -466,7 +463,7 @@
for name, cmd in commithooks:
ui.setconfig('hooks', name, cmd)
if node is not None:
- _overwrite(ui, self, _kwtemplater, node=node)
+ _overwrite(ui, self, node=node)
repo.hook('commit', node=node, parent1=_p1, parent2=_p2)
return node
finally: