# HG changeset patch # User Christian Ebert # Date 1267963383 -3600 # Node ID 9a36d159595f69ebc896110caf299ebc7669ab4c # Parent f511df3a4357e9b91ad61745884003e1587f795f keyword: remove spurious locks, improve handling of wlock - kwcommitctx is inside the wlock of repo.commit: no lock - _kwfwrite only needs wlock wlock outside try block, so we don't need to import lock.release _kwfwrite should even be safer that way, as we moved the status call inside the try-except block. Thanks to Benoit Boissinot for help. diff -r f511df3a4357 -r 9a36d159595f hgext/keyword.py --- a/hgext/keyword.py Sun Mar 07 13:03:03 2010 +0100 +++ b/hgext/keyword.py Sun Mar 07 13:03:03 2010 +0100 @@ -79,7 +79,6 @@ from mercurial import commands, cmdutil, dispatch, filelog, revlog, extensions from mercurial import patch, localrepo, templater, templatefilters, util, match from mercurial.hgweb import webcommands -from mercurial.lock import release from mercurial.node import nullid from mercurial.i18n import _ import re, shutil, tempfile @@ -264,17 +263,15 @@ if repo.dirstate.parents()[1] != nullid: raise util.Abort(_('outstanding uncommitted merge')) kwt = kwtools['templater'] - status = _status(ui, repo, kwt, *pats, **opts) - modified, added, removed, deleted, unknown, ignored, clean = status - if modified or added or removed or deleted: - raise util.Abort(_('outstanding uncommitted changes')) - wlock = lock = None + wlock = repo.wlock() try: - wlock = repo.wlock() - lock = repo.lock() + status = _status(ui, repo, kwt, *pats, **opts) + modified, added, removed, deleted, unknown, ignored, clean = status + if modified or added or removed or deleted: + raise util.Abort(_('outstanding uncommitted changes')) kwt.overwrite(None, expand, clean) finally: - release(lock, wlock) + wlock.release() def demo(ui, repo, *args, **opts): '''print [keywordmaps] configuration and an expansion example @@ -485,15 +482,10 @@ del self.commitctx def kwcommitctx(self, ctx, error=False): - wlock = lock = None - try: - wlock = self.wlock() - lock = self.lock() - n = super(kwrepo, self).commitctx(ctx, error) - kwt.overwrite(n, True, None) - return n - finally: - release(lock, wlock) + n = super(kwrepo, self).commitctx(ctx, error) + # no lock needed, only called from repo.commit() which already locks + kwt.overwrite(n, True, None) + return n # monkeypatches def kwpatchfile_init(orig, self, ui, fname, opener,