mercurial/exchange.py
changeset 39569 130e5df346d5
parent 39191 b0c73866c9fb
child 39645 a86d21e70b2b
--- 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()