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

login
register
mail settings
Submitter Gregory Szorc
Date July 6, 2017, 9:54 p.m.
Message ID <7bd81df5813100a0a28a.1499378059@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/22055/
State Accepted
Headers show

Comments

Gregory Szorc - July 6, 2017, 9:54 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@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.
via Mercurial-devel - July 6, 2017, 10:21 p.m.
On Thu, Jul 6, 2017 at 2:54 PM, Gregory Szorc <gregory.szorc@gmail.com> wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@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
>
> 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):

Looks like this one could have preserved its leading _.

Patch

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)