exchange: support defining narrow file patterns for pull
This commit teaches exchange.pull() about the desire to perform a
narrow file pull. We simply pass include and exclude patterns to
the function. The values are validated and stored on the pulloperation
instance.
hg.clone() has been taught to pass these arguments to exchange.pull().
If the arguments are not passed to exchange.pull(), the active narrow
patterns from the repository will automatically be used. We /could/
always use the narrow patterns from the repo. However, allowing
explicit values to be passed in allows us to perform data fetching
that doesn't necessarily align with the repo configuration. This
provides more flexibility.
Differential Revision: https://phab.mercurial-scm.org/D4539
--- a/mercurial/exchange.py Tue Sep 11 17:20:14 2018 -0700
+++ b/mercurial/exchange.py Tue Sep 11 17:21:18 2018 -0700
@@ -1313,7 +1313,8 @@
"""
def __init__(self, repo, remote, heads=None, force=False, bookmarks=(),
- remotebookmarks=None, streamclonerequested=None):
+ remotebookmarks=None, streamclonerequested=None,
+ includepats=None, excludepats=None):
# repo we pull into
self.repo = repo
# repo we pull from
@@ -1343,6 +1344,10 @@
self.stepsdone = set()
# Whether we attempted a clone from pre-generated bundles.
self.clonebundleattempted = False
+ # Set of file patterns to include.
+ self.includepats = includepats
+ # Set of file patterns to exclude.
+ self.excludepats = excludepats
@util.propertycache
def pulledsubset(self):
@@ -1447,7 +1452,7 @@
pullop.rheads = set(pullop.rheads) - pullop.common
def pull(repo, remote, heads=None, force=False, bookmarks=(), opargs=None,
- streamclonerequested=None):
+ streamclonerequested=None, includepats=None, excludepats=None):
"""Fetch repository data from a remote.
This is the main function used to retrieve data from a remote repository.
@@ -1465,13 +1470,29 @@
of revlogs from the server. This only works when the local repository is
empty. The default value of ``None`` means to respect the server
configuration for preferring stream clones.
+ ``includepats`` and ``excludepats`` define explicit file patterns to
+ include and exclude in storage, respectively. If not defined, narrow
+ patterns from the repo instance are used, if available.
Returns the ``pulloperation`` created for this pull.
"""
if opargs is None:
opargs = {}
+
+ # We allow the narrow patterns to be passed in explicitly to provide more
+ # flexibility for API consumers.
+ if includepats or excludepats:
+ includepats = includepats or set()
+ excludepats = excludepats or set()
+ else:
+ includepats, excludepats = repo.narrowpats
+
+ narrowspec.validatepatterns(includepats)
+ narrowspec.validatepatterns(excludepats)
+
pullop = pulloperation(repo, remote, heads, force, bookmarks=bookmarks,
streamclonerequested=streamclonerequested,
+ includepats=includepats, excludepats=excludepats,
**pycompat.strkwargs(opargs))
peerlocal = pullop.remote.local()
--- a/mercurial/hg.py Tue Sep 11 17:20:14 2018 -0700
+++ b/mercurial/hg.py Tue Sep 11 17:21:18 2018 -0700
@@ -749,7 +749,9 @@
overrides = {('ui', 'quietbookmarkmove'): True}
with local.ui.configoverride(overrides, 'clone'):
exchange.pull(local, srcpeer, revs,
- streamclonerequested=stream)
+ streamclonerequested=stream,
+ includepats=storeincludepats,
+ excludepats=storeexcludepats)
elif srcrepo:
# TODO lift restriction once exchange.push() accepts narrow
# push.