exchange: expose bundle2 capabilities on pulloperation
authorGregory Szorc <gregory.szorc@gmail.com>
Sun, 04 Oct 2015 18:31:53 -0700
changeset 26464 9a7fc6d48898
parent 26463 b3188339a772
child 26465 eda32ee9962f
exchange: expose bundle2 capabilities on pulloperation This adds a cache and makes accessing the capabilities slightly simpler, as you don't need to directly go through the bundle2 module. This will also help prevent a function-level import in streamclone.py. This patch arguably isn't necessary. But I think it makes things slightly nicer.
mercurial/exchange.py
--- a/mercurial/exchange.py	Sun Oct 04 21:33:29 2015 +0900
+++ b/mercurial/exchange.py	Sun Oct 04 18:31:53 2015 -0700
@@ -893,6 +893,10 @@
             # sync on this subset
             return self.heads
 
+    @util.propertycache
+    def remotebundle2caps(self):
+        return bundle2.bundle2caps(self.remote)
+
     def gettransaction(self):
         # deprecated; talk to trmanager directly
         return self.trmanager.transaction()
@@ -1017,8 +1021,7 @@
     discovery to reduce the chance and impact of race conditions."""
     if pullop.remotebookmarks is not None:
         return
-    if (_canusebundle2(pullop)
-            and 'listkeys' in bundle2.bundle2caps(pullop.remote)):
+    if _canusebundle2(pullop) and 'listkeys' in pullop.remotebundle2caps:
         # all known bundle2 servers now support listkeys, but lets be nice with
         # new implementation.
         return
@@ -1067,7 +1070,6 @@
     """pull data using bundle2
 
     For now, the only supported data are changegroup."""
-    remotecaps = bundle2.bundle2caps(pullop.remote)
     kwargs = {'bundlecaps': caps20to10(pullop.repo)}
     # pulling changegroup
     pullop.stepsdone.add('changegroup')
@@ -1075,7 +1077,7 @@
     kwargs['common'] = pullop.common
     kwargs['heads'] = pullop.heads or pullop.rheads
     kwargs['cg'] = pullop.fetch
-    if 'listkeys' in remotecaps:
+    if 'listkeys' in pullop.remotebundle2caps:
         kwargs['listkeys'] = ['phase']
         if pullop.remotebookmarks is None:
             # make sure to always includes bookmark data when migrating
@@ -1088,7 +1090,7 @@
         if pullop.heads is None and list(pullop.common) == [nullid]:
             pullop.repo.ui.status(_("requesting all changes\n"))
     if obsolete.isenabled(pullop.repo, obsolete.exchangeopt):
-        remoteversions = bundle2.obsmarkersversion(remotecaps)
+        remoteversions = bundle2.obsmarkersversion(pullop.remotebundle2caps)
         if obsolete.commonversion(remoteversions) is not None:
             kwargs['obsmarkers'] = True
             pullop.stepsdone.add('obsmarkers')