Patchwork keyword: use context manager for rollback locking

login
register
mail settings
Submitter Christian Ebert
Date June 20, 2017, 12:16 p.m.
Message ID <8d47bf86d05de2bff7cd.1497960968@1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa>
Download mbox | patch
Permalink /patch/21526/
State Accepted
Headers show

Comments

Christian Ebert - June 20, 2017, 12:16 p.m.
# HG changeset patch
# User Christian Ebert <blacktrash@gmx.net>
# Date 1497959496 -3600
#      Tue Jun 20 12:51:36 2017 +0100
# Node ID 8d47bf86d05de2bff7cd2b3abeb7ae1de66d2848
# Parent  661025fd3e1cd5d5e2dee12b7f64312d6cd48a0b
keyword: use context manager for rollback locking
Yuya Nishihara - June 20, 2017, 3:18 p.m.
On Tue, 20 Jun 2017 13:16:08 +0100, Christian Ebert wrote:
> # HG changeset patch
> # User Christian Ebert <blacktrash@gmx.net>
> # Date 1497959496 -3600
> #      Tue Jun 20 12:51:36 2017 +0100
> # Node ID 8d47bf86d05de2bff7cd2b3abeb7ae1de66d2848
> # Parent  661025fd3e1cd5d5e2dee12b7f64312d6cd48a0b
> keyword: use context manager for rollback locking

Queued, thanks.

Patch

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -639,22 +639,21 @@  def reposetup(ui, repo):
             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):