[PATCH 02 of 11 sparse] sparse: move code for clearing rules to core

Gregory Szorc gregory.szorc at gmail.com
Sat Jul 8 19:28:57 EDT 2017


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1499545178 25200
#      Sat Jul 08 13:19:38 2017 -0700
# Node ID b54b5a5d05a19ad9d2b4b52f72a87fc4706cba3e
# Parent  05fba83e64406ea5051763c4c14c4067b2b72254
sparse: move code for clearing rules to core

This is a pretty straightforward port.

diff --git a/hgext/sparse.py b/hgext/sparse.py
--- a/hgext/sparse.py
+++ b/hgext/sparse.py
@@ -365,7 +365,7 @@ def debugsparse(ui, repo, *pats, **opts)
         _import(ui, repo, pats, opts, force=force)
 
     if clearrules:
-        _clear(ui, repo, pats, force=force)
+        sparse.clearrules(repo, force=force)
 
     if refresh:
         try:
@@ -503,17 +503,6 @@ def _import(ui, repo, files, opts, force
         _verbose_output(ui, opts, profilecount, includecount, excludecount,
                         *fcounts)
 
-def _clear(ui, repo, files, force=False):
-    with repo.wlock():
-        raw = repo.vfs.tryread('sparse')
-        includes, excludes, profiles = sparse.parseconfig(ui, raw)
-
-        if includes or excludes:
-            oldstatus = repo.status()
-            oldsparsematch = sparse.matcher(repo)
-            sparse.writeconfig(repo, set(), set(), profiles)
-            sparse.refreshwdir(repo, oldstatus, oldsparsematch, force)
-
 def _verbose_output(ui, opts, profilecount, includecount, excludecount, added,
                     dropped, lookup):
     """Produce --verbose and templatable output
diff --git a/mercurial/sparse.py b/mercurial/sparse.py
--- a/mercurial/sparse.py
+++ b/mercurial/sparse.py
@@ -494,3 +494,21 @@ def aftercommit(repo, node):
         refreshwdir(repo, origstatus, origsparsematch, force=True)
 
     prunetemporaryincludes(repo)
+
+def clearrules(repo, force=False):
+    """Clears include/exclude rules from the sparse config.
+
+    The remaining sparse config only has profiles, if defined. The working
+    directory is refreshed, as needed.
+    """
+    with repo.wlock():
+        raw = repo.vfs.tryread('sparse')
+        includes, excludes, profiles = parseconfig(repo.ui, raw)
+
+        if not includes and not excludes:
+            return
+
+        oldstatus = repo.status()
+        oldmatch = matcher(repo)
+        writeconfig(repo, set(), set(), profiles)
+        refreshwdir(repo, oldstatus, oldmatch, force=force)


More information about the Mercurial-devel mailing list