sparse: move some temporary includes functions into core
authorGregory Szorc <gregory.szorc@gmail.com>
Thu, 06 Jul 2017 14:48:16 -0700
changeset 33304 3e1accab7447
parent 33303 8b571495d811
child 33305 aaa1f8f514cf
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.
hgext/sparse.py
mercurial/sparse.py
--- a/hgext/sparse.py	Thu Jul 06 12:24:55 2017 -0700
+++ b/hgext/sparse.py	Thu Jul 06 14:48:16 2017 -0700
@@ -193,7 +193,7 @@
         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 @@
                 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 @@
                 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 @@
     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"))
--- a/mercurial/sparse.py	Thu Jul 06 12:24:55 2017 -0700
+++ b/mercurial/sparse.py	Thu Jul 06 14:48:16 2017 -0700
@@ -149,3 +149,20 @@
                 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)