# HG changeset patch # User Christian Delahousse # Date 1444947644 25200 # Node ID 8af610bce2399efbf9e5e8a0ed7e751f47a31ea0 # Parent 21e50e36de02b46cf2abc704800d4c169c12fd4f 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. diff -r 21e50e36de02 -r 8af610bce239 hgext/rebase.py --- a/hgext/rebase.py Thu Oct 15 12:13:46 2015 -0700 +++ b/hgext/rebase.py Thu Oct 15 15:20:44 2015 -0700 @@ -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'''