diff hgext/narrow/narrowcommands.py @ 41238:8c366af085f4

narrow: reuse narrowspec.updateworkingcopy() when narrowing Similar to the previous patch for widening, but here we also need to teach updateworkingcopy() to forcefully delete files that are not recorded in the dirstate as clean. That should be safe because the narrowing command (e.g. `hg tracked --removeinclude`) has already checked that the working copy is clean. Differential Revision: https://phab.mercurial-scm.org/D5511
author Martin von Zweigbergk <martinvonz@google.com>
date Sun, 30 Dec 2018 00:15:38 -0800
parents ad9ab2523149
children ebbc4e70ebd1
line wrap: on
line diff
--- a/hgext/narrow/narrowcommands.py	Fri Dec 21 10:05:37 2018 -0800
+++ b/hgext/narrow/narrowcommands.py	Sun Dec 30 00:15:38 2018 -0800
@@ -159,16 +159,6 @@
 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)
@@ -240,19 +230,18 @@
 
         repo.destroying()
 
-        with repo.transaction("narrowing"):
+        with repo.transaction('narrowing'):
             # Update narrowspec before removing revlogs, so repo won't be
             # corrupt in case of crash
             repo.setnarrowpats(newincludes, newexcludes)
-            narrowspec.copytoworkingcopy(repo)
 
             for f in todelete:
                 ui.status(_('deleting %s\n') % f)
                 util.unlinkpath(repo.svfs.join(f))
                 repo.store.markremoved(f)
 
-            _narrowcleanupwdir(repo, oldincludes, oldexcludes, newincludes,
-                               newexcludes, oldmatch, newmatch)
+            narrowspec.updateworkingcopy(repo, assumeclean=True)
+            narrowspec.copytoworkingcopy(repo)
 
         repo.destroyed()