Patchwork D5511: narrow: reuse narrowspec.updateworkingcopy() when narrowing

login
register
mail settings
Submitter phabricator
Date Jan. 16, 2019, 9:34 a.m.
Message ID <e655ff806f0b7ca2e6bd0157249f70df@localhost.localdomain>
Download mbox | patch
Permalink /patch/37783/
State Not Applicable
Headers show

Comments

phabricator - Jan. 16, 2019, 9:34 a.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG8a26faac4a45: narrow: reuse narrowspec.updateworkingcopy() when narrowing (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5511?vs=13150&id=13248

REVISION DETAIL
  https://phab.mercurial-scm.org/D5511

AFFECTED FILES
  hgext/narrow/narrowcommands.py
  mercurial/narrowspec.py

CHANGE DETAILS




To: martinvonz, durin42, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/narrowspec.py b/mercurial/narrowspec.py
--- a/mercurial/narrowspec.py
+++ b/mercurial/narrowspec.py
@@ -273,7 +273,12 @@ 
         raise error.Abort(_("working copy's narrowspec is stale"),
                           hint=_("run 'hg tracked --update-working-copy'"))
 
-def updateworkingcopy(repo):
+def updateworkingcopy(repo, assumeclean=False):
+    """updates the working copy and dirstate from the store narrowspec
+
+    When assumeclean=True, files that are not known to be clean will also
+    be deleted. It is then up to the caller to make sure they are clean.
+    """
     oldspec = repo.vfs.tryread(DIRSTATE_FILENAME)
     newspec = repo.svfs.tryread(FILENAME)
 
@@ -287,11 +292,17 @@ 
     ds = repo.dirstate
     lookup, status = ds.status(removedmatch, subrepos=[], ignored=False,
                                clean=True, unknown=False)
-    _deletecleanfiles(repo, status.clean)
-    trackeddirty = lookup + status.modified + status.added
+    trackeddirty = status.modified + status.added
+    clean = status.clean
+    if assumeclean:
+        assert not trackeddirty
+        clean.extend(lookup)
+    else:
+        trackeddirty.extend(lookup)
+    _deletecleanfiles(repo, clean)
     for f in sorted(trackeddirty):
         repo.ui.status(_('not deleting possibly dirty file %s\n') % f)
-    for f in status.clean + trackeddirty:
+    for f in clean + trackeddirty:
         ds.drop(f)
 
     repo.narrowpats = newincludes, newexcludes
diff --git a/hgext/narrow/narrowcommands.py b/hgext/narrow/narrowcommands.py
--- a/hgext/narrow/narrowcommands.py
+++ b/hgext/narrow/narrowcommands.py
@@ -160,16 +160,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)
@@ -241,19 +231,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()