diff mercurial/sparse.py @ 33321:d09e948dc303

sparse: move pruning of temporary includes into core This was our last method on the custom repo type, meaning we could remove that custom type and inline the 2 lines of code into reposetup(). As part of the move, instead of wrapping merge.update() from the sparse extension, we inline the function call. The ported function now no-ops if sparse isn't enabled, making it safe to always call. The call site in update() may not be the most appropriate. But it matches the previous behavior, which is the safest thing to do. It can be improved later.
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 06 Jul 2017 14:33:18 -0700
parents 153456f02426
children fa6c2c3064fd
line wrap: on
line diff
--- a/mercurial/sparse.py	Thu Jul 06 17:41:45 2017 -0700
+++ b/mercurial/sparse.py	Thu Jul 06 14:33:18 2017 -0700
@@ -7,6 +7,7 @@
 
 from __future__ import absolute_import
 
+import collections
 import hashlib
 import os
 
@@ -15,6 +16,7 @@
 from . import (
     error,
     match as matchmod,
+    merge as mergemod,
     pycompat,
 )
 
@@ -197,6 +199,41 @@
         includes.add(i)
     writetemporaryincludes(repo, includes)
 
+def prunetemporaryincludes(repo):
+    if not enabled or not repo.vfs.exists('tempsparse'):
+        return
+
+    origstatus = repo.status()
+    modified, added, removed, deleted, a, b, c = origstatus
+    if modified or added or removed or deleted:
+        # Still have pending changes. Don't bother trying to prune.
+        return
+
+    sparsematch = matcher(repo, includetemp=False)
+    dirstate = repo.dirstate
+    actions = []
+    dropped = []
+    tempincludes = readtemporaryincludes(repo)
+    for file in tempincludes:
+        if file in dirstate and not sparsematch(file):
+            message = _('dropping temporarily included sparse files')
+            actions.append((file, None, message))
+            dropped.append(file)
+
+    typeactions = collections.defaultdict(list)
+    typeactions['r'] = actions
+    mergemod.applyupdates(repo, typeactions, repo[None], repo['.'], False)
+
+    # Fix dirstate
+    for file in dropped:
+        dirstate.drop(file)
+
+    repo.vfs.unlink('tempsparse')
+    invalidatesignaturecache(repo)
+    msg = _('cleaned up %d temporarily added file(s) from the '
+            'sparse checkout\n')
+    repo.ui.status(msg % len(tempincludes))
+
 def matcher(repo, revs=None, includetemp=True):
     """Obtain a matcher for sparse working directories for the given revs.