Patchwork [3,of,8] rebase: reduce scope of try catch in restorestate

login
register
mail settings
Submitter Christian Delahousse
Date Oct. 16, 2015, 2:33 a.m.
Message ID <d8c393e7c3bec8f2ba0e.1444962812@dev4253.prn1.facebook.com>
Download mbox | patch
Permalink /patch/11138/
State Accepted
Commit 8af610bce2399efbf9e5e8a0ed7e751f47a31ea0
Headers show

Comments

Christian Delahousse - Oct. 16, 2015, 2:33 a.m.
# HG changeset patch
# User Christian Delahousse <cdelahousse@fb.com>
# Date 1444947644 25200
#      Thu Oct 15 15:20:44 2015 -0700
# Node ID d8c393e7c3bec8f2ba0ea286d121c05a999e7ade
# Parent  1dd6fe8f95da7735de7485d5145a2c389860e387
rebase: reduce scope of try catch in restorestate

Refactoring by reduce the scope of the try catch block so that it only captures
what it needs.  I could have made it smaller but another patch in the series
will add onto it.
Matt Mackall - Oct. 17, 2015, 7:26 p.m.
On Thu, 2015-10-15 at 19:33 -0700, Christian Delahousse wrote:
> # HG changeset patch
> # User Christian Delahousse <cdelahousse@fb.com>
> # Date 1444947644 25200
> #      Thu Oct 15 15:20:44 2015 -0700
> # Node ID d8c393e7c3bec8f2ba0ea286d121c05a999e7ade
> # Parent  1dd6fe8f95da7735de7485d5145a2c389860e387
> rebase: reduce scope of try catch in restorestate

I've queued 1 and 3 of this series, thanks.

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -845,13 +845,14 @@ 
 
 def restorestatus(repo):
     'Restore a previously stored status'
+    keepbranches = None
+    target = None
+    collapse = False
+    external = nullrev
+    activebookmark = None
+    state = {}
+
     try:
-        keepbranches = None
-        target = None
-        collapse = False
-        external = nullrev
-        activebookmark = None
-        state = {}
         f = repo.vfs("rebasestate")
         for i, l in enumerate(f.read().splitlines()):
             if i == 0:
@@ -881,28 +882,29 @@ 
                 else:
                     state[repo[oldrev].rev()] = repo[newrev].rev()
 
-        if keepbranches is None:
-            raise error.Abort(_('.hg/rebasestate is incomplete'))
-
-        skipped = set()
-        # recompute the set of skipped revs
-        if not collapse:
-            seen = set([target])
-            for old, new in sorted(state.items()):
-                if new != revtodo and new in seen:
-                    skipped.add(old)
-                seen.add(new)
-        repo.ui.debug('computed skipped revs: %s\n' %
-                      (' '.join(str(r) for r in sorted(skipped)) or None))
-        repo.ui.debug('rebase status resumed\n')
-        _setrebasesetvisibility(repo, state.keys())
-        return (originalwd, target, state, skipped,
-                collapse, keep, keepbranches, external, activebookmark)
     except IOError as err:
         if err.errno != errno.ENOENT:
             raise
         raise error.Abort(_('no rebase in progress'))
 
+    if keepbranches is None:
+        raise error.Abort(_('.hg/rebasestate is incomplete'))
+
+    skipped = set()
+    # recompute the set of skipped revs
+    if not collapse:
+        seen = set([target])
+        for old, new in sorted(state.items()):
+            if new != revtodo and new in seen:
+                skipped.add(old)
+            seen.add(new)
+    repo.ui.debug('computed skipped revs: %s\n' %
+                    (' '.join(str(r) for r in sorted(skipped)) or None))
+    repo.ui.debug('rebase status resumed\n')
+    _setrebasesetvisibility(repo, state.keys())
+    return (originalwd, target, state, skipped,
+            collapse, keep, keepbranches, external, activebookmark)
+
 def needupdate(repo, state):
     '''check whether we should `update --clean` away from a merge, or if
     somehow the working dir got forcibly updated, e.g. by older hg'''