Patchwork D7430: bisect: replace try:/finally: by a "restore_state" context manager

login
register
mail settings
Submitter phabricator
Date Nov. 15, 2019, 5:25 p.m.
Message ID <9d0cd882137bebb0e4f940f7fdfdfc43@localhost.localdomain>
Download mbox | patch
Permalink /patch/43274/
State Not Applicable
Headers show

Comments

phabricator - Nov. 15, 2019, 5:25 p.m.
Closed by commit rHGf37da59a36d9: bisect: replace try:/finally: by a &quot;restore_state&quot; context manager (authored by dlax).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7430?vs=18156&id=18160

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7430/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7430

AFFECTED FILES
  mercurial/commands.py
  mercurial/hbisect.py

CHANGE DETAILS




To: dlax, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/hbisect.py b/mercurial/hbisect.py
--- a/mercurial/hbisect.py
+++ b/mercurial/hbisect.py
@@ -11,6 +11,7 @@ 
 from __future__ import absolute_import
 
 import collections
+import contextlib
 
 from .i18n import _
 from .node import (
@@ -180,6 +181,15 @@ 
         raise error.Abort(_(b'cannot bisect (no known bad revisions)'))
 
 
+@contextlib.contextmanager
+def restore_state(repo, state, node):
+    try:
+        yield
+    finally:
+        state[b'current'] = [node]
+        save_state(repo, state)
+
+
 def get(repo, status):
     """
     Return a list of revision(s) that match the given status:
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1073,7 +1073,7 @@ 
                 raise error.Abort(_(b'current bisect revision is a merge'))
         if rev:
             node = repo[scmutil.revsingle(repo, rev, node)].node()
-        try:
+        with hbisect.restore_state(repo, state, node):
             while changesets:
                 # update state
                 state[b'current'] = [node]
@@ -1105,9 +1105,6 @@ 
                 # update to next check
                 node = nodes[0]
                 mayupdate(repo, node, show_stats=False)
-        finally:
-            state[b'current'] = [node]
-            hbisect.save_state(repo, state)
         hbisect.printresult(ui, repo, state, displayer, nodes, bgood)
         return