Mercurial > hg
diff hgext/keyword.py @ 32935:69d1c3ea0d6f
keyword: use context manager for rollback locking
author | Christian Ebert <blacktrash@gmx.net> |
---|---|
date | Tue, 20 Jun 2017 12:51:36 +0100 |
parents | 50586a0a946f |
children | 7f569ce30216 |
line wrap: on
line diff
--- 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):