Patchwork [1,of,9] rebase: use context manager for locking in rebase()

login
register
mail settings
Submitter via Mercurial-devel
Date June 19, 2017, 8:47 p.m.
Message ID <13b76c56433d09394036.1497905273@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/21507/
State Accepted
Headers show

Comments

via Mercurial-devel - June 19, 2017, 8:47 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1497896285 25200
#      Mon Jun 19 11:18:05 2017 -0700
# Node ID 13b76c56433d09394036c0885bc5593287d0d305
# Parent  661025fd3e1cd5d5e2dee12b7f64312d6cd48a0b
rebase: use context manager for locking in rebase()
Gregory Szorc - June 20, 2017, 6:26 a.m.
On Mon, Jun 19, 2017 at 1:47 PM, Martin von Zweigbergk via Mercurial-devel <
mercurial-devel@mercurial-scm.org> wrote:

> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1497896285 25200
> #      Mon Jun 19 11:18:05 2017 -0700
> # Node ID 13b76c56433d09394036c0885bc5593287d0d305
> # Parent  661025fd3e1cd5d5e2dee12b7f64312d6cd48a0b
> rebase: use context manager for locking in rebase()
>

Queued this series. Nice cleanup!


>
> diff --git a/hgext/rebase.py b/hgext/rebase.py
> --- a/hgext/rebase.py
> +++ b/hgext/rebase.py
> @@ -683,11 +683,7 @@
>      """
>      rbsrt = rebaseruntime(repo, ui, opts)
>
> -    lock = wlock = None
> -    try:
> -        wlock = repo.wlock()
> -        lock = repo.lock()
> -
> +    with repo.wlock(), repo.lock():
>          # Validate input and define rebasing points
>          destf = opts.get('dest', None)
>          srcf = opts.get('source', None)
> @@ -753,8 +749,6 @@
>                  release(dsguard)
>                  raise
>          rbsrt._finishrebase()
> -    finally:
> -        release(lock, wlock)
>
>  def _definesets(ui, repo, destf=None, srcf=None, basef=None, revf=None,
>                  destspace=None):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -683,11 +683,7 @@ 
     """
     rbsrt = rebaseruntime(repo, ui, opts)
 
-    lock = wlock = None
-    try:
-        wlock = repo.wlock()
-        lock = repo.lock()
-
+    with repo.wlock(), repo.lock():
         # Validate input and define rebasing points
         destf = opts.get('dest', None)
         srcf = opts.get('source', None)
@@ -753,8 +749,6 @@ 
                 release(dsguard)
                 raise
         rbsrt._finishrebase()
-    finally:
-        release(lock, wlock)
 
 def _definesets(ui, repo, destf=None, srcf=None, basef=None, revf=None,
                 destspace=None):