Patchwork D6437: narrow: refactor code around widening complicated by previous patch

login
register
mail settings
Submitter phabricator
Date May 22, 2019, 9:47 p.m.
Message ID <differential-rev-PHID-DREV-ayjskr6yq7kzwjijjxqc-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/40198/
State Superseded
Headers show

Comments

phabricator - May 22, 2019, 9:47 p.m.
pulkit created this revision.
Herald added a reviewer: durin42.
Herald added a reviewer: martinvonz.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Previous patch while adding support for using narrow_widen wireproto command,
  complicated the code a bit. This patch refactors that.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6437

AFFECTED FILES
  hgext/narrow/narrowcommands.py

CHANGE DETAILS




To: pulkit, durin42, martinvonz, #hg-reviewers
Cc: mercurial-devel
phabricator - June 4, 2019, 5:36 p.m.
martinvonz added inline comments.

INLINE COMMENTS

> narrowcommands.py:281
>  
> +    bundle = None
> +    known = []

nit: looks like this can be deleted

> narrowcommands.py:282
> +    bundle = None
> +    known = []
> +    common = commoninc[0]

nit: looks like these can be moved to before line 294

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6437

To: pulkit, durin42, martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/hgext/narrow/narrowcommands.py b/hgext/narrow/narrowcommands.py
--- a/hgext/narrow/narrowcommands.py
+++ b/hgext/narrow/narrowcommands.py
@@ -255,71 +255,48 @@ 
     # functionality from an ellipses enabled server
     ellipsesremote = wireprototypes.ELLIPSESCAP in remote.capabilities()
 
-    def pullbundle2extraprepare_widen(orig, pullop, kwargs):
-        orig(pullop, kwargs)
-        # The old{in,ex}cludepats have already been set by orig()
-        kwargs['includepats'] = newincludes
-        kwargs['excludepats'] = newexcludes
-    wrappedextraprepare = extensions.wrappedfunction(exchange,
-        '_pullbundle2extraprepare', pullbundle2extraprepare_widen)
-
     # define a function that narrowbundle2 can call after creating the
     # backup bundle, but before applying the bundle from the server
     def setnewnarrowpats():
         repo.setnarrowpats(newincludes, newexcludes)
     repo.setnewnarrowpats = setnewnarrowpats
     # silence the devel-warning of applying an empty changegroup
     overrides = {('devel', 'all-warnings'): False}
 
+    bundle = None
+    known = []
+    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)
-            with wrappedextraprepare:
-                known = [node.hex(ctx.node()) for ctx in
-                                   repo.set('::%ln', common)
-                                   if ctx.node() != node.nullid]
+            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 remote.commandexecutor() as e:
+            bundle = e.callcommand('narrow_widen', {
+                'oldincludes': oldincludes,
+                'oldexcludes': oldexcludes,
+                'newincludes': newincludes,
+                'newexcludes': newexcludes,
+                'cgversion': '03',
+                'commonheads': common,
+                'known': known,
+                'ellipses': ellipsesremote,
+            }).result()
+        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)
-        else:
-            with remote.commandexecutor() as e:
-                bundle = e.callcommand('narrow_widen', {
-                    'oldincludes': oldincludes,
-                    'oldexcludes': oldexcludes,
-                    'newincludes': newincludes,
-                    'newexcludes': newexcludes,
-                    'cgversion': '03',
-                    'commonheads': common,
-                    'known': [],
-                    'ellipses': False,
-                }).result()
-
-            with repo.transaction('widening') as tr:
-                with repo.ui.configoverride(overrides, 'widen'):
-                    tgetter = lambda: tr
-                    bundle2.processbundle(repo, bundle,
-                            transactiongetter=tgetter)
 
         with repo.transaction('widening'):
             repo.setnewnarrowpats()