comparison mercurial/cmdutil.py @ 22185:afead12e724b

revert: triage "deleted" files into more appropriate categories Status can return file as "deleted". This is only a special case related to working directory state: file is recorded as tracked but no file exists on disk. This will never be a state obtainable from manifest comparisons. "Deleted" files have another working directory status shadowed by the lack of file. They will -alway- be touched by revert. The "lack of file" can be seen as a modification. The file will never match the same "content" as in the revert target. From there we have two options: 1. The file exists in the target and can be seen as "modified". 2. The file does not exist in the target and can be seen as "added". So now we just dispatch elements from delete into appropriate categories.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Fri, 01 Aug 2014 18:57:53 -0700
parents d3702a822241
children a89bc7833e0d
comparison
equal deleted inserted replaced
22184:fb8065de47b0 22185:afead12e724b
2378 2378
2379 changes = repo.status(node1=node, match=m, clean=True) 2379 changes = repo.status(node1=node, match=m, clean=True)
2380 modified = set(changes[0]) 2380 modified = set(changes[0])
2381 added = set(changes[1]) 2381 added = set(changes[1])
2382 removed = set(changes[2]) 2382 removed = set(changes[2])
2383 deleted = set(changes[3]) 2383 _deleted = set(changes[3])
2384
2385 # split between files known in target manifest and the others
2386 smf = set(mf)
2387
2388 # determine the exact nature of the deleted changesets
2389 _deletedadded = _deleted - smf
2390 _deletedmodified = _deleted - _deletedadded
2391 added |= _deletedadded
2392 modified |= _deletedmodified
2384 2393
2385 # We need to account for the state of file in the dirstate 2394 # We need to account for the state of file in the dirstate
2386 # 2395 #
2387 # Even, when we revert agains something else than parent. this will 2396 # Even, when we revert agains something else than parent. this will
2388 # slightly alter the behavior of revert (doing back up or not, delete 2397 # slightly alter the behavior of revert (doing back up or not, delete
2395 else: 2404 else:
2396 changes = repo.status(node1=parent, match=m) 2405 changes = repo.status(node1=parent, match=m)
2397 dsmodified = set(changes[0]) 2406 dsmodified = set(changes[0])
2398 dsadded = set(changes[1]) 2407 dsadded = set(changes[1])
2399 dsremoved = set(changes[2]) 2408 dsremoved = set(changes[2])
2409 dsadded |= _deletedadded
2410 dsmodified |= _deletedmodified
2400 2411
2401 # if f is a rename, update `names` to also revert the source 2412 # if f is a rename, update `names` to also revert the source
2402 cwd = repo.getcwd() 2413 cwd = repo.getcwd()
2403 for f in dsadded: 2414 for f in dsadded:
2404 src = repo.dirstate.copied(f) 2415 src = repo.dirstate.copied(f)
2411 def removeforget(abs): 2422 def removeforget(abs):
2412 if repo.dirstate[abs] == 'a': 2423 if repo.dirstate[abs] == 'a':
2413 return _('forgetting %s\n') 2424 return _('forgetting %s\n')
2414 return _('removing %s\n') 2425 return _('removing %s\n')
2415 2426
2416 # split between files known in target manifest and the others
2417 smf = set(mf)
2418
2419 missingmodified = dsmodified - smf 2427 missingmodified = dsmodified - smf
2420 dsmodified -= missingmodified 2428 dsmodified -= missingmodified
2421 missingadded = dsadded - smf 2429 missingadded = dsadded - smf
2422 dsadded -= missingadded 2430 dsadded -= missingadded
2423 missingremoved = dsremoved - smf 2431 missingremoved = dsremoved - smf
2424 dsremoved -= missingremoved 2432 dsremoved -= missingremoved
2425 missingdeleted = deleted - smf
2426 deleted -= missingdeleted
2427 2433
2428 # action to be actually performed by revert 2434 # action to be actually performed by revert
2429 # (<list of file>, message>) tuple 2435 # (<list of file>, message>) tuple
2430 actions = {'revert': ([], _('reverting %s\n')), 2436 actions = {'revert': ([], _('reverting %s\n')),
2431 'add': ([], _('adding %s\n')), 2437 'add': ([], _('adding %s\n')),
2441 (missingmodified, (actions['remove'], True)), 2447 (missingmodified, (actions['remove'], True)),
2442 (dsadded, (actions['revert'], True)), 2448 (dsadded, (actions['revert'], True)),
2443 (missingadded, (actions['remove'], False)), 2449 (missingadded, (actions['remove'], False)),
2444 (dsremoved, (actions['undelete'], True)), 2450 (dsremoved, (actions['undelete'], True)),
2445 (missingremoved, (None, False)), 2451 (missingremoved, (None, False)),
2446 (deleted, (actions['revert'], False)),
2447 (missingdeleted, (actions['remove'], False)),
2448 ) 2452 )
2449 2453
2450 for abs, (rel, exact) in sorted(names.items()): 2454 for abs, (rel, exact) in sorted(names.items()):
2451 # hash on file in target manifest (or None if missing from target) 2455 # hash on file in target manifest (or None if missing from target)
2452 mfentry = mf.get(abs) 2456 mfentry = mf.get(abs)