narrow: refactor code around widening complicated by previous patch
authorPulkit Goyal <7895pulkit@gmail.com>
Thu, 23 May 2019 02:48:25 +0530
changeset 42416 8381b7067f17
parent 42415 c767e655ffda
child 42417 a97b12f726e4
narrow: refactor code around widening complicated by previous patch Previous patch while adding support for using narrow_widen wireproto command, complicated the code a bit. This patch refactors that. Differential Revision: https://phab.mercurial-scm.org/D6437
hgext/narrow/narrowcommands.py
--- a/hgext/narrow/narrowcommands.py	Wed May 22 02:59:48 2019 +0530
+++ b/hgext/narrow/narrowcommands.py	Thu May 23 02:48:25 2019 +0530
@@ -278,42 +278,22 @@
     # silence the devel-warning of applying an empty changegroup
     overrides = {('devel', 'all-warnings'): False}
 
+    common = commoninc[0]
     with ui.uninterruptible():
-        common = commoninc[0]
         if ellipsesremote:
             ds = repo.dirstate
             p1, p2 = ds.p1(), ds.p2()
             with ds.parentchange():
                 ds.setparents(node.nullid, node.nullid)
+        if isoldellipses:
             with wrappedextraprepare:
-                if isoldellipses:
-                    exchange.pull(repo, remote, heads=common)
-                else:
-                    known = [node.hex(ctx.node()) for ctx in
-                                       repo.set('::%ln', common)
-                                       if ctx.node() != node.nullid]
-
-                    with remote.commandexecutor() as e:
-                        bundle = e.callcommand('narrow_widen', {
-                            'oldincludes': oldincludes,
-                            'oldexcludes': oldexcludes,
-                            'newincludes': newincludes,
-                            'newexcludes': newexcludes,
-                            'cgversion': '03',
-                            'commonheads': common,
-                            'known': known,
-                            'ellipses': True,
-                        }).result()
-                    trmanager = exchange.transactionmanager(repo, 'widen',
-                                                            remote.url())
-                    with trmanager:
-                        op = bundle2.bundleoperation(repo,
-                                trmanager.transaction, source='widen')
-                        bundle2.processbundle(repo, bundle, op=op)
-
-            with ds.parentchange():
-                ds.setparents(p1, p2)
+                exchange.pull(repo, remote, heads=common)
         else:
+            known = []
+            if ellipsesremote:
+                known = [node.hex(ctx.node()) for ctx in
+                         repo.set('::%ln', common)
+                         if ctx.node() != node.nullid]
             with remote.commandexecutor() as e:
                 bundle = e.callcommand('narrow_widen', {
                     'oldincludes': oldincludes,
@@ -322,15 +302,20 @@
                     'newexcludes': newexcludes,
                     'cgversion': '03',
                     'commonheads': common,
-                    'known': [],
-                    'ellipses': False,
+                    'known': known,
+                    'ellipses': ellipsesremote,
                 }).result()
 
-            with repo.transaction('widening') as tr:
-                with repo.ui.configoverride(overrides, 'widen'):
-                    tgetter = lambda: tr
-                    bundle2.processbundle(repo, bundle,
-                            transactiongetter=tgetter)
+            trmanager = exchange.transactionmanager(repo, 'widen', remote.url())
+            with trmanager, repo.ui.configoverride(overrides, 'widen'):
+                op = bundle2.bundleoperation(repo, trmanager.transaction,
+                                             source='widen')
+                # TODO: we should catch error.Abort here
+                bundle2.processbundle(repo, bundle, op=op)
+
+        if ellipsesremote:
+            with ds.parentchange():
+                ds.setparents(p1, p2)
 
         with repo.transaction('widening'):
             repo.setnewnarrowpats()