[PATCH 3 of 9 sparse] sparse: move some temporary includes functions into core

Gregory Szorc gregory.szorc at gmail.com
Thu Jul 6 17:54:19 EDT 2017


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1499377696 25200
#      Thu Jul 06 14:48:16 2017 -0700
# Node ID 7bd81df5813100a0a28ac2373722cd6405b5c505
# Parent  868fe26df6ac39fddf1decc3ceae5dc0db9248be
sparse: move some temporary includes functions into core

Functions for reading and writing the tempsparse file have been
moved. prunetemporaryincludes() will be moved separately
because it is non-trivial.

diff --git a/hgext/sparse.py b/hgext/sparse.py
--- a/hgext/sparse.py
+++ b/hgext/sparse.py
@@ -193,7 +193,7 @@ def _setupupdates(ui):
         if len(temporaryfiles) > 0:
             ui.status(_("temporarily included %d file(s) in the sparse checkout"
                 " for merging\n") % len(temporaryfiles))
-            repo.addtemporaryincludes(temporaryfiles)
+            sparse.addtemporaryincludes(repo, temporaryfiles)
 
             # Add the new files to the working copy so they can be merged, etc
             actions = []
@@ -503,31 +503,13 @@ def _wraprepo(ui, repo):
                 result = unionmatcher(matchers)
 
             if kwargs.get('includetemp', True):
-                tempincludes = self.gettemporaryincludes()
+                tempincludes = sparse.readtemporaryincludes(self)
                 result = forceincludematcher(result, tempincludes)
 
             self._sparsematchercache[key] = result
 
             return result
 
-        def addtemporaryincludes(self, files):
-            includes = self.gettemporaryincludes()
-            for file in files:
-                includes.add(file)
-            self._writetemporaryincludes(includes)
-
-        def gettemporaryincludes(self):
-            existingtemp = set()
-            raw = self.vfs.tryread('tempsparse')
-            if raw:
-                existingtemp.update(raw.split('\n'))
-            return existingtemp
-
-        def _writetemporaryincludes(self, includes):
-            raw = '\n'.join(sorted(includes))
-            self.vfs.write('tempsparse', raw)
-            sparse.invalidatesignaturecache(self)
-
         def prunetemporaryincludes(self):
             if repo.vfs.exists('tempsparse'):
                 origstatus = self.status()
@@ -540,7 +522,7 @@ def _wraprepo(ui, repo):
                 dirstate = self.dirstate
                 actions = []
                 dropped = []
-                tempincludes = self.gettemporaryincludes()
+                tempincludes = sparse.readtemporaryincludes(self)
                 for file in tempincludes:
                     if file in dirstate and not sparsematch(file):
                         message = 'dropping temporarily included sparse files'
@@ -639,7 +621,7 @@ def debugsparse(ui, repo, *pats, **opts)
     if count == 0:
         if repo.vfs.exists('sparse'):
             ui.status(repo.vfs.read("sparse") + "\n")
-            temporaryincludes = repo.gettemporaryincludes()
+            temporaryincludes = sparse.readtemporaryincludes(repo)
             if temporaryincludes:
                 ui.status(_("Temporarily Included Files (for merge/rebase):\n"))
                 ui.status(("\n".join(temporaryincludes) + "\n"))
diff --git a/mercurial/sparse.py b/mercurial/sparse.py
--- a/mercurial/sparse.py
+++ b/mercurial/sparse.py
@@ -149,3 +149,20 @@ def writeconfig(repo, includes, excludes
                 fh.write('\n')
 
     invalidatesignaturecache(repo)
+
+def readtemporaryincludes(repo):
+    raw = repo.vfs.tryread('tempsparse')
+    if not raw:
+        return set()
+
+    return set(raw.split('\n'))
+
+def writetemporaryincludes(repo, includes):
+    repo.vfs.write('tempsparse', '\n'.join(sorted(includes)))
+    invalidatesignaturecache(repo)
+
+def addtemporaryincludes(repo, additional):
+    includes = readtemporaryincludes(repo)
+    for i in additional:
+        includes.add(i)
+    writetemporaryincludes(repo, includes)


More information about the Mercurial-devel mailing list