# HG changeset patch # User Gregory Szorc # Date 1499377696 25200 # Node ID 3e1accab7447b67ebb58d5b5da341e553a4cc564 # Parent 8b571495d8118b399dbea7d5d7da6700b7a5bd5d 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 -r 8b571495d811 -r 3e1accab7447 hgext/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")) diff -r 8b571495d811 -r 3e1accab7447 mercurial/sparse.py --- 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)