--- a/hgkw/keyword.py Thu Sep 23 17:03:23 2010 +0200
+++ b/hgkw/keyword.py Sun Sep 26 21:59:47 2010 +0200
@@ -92,8 +92,7 @@
# hg commands that do not act on keywords
nokwcommands = ('add addremove annotate bundle copy export grep incoming init'
- ' log outgoing push rename rollback tip verify'
- ' convert email glog')
+ ' log outgoing push rename tip verify convert email glog')
# hg commands that trigger expansion only when writing to working dir,
# not when reading filelog, and unexpand when reading from working dir
@@ -192,18 +191,20 @@
Caveat: localrepository._link fails on Windows.'''
return self.match(path) and not 'l' in flagfunc(path)
- def overwrite(self, ctx, candidates, iswctx, expand):
+ def overwrite(self, ctx, candidates, iswctx, expand, cfiles):
'''Overwrites selected files expanding/shrinking keywords.'''
- if self.record:
- candidates = [f for f in ctx.files() if f in ctx]
+ if cfiles is not None:
+ candidates = [f for f in candidates if f in cfiles]
candidates = [f for f in candidates if self.iskwfile(f, ctx.flags)]
if candidates:
+ restrict = self.restrict
self.restrict = True # do not expand when reading
+ rollback = kwtools['hgcmd'] == 'rollback'
mf = ctx.manifest()
msg = (expand and _('overwriting %s expanding keywords\n')
or _('overwriting %s shrinking keywords\n'))
for f in candidates:
- if not self.record:
+ if not self.record and not rollback:
data = self.repo.file(f).read(mf[f])
else:
data = self.repo.wread(f)
@@ -219,11 +220,11 @@
if found:
self.ui.note(msg % f)
self.repo.wwrite(f, data, mf.flags(f))
- if iswctx:
+ if iswctx and not rollback:
self.repo.dirstate.normal(f)
elif self.record:
self.repo.dirstate.normallookup(f)
- self.restrict = False
+ self.restrict = restrict
def shrinktext(self, text):
'''Unconditionally removes all keyword substitutions from text.'''
@@ -298,7 +299,7 @@
modified, added, removed, deleted, unknown, ignored, clean = status
if modified or added or removed or deleted:
raise util.Abort(_('outstanding uncommitted changes'))
- kwt.overwrite(wctx, clean, True, expand)
+ kwt.overwrite(wctx, clean, True, expand, None)
finally:
wlock.release()
@@ -502,9 +503,24 @@
# no lock needed, only called from repo.commit() which already locks
if not kwt.record:
kwt.overwrite(self[n], sorted(ctx.added() + ctx.modified()),
- False, True)
+ False, True, None)
return n
+ def rollback(self, dryrun=False):
+ wlock = repo.wlock()
+ try:
+ if not dryrun:
+ cfiles = self['.'].files()
+ ret = super(kwrepo, self).rollback(dryrun)
+ if not dryrun:
+ ctx = self['.']
+ modified, added = super(kwrepo, self).status()[:2]
+ kwt.overwrite(ctx, added, True, False, cfiles)
+ kwt.overwrite(ctx, modified, True, True, cfiles)
+ return ret
+ finally:
+ wlock.release()
+
# monkeypatches
def kwpatchfile_init(orig, self, ui, fname, opener,
missing=False, eolmode=None):
@@ -516,12 +532,8 @@
def kw_diff(orig, repo, node1=None, node2=None, match=None, changes=None,
opts=None, prefix=''):
- '''Monkeypatch patch.diff to avoid expansion except when
- comparing against working dir.'''
- if node2 is not None:
- kwt.match = util.never
- elif node1 is not None and node1 != repo['.'].node():
- kwt.restrict = True
+ '''Monkeypatch patch.diff to avoid expansion.'''
+ kwt.restrict = True
return orig(repo, node1, node2, match, changes, opts, prefix)
def kwweb_skip(orig, web, req, tmpl):
@@ -539,7 +551,8 @@
ret = orig(ui, repo, commitfunc, *pats, **opts)
recordctx = repo['.']
if ctx != recordctx:
- kwt.overwrite(recordctx, None, False, True)
+ kwt.overwrite(recordctx, recordctx.files(),
+ False, True, recordctx)
return ret
finally:
wlock.release()
@@ -547,8 +560,7 @@
repo.__class__ = kwrepo
extensions.wrapfunction(patch.patchfile, '__init__', kwpatchfile_init)
- if not kwt.restrict:
- extensions.wrapfunction(patch, 'diff', kw_diff)
+ extensions.wrapfunction(patch, 'diff', kw_diff)
for c in 'annotate changeset rev filediff diff'.split():
extensions.wrapfunction(webcommands, c, kwweb_skip)
for name in recordextensions.split():