changeset 37717:0664be4f0c1f

hg: pass command intents to repo/peer creation (API) The previous commit introduced a mechanism to declare command intents. This commit changes the repository and peer instantiation mechanism so the intents are passed down to each repository and peer type so they can do with them whatever they please. Currently, nobody does anything with any intent. Differential Revision: https://phab.mercurial-scm.org/D3377
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 14 Apr 2018 09:57:44 -0700
parents dfc51a482031
children ad1c07008e0b
files hgext/schemes.py mercurial/bundlerepo.py mercurial/dispatch.py mercurial/hg.py mercurial/httppeer.py mercurial/localrepo.py mercurial/sshpeer.py mercurial/statichttprepo.py mercurial/unionrepo.py
diffstat 9 files changed, 21 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/schemes.py	Sat Apr 14 09:23:48 2018 -0700
+++ b/hgext/schemes.py	Sat Apr 14 09:57:44 2018 -0700
@@ -78,9 +78,9 @@
     def __repr__(self):
         return '<ShortRepository: %s>' % self.scheme
 
-    def instance(self, ui, url, create):
+    def instance(self, ui, url, create, intents=None):
         url = self.resolve(url)
-        return hg._peerlookup(url).instance(ui, url, create)
+        return hg._peerlookup(url).instance(ui, url, create, intents=intents)
 
     def resolve(self, url):
         # Should this use the util.url class, or is manual parsing better?
--- a/mercurial/bundlerepo.py	Sat Apr 14 09:23:48 2018 -0700
+++ b/mercurial/bundlerepo.py	Sat Apr 14 09:57:44 2018 -0700
@@ -450,7 +450,7 @@
             self.ui.warn(msg % nodemod.hex(p2))
         return super(bundlerepository, self).setparents(p1, p2)
 
-def instance(ui, path, create):
+def instance(ui, path, create, intents=None):
     if create:
         raise error.Abort(_('cannot create new bundle repository'))
     # internal config: bundle.mainreporoot
--- a/mercurial/dispatch.py	Sat Apr 14 09:23:48 2018 -0700
+++ b/mercurial/dispatch.py	Sat Apr 14 09:57:44 2018 -0700
@@ -928,7 +928,8 @@
             else:
                 try:
                     repo = hg.repository(ui, path=path,
-                                         presetupfuncs=req.prereposetups)
+                                         presetupfuncs=req.prereposetups,
+                                         intents=func.intents)
                     if not repo.local():
                         raise error.Abort(_("repository '%s' is not local")
                                           % path)
--- a/mercurial/hg.py	Sat Apr 14 09:23:48 2018 -0700
+++ b/mercurial/hg.py	Sat Apr 14 09:57:44 2018 -0700
@@ -157,9 +157,10 @@
 # a list of (ui, repo) functions called for wire peer initialization
 wirepeersetupfuncs = []
 
-def _peerorrepo(ui, path, create=False, presetupfuncs=None):
+def _peerorrepo(ui, path, create=False, presetupfuncs=None,
+                intents=None):
     """return a repository object for the specified path"""
-    obj = _peerlookup(path).instance(ui, path, create)
+    obj = _peerlookup(path).instance(ui, path, create, intents=intents)
     ui = getattr(obj, "ui", ui)
     for f in presetupfuncs or []:
         f(ui, obj)
@@ -172,19 +173,20 @@
             f(ui, obj)
     return obj
 
-def repository(ui, path='', create=False, presetupfuncs=None):
+def repository(ui, path='', create=False, presetupfuncs=None, intents=None):
     """return a repository object for the specified path"""
-    peer = _peerorrepo(ui, path, create, presetupfuncs=presetupfuncs)
+    peer = _peerorrepo(ui, path, create, presetupfuncs=presetupfuncs,
+                       intents=intents)
     repo = peer.local()
     if not repo:
         raise error.Abort(_("repository '%s' is not local") %
                          (path or peer.url()))
     return repo.filtered('visible')
 
-def peer(uiorrepo, opts, path, create=False):
+def peer(uiorrepo, opts, path, create=False, intents=None):
     '''return a repository peer for the specified path'''
     rui = remoteui(uiorrepo, opts)
-    return _peerorrepo(rui, path, create).peer()
+    return _peerorrepo(rui, path, create, intents=intents).peer()
 
 def defaultdest(source):
     '''return default destination of clone if none is given
--- a/mercurial/httppeer.py	Sat Apr 14 09:23:48 2018 -0700
+++ b/mercurial/httppeer.py	Sat Apr 14 09:57:44 2018 -0700
@@ -990,7 +990,7 @@
     return httppeer(ui, path, respurl, opener, requestbuilder,
                     info['v1capabilities'])
 
-def instance(ui, path, create):
+def instance(ui, path, create, intents=None):
     if create:
         raise error.Abort(_('cannot create new http repository'))
     try:
--- a/mercurial/localrepo.py	Sat Apr 14 09:23:48 2018 -0700
+++ b/mercurial/localrepo.py	Sat Apr 14 09:57:44 2018 -0700
@@ -413,7 +413,7 @@
         'bisect.state',
     }
 
-    def __init__(self, baseui, path, create=False):
+    def __init__(self, baseui, path, create=False, intents=None):
         self.requirements = set()
         self.filtername = None
         # wvfs: rooted at the repository root, used to access the working copy
@@ -2332,8 +2332,9 @@
     assert name.startswith('journal')
     return os.path.join(base, name.replace('journal', 'undo', 1))
 
-def instance(ui, path, create):
-    return localrepository(ui, util.urllocalpath(path), create)
+def instance(ui, path, create, intents=None):
+    return localrepository(ui, util.urllocalpath(path), create,
+                           intents=intents)
 
 def islocal(path):
     return True
--- a/mercurial/sshpeer.py	Sat Apr 14 09:23:48 2018 -0700
+++ b/mercurial/sshpeer.py	Sat Apr 14 09:57:44 2018 -0700
@@ -587,7 +587,7 @@
         raise error.RepoError(_('unknown version of SSH protocol: %s') %
                               protoname)
 
-def instance(ui, path, create):
+def instance(ui, path, create, intents=None):
     """Create an SSH peer.
 
     The returned object conforms to the ``wireprotov1peer.wirepeer`` interface.
--- a/mercurial/statichttprepo.py	Sat Apr 14 09:23:48 2018 -0700
+++ b/mercurial/statichttprepo.py	Sat Apr 14 09:57:44 2018 -0700
@@ -215,7 +215,7 @@
     def _writecaches(self):
         pass # statichttprepository are read only
 
-def instance(ui, path, create):
+def instance(ui, path, create, intents=None):
     if create:
         raise error.Abort(_('cannot create new static-http repository'))
     return statichttprepository(ui, path[7:])
--- a/mercurial/unionrepo.py	Sat Apr 14 09:23:48 2018 -0700
+++ b/mercurial/unionrepo.py	Sat Apr 14 09:57:44 2018 -0700
@@ -231,7 +231,7 @@
     def getcwd(self):
         return pycompat.getcwd() # always outside the repo
 
-def instance(ui, path, create):
+def instance(ui, path, create, intents=None):
     if create:
         raise error.Abort(_('cannot create new union repository'))
     parentpath = ui.config("bundle", "mainreporoot")