comparison hgext/narrow/narrowcommands.py @ 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 f1844a10ee19
children 24e493ec2229
comparison
equal deleted inserted replaced
39733:5adc5fe41a7d 39734:9d5c919b6dc3
157 # the server. 157 # the server.
158 del kwargs['known'] 158 del kwargs['known']
159 159
160 extensions.wrapfunction(exchange,'_pullbundle2extraprepare', 160 extensions.wrapfunction(exchange,'_pullbundle2extraprepare',
161 pullbundle2extraprepare) 161 pullbundle2extraprepare)
162
163 # This is an extension point for filesystems that need to do something other
164 # than just blindly unlink the files. It's not clear what arguments would be
165 # useful, so we're passing in a fair number of them, some of them redundant.
166 def _narrowcleanupwdir(repo, oldincludes, oldexcludes, newincludes, newexcludes,
167 oldmatch, newmatch):
168 for f in repo.dirstate:
169 if not newmatch(f):
170 repo.dirstate.drop(f)
171 repo.wvfs.unlinkpath(f)
162 172
163 def _narrow(ui, repo, remote, commoninc, oldincludes, oldexcludes, 173 def _narrow(ui, repo, remote, commoninc, oldincludes, oldexcludes,
164 newincludes, newexcludes, force): 174 newincludes, newexcludes, force):
165 oldmatch = narrowspec.match(repo.root, oldincludes, oldexcludes) 175 oldmatch = narrowspec.match(repo.root, oldincludes, oldexcludes)
166 newmatch = narrowspec.match(repo.root, newincludes, newexcludes) 176 newmatch = narrowspec.match(repo.root, newincludes, newexcludes)
233 for f in todelete: 243 for f in todelete:
234 ui.status(_('deleting %s\n') % f) 244 ui.status(_('deleting %s\n') % f)
235 util.unlinkpath(repo.svfs.join(f)) 245 util.unlinkpath(repo.svfs.join(f))
236 repo.store.markremoved(f) 246 repo.store.markremoved(f)
237 247
238 for f in repo.dirstate: 248 _narrowcleanupwdir(repo, oldincludes, oldexcludes, newincludes,
239 if not newmatch(f): 249 newexcludes, oldmatch, newmatch)
240 repo.dirstate.drop(f)
241 repo.wvfs.unlinkpath(f)
242 repo.setnarrowpats(newincludes, newexcludes) 250 repo.setnarrowpats(newincludes, newexcludes)
243 251
244 repo.destroyed() 252 repo.destroyed()
245 253
246 def _widen(ui, repo, remote, commoninc, newincludes, newexcludes): 254 def _widen(ui, repo, remote, commoninc, newincludes, newexcludes):