Patchwork [2,of,2] evolve: removed redundant try/finally blocks

login
register
mail settings
Submitter Pulkit Goyal
Date Aug. 31, 2016, 11:14 p.m.
Message ID <2ab652cca0c72df66344.1472685244@pulkit-goyal>
Download mbox | patch
Permalink /patch/16520/
State Superseded
Headers show

Comments

Pulkit Goyal - Aug. 31, 2016, 11:14 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1472684936 -19800
#      Thu Sep 01 04:38:56 2016 +0530
# Branch stable
# Node ID 2ab652cca0c72df663446cc5e79bef2afa0e9854
# Parent  20689e0835c621df4cd19efe7bd06127ab1e0bf8
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.
Pierre-Yves David - Sept. 6, 2016, 12:31 p.m.
On 09/01/2016 01:14 AM, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1472684936 -19800
> #      Thu Sep 01 04:38:56 2016 +0530
> # Branch stable
> # Node ID 2ab652cca0c72df663446cc5e79bef2afa0e9854
> # Parent  20689e0835c621df4cd19efe7bd06127ab1e0bf8
> 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.

I've taken that one, thanks.

Patch

diff -r 20689e0835c6 -r 2ab652cca0c7 hgext/evolve.py
--- a/hgext/evolve.py	Thu Sep 01 03:23:31 2016 +0530
+++ b/hgext/evolve.py	Thu Sep 01 04:38:56 2016 +0530
@@ -963,28 +963,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):
@@ -1993,73 +1990,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)