# HG changeset patch # User Christian Ebert # Date 1497959496 -3600 # Node ID 69d1c3ea0d6f34a30ceea081ce03248fd111d12b # Parent 6123a52671197037074eb96a6abd1f19eb7294a4 keyword: use context manager for rollback locking diff -r 6123a5267119 -r 69d1c3ea0d6f hgext/keyword.py --- a/hgext/keyword.py Sat Jun 03 17:13:35 2017 -0700 +++ b/hgext/keyword.py Tue Jun 20 12:51:36 2017 +0100 @@ -639,22 +639,21 @@ return n def rollback(self, dryrun=False, force=False): - wlock = self.wlock() - origrestrict = kwt.restrict - try: - if not dryrun: - changed = self['.'].files() - ret = super(kwrepo, self).rollback(dryrun, force) - if not dryrun: - ctx = self['.'] - modified, added = _preselect(ctx.status(), changed) - kwt.restrict = False - kwt.overwrite(ctx, modified, True, True) - kwt.overwrite(ctx, added, True, False) - return ret - finally: - kwt.restrict = origrestrict - wlock.release() + with self.wlock(): + origrestrict = kwt.restrict + try: + if not dryrun: + changed = self['.'].files() + ret = super(kwrepo, self).rollback(dryrun, force) + if not dryrun: + ctx = self['.'] + modified, added = _preselect(ctx.status(), changed) + kwt.restrict = False + kwt.overwrite(ctx, modified, True, True) + kwt.overwrite(ctx, added, True, False) + return ret + finally: + kwt.restrict = origrestrict # monkeypatches def kwpatchfile_init(orig, self, ui, gp, backend, store, eolmode=None):