diff hgext/evolve.py @ 1729:8ed0266c58a3

evolve: removed redundant try/finally blocks There were two todo's to remove the redundant try finally blocks. Done that and also fixed the indentation afterwards.
author Pulkit Goyal <7895pulkit@gmail.com>
date Thu, 01 Sep 2016 04:38:56 +0530
parents 192cdab2884e
children f4047fba5e90
line wrap: on
line diff
--- a/hgext/evolve.py	Sat Aug 27 20:37:15 2016 +0800
+++ b/hgext/evolve.py	Thu Sep 01 04:38:56 2016 +0530
@@ -964,28 +964,25 @@
     tr = repo.currenttransaction()
     assert tr is not None
     try:
-        try:
-            r = _evolvemerge(repo, orig, dest, pctx, keepbranch)
-            if r[-1]:  #some conflict
-                raise error.Abort(
-                        'unresolved merge conflicts (see hg help resolve)')
-            nodenew = _relocatecommit(repo, orig, commitmsg)
-        except error.Abort as exc:
-            repo.dirstate.beginparentchange()
-            repo.setparents(repo['.'].node(), nullid)
-            writedirstate(repo.dirstate, tr)
-            # fix up dirstate for copies and renames
-            copies.duplicatecopies(repo, dest.rev(), orig.p1().rev())
-            repo.dirstate.endparentchange()
-            class LocalMergeFailure(MergeFailure, exc.__class__):
-                pass
-            exc.__class__ = LocalMergeFailure
-            tr.close() # to keep changes in this transaction (e.g. dirstate)
-            raise
-        oldbookmarks = repo.nodebookmarks(nodesrc)
-        _finalizerelocate(repo, orig, dest, nodenew, tr)
-    finally:
-        pass # TODO: remove this redundant try/finally block
+        r = _evolvemerge(repo, orig, dest, pctx, keepbranch)
+        if r[-1]:  #some conflict
+            raise error.Abort(
+                    'unresolved merge conflicts (see hg help resolve)')
+        nodenew = _relocatecommit(repo, orig, commitmsg)
+    except error.Abort as exc:
+        repo.dirstate.beginparentchange()
+        repo.setparents(repo['.'].node(), nullid)
+        writedirstate(repo.dirstate, tr)
+        # fix up dirstate for copies and renames
+        copies.duplicatecopies(repo, dest.rev(), orig.p1().rev())
+        repo.dirstate.endparentchange()
+        class LocalMergeFailure(MergeFailure, exc.__class__):
+            pass
+        exc.__class__ = LocalMergeFailure
+        tr.close() # to keep changes in this transaction (e.g. dirstate)
+        raise
+    oldbookmarks = repo.nodebookmarks(nodesrc)
+    _finalizerelocate(repo, orig, dest, nodenew, tr)
     return nodenew
 
 def _bookmarksupdater(repo, oldid, tr):
@@ -1998,73 +1995,70 @@
     tr = repo.currenttransaction()
     assert tr is not None
     bmupdate = _bookmarksupdater(repo, bumped.node(), tr)
-    try:
-        if not list(repo.set('parents(%d) and parents(%d)', bumped, prec)):
-            # Need to rebase the changeset at the right place
-            repo.ui.status(
-                _('rebasing to destination parent: %s\n') % prec.p1())
-            try:
-                tmpid = relocate(repo, bumped, prec.p1())
-                if tmpid is not None:
-                    tmpctx = repo[tmpid]
-                    obsolete.createmarkers(repo, [(bumped, (tmpctx,))])
-            except MergeFailure:
-                repo.opener.write('graftstate', bumped.hex() + '\n')
-                repo.ui.write_err(_('evolution failed!\n'))
-                repo.ui.write_err(
-                    _('fix conflict and run "hg evolve --continue"\n'))
-                raise
-        # Create the new commit context
-        repo.ui.status(_('computing new diff\n'))
-        files = set()
-        copied = copies.pathcopies(prec, bumped)
-        precmanifest = prec.manifest()
-        # 3.3.2 needs a list.
-        # future 3.4 don't detect the size change during iteration
-        # this is fishy
-        for key, val in list(bumped.manifest().iteritems()):
-            precvalue = precmanifest.get(key, None)
-            if precvalue is not None:
-                del precmanifest[key]
-            if precvalue != val:
-                files.add(key)
-        files.update(precmanifest)  # add missing files
-        # commit it
-        if files: # something to commit!
-            def filectxfn(repo, ctx, path):
-                if path in bumped:
-                    fctx = bumped[path]
-                    flags = fctx.flags()
-                    mctx = memfilectx(repo, fctx.path(), fctx.data(),
-                                      islink='l' in flags,
-                                      isexec='x' in flags,
-                                      copied=copied.get(path))
-                    return mctx
-                return None
-            text = 'bumped update to %s:\n\n' % prec
-            text += bumped.description()
-
-            new = context.memctx(repo,
-                                 parents=[prec.node(), node.nullid],
-                                 text=text,
-                                 files=files,
-                                 filectxfn=filectxfn,
-                                 user=bumped.user(),
-                                 date=bumped.date(),
-                                 extra=bumped.extra())
-
-            newid = repo.commitctx(new)
-        if newid is None:
-            obsolete.createmarkers(repo, [(tmpctx, ())])
-            newid = prec.node()
-        else:
-            phases.retractboundary(repo, tr, bumped.phase(), [newid])
-            obsolete.createmarkers(repo, [(tmpctx, (repo[newid],))],
-                                   flag=obsolete.bumpedfix)
-        bmupdate(newid)
-        repo.ui.status(_('committed as %s\n') % node.short(newid))
-    finally:
-        pass # TODO: remove this redundant try/finally block
+    if not list(repo.set('parents(%d) and parents(%d)', bumped, prec)):
+        # Need to rebase the changeset at the right place
+        repo.ui.status(
+            _('rebasing to destination parent: %s\n') % prec.p1())
+        try:
+            tmpid = relocate(repo, bumped, prec.p1())
+            if tmpid is not None:
+                tmpctx = repo[tmpid]
+                obsolete.createmarkers(repo, [(bumped, (tmpctx,))])
+        except MergeFailure:
+            repo.opener.write('graftstate', bumped.hex() + '\n')
+            repo.ui.write_err(_('evolution failed!\n'))
+            repo.ui.write_err(
+                _('fix conflict and run "hg evolve --continue"\n'))
+            raise
+    # Create the new commit context
+    repo.ui.status(_('computing new diff\n'))
+    files = set()
+    copied = copies.pathcopies(prec, bumped)
+    precmanifest = prec.manifest()
+    # 3.3.2 needs a list.
+    # future 3.4 don't detect the size change during iteration
+    # this is fishy
+    for key, val in list(bumped.manifest().iteritems()):
+        precvalue = precmanifest.get(key, None)
+        if precvalue is not None:
+            del precmanifest[key]
+        if precvalue != val:
+            files.add(key)
+    files.update(precmanifest)  # add missing files
+    # commit it
+    if files: # something to commit!
+        def filectxfn(repo, ctx, path):
+            if path in bumped:
+                fctx = bumped[path]
+                flags = fctx.flags()
+                mctx = memfilectx(repo, fctx.path(), fctx.data(),
+                                  islink='l' in flags,
+                                  isexec='x' in flags,
+                                  copied=copied.get(path))
+                return mctx
+            return None
+        text = 'bumped update to %s:\n\n' % prec
+        text += bumped.description()
+
+        new = context.memctx(repo,
+                             parents=[prec.node(), node.nullid],
+                             text=text,
+                             files=files,
+                             filectxfn=filectxfn,
+                             user=bumped.user(),
+                             date=bumped.date(),
+                             extra=bumped.extra())
+
+        newid = repo.commitctx(new)
+    if newid is None:
+        obsolete.createmarkers(repo, [(tmpctx, ())])
+        newid = prec.node()
+    else:
+        phases.retractboundary(repo, tr, bumped.phase(), [newid])
+        obsolete.createmarkers(repo, [(tmpctx, (repo[newid],))],
+                               flag=obsolete.bumpedfix)
+    bmupdate(newid)
+    repo.ui.status(_('committed as %s\n') % node.short(newid))
     # reroute the working copy parent to the new changeset
     repo.dirstate.beginparentchange()
     repo.dirstate.setparents(newid, node.nullid)