changeset 39734:9d5c919b6dc3

narrow: extract wdir cleanup function to make it extensible We have an overlay filesystem which shows the entire repository, and unlinking a file that's in the underlying data store will create "tombstone" entries, which are going to cause our automatic tracking to re-add these directories. We need to use a different (non-posix) interface to clean up items in the working directory that are no longer relevant. Extracting this to a function lets us use extensions.wrappedfunction and perform this cleanup work, even if the paths aren't in the dirstate (they may have been removed in the past and thus entirely "tombstone" entries already, part of hgignore, exclusively directories (possibly empty), or other edge cases). Differential Revision: https://phab.mercurial-scm.org/D4681
author Kyle Lippincott <spectral@google.com>
date Thu, 20 Sep 2018 12:13:00 -0700
parents 5adc5fe41a7d
children c0c703861b60
files hgext/narrow/narrowcommands.py
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/narrow/narrowcommands.py	Thu Sep 20 09:52:59 2018 -0400
+++ b/hgext/narrow/narrowcommands.py	Thu Sep 20 12:13:00 2018 -0700
@@ -160,6 +160,16 @@
 extensions.wrapfunction(exchange,'_pullbundle2extraprepare',
                         pullbundle2extraprepare)
 
+# This is an extension point for filesystems that need to do something other
+# than just blindly unlink the files. It's not clear what arguments would be
+# useful, so we're passing in a fair number of them, some of them redundant.
+def _narrowcleanupwdir(repo, oldincludes, oldexcludes, newincludes, newexcludes,
+                       oldmatch, newmatch):
+    for f in repo.dirstate:
+        if not newmatch(f):
+            repo.dirstate.drop(f)
+            repo.wvfs.unlinkpath(f)
+
 def _narrow(ui, repo, remote, commoninc, oldincludes, oldexcludes,
             newincludes, newexcludes, force):
     oldmatch = narrowspec.match(repo.root, oldincludes, oldexcludes)
@@ -235,10 +245,8 @@
                 util.unlinkpath(repo.svfs.join(f))
                 repo.store.markremoved(f)
 
-            for f in repo.dirstate:
-                if not newmatch(f):
-                    repo.dirstate.drop(f)
-                    repo.wvfs.unlinkpath(f)
+            _narrowcleanupwdir(repo, oldincludes, oldexcludes, newincludes,
+                               newexcludes, oldmatch, newmatch)
             repo.setnarrowpats(newincludes, newexcludes)
 
         repo.destroyed()