comparison mercurial/narrowspec.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 50ca531f1f24
children 88a7c211b21e
comparison
equal deleted inserted replaced
41237:ad9ab2523149 41238:8c366af085f4
271 wcspec = repo.vfs.tryread(DIRSTATE_FILENAME) 271 wcspec = repo.vfs.tryread(DIRSTATE_FILENAME)
272 if wcspec != storespec: 272 if wcspec != storespec:
273 raise error.Abort(_("working copy's narrowspec is stale"), 273 raise error.Abort(_("working copy's narrowspec is stale"),
274 hint=_("run 'hg tracked --update-working-copy'")) 274 hint=_("run 'hg tracked --update-working-copy'"))
275 275
276 def updateworkingcopy(repo): 276 def updateworkingcopy(repo, assumeclean=False):
277 """updates the working copy and dirstate from the store narrowspec
278
279 When assumeclean=True, files that are not known to be clean will also
280 be deleted. It is then up to the caller to make sure they are clean.
281 """
277 oldspec = repo.vfs.tryread(DIRSTATE_FILENAME) 282 oldspec = repo.vfs.tryread(DIRSTATE_FILENAME)
278 newspec = repo.svfs.tryread(FILENAME) 283 newspec = repo.svfs.tryread(FILENAME)
279 284
280 oldincludes, oldexcludes = parseconfig(repo.ui, oldspec) 285 oldincludes, oldexcludes = parseconfig(repo.ui, oldspec)
281 newincludes, newexcludes = parseconfig(repo.ui, newspec) 286 newincludes, newexcludes = parseconfig(repo.ui, newspec)
285 removedmatch = matchmod.differencematcher(oldmatch, newmatch) 290 removedmatch = matchmod.differencematcher(oldmatch, newmatch)
286 291
287 ds = repo.dirstate 292 ds = repo.dirstate
288 lookup, status = ds.status(removedmatch, subrepos=[], ignored=False, 293 lookup, status = ds.status(removedmatch, subrepos=[], ignored=False,
289 clean=True, unknown=False) 294 clean=True, unknown=False)
290 _deletecleanfiles(repo, status.clean) 295 trackeddirty = status.modified + status.added
291 trackeddirty = lookup + status.modified + status.added 296 clean = status.clean
297 if assumeclean:
298 assert not trackeddirty
299 clean.extend(lookup)
300 else:
301 trackeddirty.extend(lookup)
302 _deletecleanfiles(repo, clean)
292 for f in sorted(trackeddirty): 303 for f in sorted(trackeddirty):
293 repo.ui.status(_('not deleting possibly dirty file %s\n') % f) 304 repo.ui.status(_('not deleting possibly dirty file %s\n') % f)
294 for f in status.clean + trackeddirty: 305 for f in clean + trackeddirty:
295 ds.drop(f) 306 ds.drop(f)
296 307
297 repo.narrowpats = newincludes, newexcludes 308 repo.narrowpats = newincludes, newexcludes
298 repo._narrowmatch = newmatch 309 repo._narrowmatch = newmatch
299 pctx = repo['.'] 310 pctx = repo['.']