# HG changeset patch # User Christian Ebert # Date 1338624599 -7200 # Node ID 64fc3d450713de74bf80fedfa0b4bddc22b454e5 # Parent 2a1ab2f6559cd954a881474d41cbedb6b318d4ba# Parent 2ba350253f7671c3b9d5fd7e9b8242bda9e1a14b Merge with default diff -r 2a1ab2f6559c -r 64fc3d450713 hgkw/keyword.py --- a/hgkw/keyword.py Tue May 15 14:37:49 2012 -0500 +++ b/hgkw/keyword.py Sat Jun 02 10:09:59 2012 +0200 @@ -1,6 +1,6 @@ # keyword.py - $Keyword$ expansion for Mercurial # -# Copyright 2007-2010 Christian Ebert +# Copyright 2007-2012 Christian Ebert # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. @@ -188,7 +188,7 @@ self.repo = repo self.match = match.match(repo.root, '', [], inc, exc) self.restrict = kwtools['hgcmd'] in restricted.split() - self.record = False + self.postcommit = False kwmaps = self.ui.configitems('keywordmaps') if kwmaps: # override default templates @@ -243,7 +243,7 @@ def overwrite(self, ctx, candidates, lookup, expand, rekw=False): '''Overwrites selected files expanding/shrinking keywords.''' - if self.restrict or lookup or self.record: # exclude kw_copy + if self.restrict or lookup or self.postcommit: # exclude kw_copy candidates = self.iskwfile(candidates, ctx) if not candidates: return @@ -280,7 +280,7 @@ fp.close() if kwcmd: self.repo.dirstate.normal(f) - elif self.record: + elif self.postcommit: self.repo.dirstate.normallookup(f) def shrink(self, fname, text): @@ -583,7 +583,7 @@ def kwcommitctx(self, ctx, error=False): n = super(kwrepo, self).commitctx(ctx, error) # no lock needed, only called from repo.commit() which already locks - if not kwt.record: + if not kwt.postcommit: restrict = kwt.restrict kwt.restrict = True kwt.overwrite(self[n], sorted(ctx.added() + ctx.modified()), @@ -625,6 +625,21 @@ kwt.match = util.never return orig(web, req, tmpl) + def kw_amend(orig, ui, repo, commitfunc, old, extra, pats, opts): + '''Wraps cmdutil.amend expanding keywords after amend.''' + wlock = repo.wlock() + try: + kwt.postcommit = True + newid = orig(ui, repo, commitfunc, old, extra, pats, opts) + if newid != old.node(): + ctx = repo[newid] + kwt.restrict = True + kwt.overwrite(ctx, ctx.files(), False, True) + kwt.restrict = False + return newid + finally: + wlock.release() + def kw_copy(orig, ui, repo, pats, opts, rename=False): '''Wraps cmdutil.copy so that copy/rename destinations do not contain expanded keywords. @@ -635,25 +650,29 @@ For the latter we have to follow the symlink to find out whether its target is configured for expansion and we therefore must unexpand the keywords in the destination.''' - orig(ui, repo, pats, opts, rename) - if opts.get('dry_run'): - return - wctx = repo[None] - cwd = repo.getcwd() + wlock = repo.wlock() + try: + orig(ui, repo, pats, opts, rename) + if opts.get('dry_run'): + return + wctx = repo[None] + cwd = repo.getcwd() - def haskwsource(dest): - '''Returns true if dest is a regular file and configured for - expansion or a symlink which points to a file configured for - expansion. ''' - source = repo.dirstate.copied(dest) - if 'l' in wctx.flags(source): - source = scmutil.canonpath(repo.root, cwd, - os.path.realpath(source)) - return kwt.match(source) + def haskwsource(dest): + '''Returns true if dest is a regular file and configured for + expansion or a symlink which points to a file configured for + expansion. ''' + source = repo.dirstate.copied(dest) + if 'l' in wctx.flags(source): + source = scmutil.canonpath(repo.root, cwd, + os.path.realpath(source)) + return kwt.match(source) - candidates = [f for f in repo.dirstate.copies() if - 'l' not in wctx.flags(f) and haskwsource(f)] - kwt.overwrite(wctx, candidates, False, False) + candidates = [f for f in repo.dirstate.copies() if + 'l' not in wctx.flags(f) and haskwsource(f)] + kwt.overwrite(wctx, candidates, False, False) + finally: + wlock.release() def kw_dorecord(orig, ui, repo, commitfunc, *pats, **opts): '''Wraps record.dorecord expanding keywords after recording.''' @@ -661,7 +680,7 @@ try: # record returns 0 even when nothing has changed # therefore compare nodes before and after - kwt.record = True + kwt.postcommit = True ctx = repo['.'] wstatus = repo[None].status() ret = orig(ui, repo, commitfunc, *pats, **opts) @@ -690,6 +709,7 @@ extensions.wrapfunction(context.filectx, 'cmp', kwfilectx_cmp) extensions.wrapfunction(patch.patchfile, '__init__', kwpatchfile_init) extensions.wrapfunction(patch, 'diff', kw_diff) + extensions.wrapfunction(cmdutil, 'amend', kw_amend) extensions.wrapfunction(cmdutil, 'copy', kw_copy) for c in 'annotate changeset rev filediff diff'.split(): extensions.wrapfunction(webcommands, c, kwweb_skip) diff -r 2a1ab2f6559c -r 64fc3d450713 tests/test-keyword.t --- a/tests/test-keyword.t Tue May 15 14:37:49 2012 -0500 +++ b/tests/test-keyword.t Sat Jun 02 10:09:59 2012 +0200 @@ -495,6 +495,22 @@ $ hg forget i $ rm i +amend + + $ echo amend >> a + $ echo amend >> b + $ hg -q commit -d '1 14' -m 'prepare amend' + + $ hg --debug commit --amend -d '1 15' -m 'amend without changes' | grep keywords + invalidating branch cache (tip differs) + overwriting a expanding keywords + $ hg -q id + a71343332ea9 + $ head -1 a + expand $Id: a,v a71343332ea9 1970/01/01 00:00:01 test $ + + $ hg -q strip -n tip + Test patch queue repo $ hg init --mq