comparison 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
comparison
equal deleted inserted replaced
41237:ad9ab2523149 41238:8c366af085f4
156 # the server. 156 # the server.
157 del kwargs['known'] 157 del kwargs['known']
158 158
159 extensions.wrapfunction(exchange,'_pullbundle2extraprepare', 159 extensions.wrapfunction(exchange,'_pullbundle2extraprepare',
160 pullbundle2extraprepare) 160 pullbundle2extraprepare)
161
162 # This is an extension point for filesystems that need to do something other
163 # than just blindly unlink the files. It's not clear what arguments would be
164 # useful, so we're passing in a fair number of them, some of them redundant.
165 def _narrowcleanupwdir(repo, oldincludes, oldexcludes, newincludes, newexcludes,
166 oldmatch, newmatch):
167 for f in repo.dirstate:
168 if not newmatch(f):
169 repo.dirstate.drop(f)
170 repo.wvfs.unlinkpath(f)
171 161
172 def _narrow(ui, repo, remote, commoninc, oldincludes, oldexcludes, 162 def _narrow(ui, repo, remote, commoninc, oldincludes, oldexcludes,
173 newincludes, newexcludes, force): 163 newincludes, newexcludes, force):
174 oldmatch = narrowspec.match(repo.root, oldincludes, oldexcludes) 164 oldmatch = narrowspec.match(repo.root, oldincludes, oldexcludes)
175 newmatch = narrowspec.match(repo.root, newincludes, newexcludes) 165 newmatch = narrowspec.match(repo.root, newincludes, newexcludes)
238 if not include: 228 if not include:
239 todelete.append(f) 229 todelete.append(f)
240 230
241 repo.destroying() 231 repo.destroying()
242 232
243 with repo.transaction("narrowing"): 233 with repo.transaction('narrowing'):
244 # Update narrowspec before removing revlogs, so repo won't be 234 # Update narrowspec before removing revlogs, so repo won't be
245 # corrupt in case of crash 235 # corrupt in case of crash
246 repo.setnarrowpats(newincludes, newexcludes) 236 repo.setnarrowpats(newincludes, newexcludes)
247 narrowspec.copytoworkingcopy(repo)
248 237
249 for f in todelete: 238 for f in todelete:
250 ui.status(_('deleting %s\n') % f) 239 ui.status(_('deleting %s\n') % f)
251 util.unlinkpath(repo.svfs.join(f)) 240 util.unlinkpath(repo.svfs.join(f))
252 repo.store.markremoved(f) 241 repo.store.markremoved(f)
253 242
254 _narrowcleanupwdir(repo, oldincludes, oldexcludes, newincludes, 243 narrowspec.updateworkingcopy(repo, assumeclean=True)
255 newexcludes, oldmatch, newmatch) 244 narrowspec.copytoworkingcopy(repo)
256 245
257 repo.destroyed() 246 repo.destroyed()
258 247
259 def _widen(ui, repo, remote, commoninc, oldincludes, oldexcludes, 248 def _widen(ui, repo, remote, commoninc, oldincludes, oldexcludes,
260 newincludes, newexcludes): 249 newincludes, newexcludes):