comparison mercurial/cmdutil.py @ 22153:fc8bc2787528

revert: move manifest membership condition outside of the loop Currently, revset is using information from dirstate status and alter its behavior whenever the file exist in the target manifest or not. This tests are done a big for loop. We move this member ship testing outside of the loop and simplifies associates data structure. This is a step toward a cleaner implementation of revert based on status.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Tue, 24 Jun 2014 15:28:22 +0100
parents de5cee8ba088
children fc422de25773
comparison
equal deleted inserted replaced
22152:d2a5986cb89d 22153:fc8bc2787528
2384 def removeforget(abs): 2384 def removeforget(abs):
2385 if repo.dirstate[abs] == 'a': 2385 if repo.dirstate[abs] == 'a':
2386 return _('forgetting %s\n') 2386 return _('forgetting %s\n')
2387 return _('removing %s\n') 2387 return _('removing %s\n')
2388 2388
2389 # split between files known in target manifest and the others
2390 smf = set(mf)
2391
2392 missingmodified = modified - smf
2393 modified -= missingmodified
2394 missingadded = added - smf
2395 added -= missingadded
2396 missingremoved = removed - smf
2397 removed -= missingremoved
2398 missingdeleted = deleted - smf
2399 deleted -= missingdeleted
2400
2389 # action to be actually performed by revert 2401 # action to be actually performed by revert
2390 # (<list of file>, message>) tuple 2402 # (<list of file>, message>) tuple
2391 actions = {'revert': ([], _('reverting %s\n')), 2403 actions = {'revert': ([], _('reverting %s\n')),
2392 'add': ([], _('adding %s\n')), 2404 'add': ([], _('adding %s\n')),
2393 'remove': ([], removeforget), 2405 'remove': ([], removeforget),
2394 'undelete': ([], _('undeleting %s\n'))} 2406 'undelete': ([], _('undeleting %s\n'))}
2395 2407
2396 disptable = ( 2408 disptable = (
2397 # dispatch table: 2409 # dispatch table:
2398 # file state 2410 # file state
2399 # action if in target manifest 2411 # action
2400 # action if not in target manifest 2412 # make backup
2401 # make backup if in target manifest 2413 (modified, (actions['revert'], True)),
2402 # make backup if not in target manifest 2414 (missingmodified, (actions['remove'], True)),
2403 (modified, (actions['revert'], True), 2415 (added, (actions['revert'], True)),
2404 (actions['remove'], True)), 2416 (missingadded, (actions['remove'], False)),
2405 (added, (actions['revert'], True), 2417 (removed, (actions['undelete'], True)),
2406 (actions['remove'], False)), 2418 (missingremoved, (None, False)),
2407 (removed, (actions['undelete'], True), 2419 (deleted, (actions['revert'], False)),
2408 (None, False)), 2420 (missingdeleted, (actions['remove'], False)),
2409 (deleted, (actions['revert'], False),
2410 (actions['remove'], False)),
2411 ) 2421 )
2412 2422
2413 for abs, (rel, exact) in sorted(names.items()): 2423 for abs, (rel, exact) in sorted(names.items()):
2414 # hash on file in target manifest (or None if missing from target) 2424 # hash on file in target manifest (or None if missing from target)
2415 mfentry = mf.get(abs) 2425 mfentry = mf.get(abs)
2431 msg = msg(abs) 2441 msg = msg(abs)
2432 ui.status(msg % rel) 2442 ui.status(msg % rel)
2433 # search the entry in the dispatch table. 2443 # search the entry in the dispatch table.
2434 # if the file is in any of this sets, it was touched in the working 2444 # if the file is in any of this sets, it was touched in the working
2435 # directory parent and we are sure it needs to be reverted. 2445 # directory parent and we are sure it needs to be reverted.
2436 for table, hit, miss in disptable: 2446 for table, (action, backup) in disptable:
2437 if abs not in table: 2447 if abs not in table:
2438 continue 2448 continue
2439 # file has changed in dirstate 2449 if action is not None:
2440 if mfentry: 2450 handle(action, backup)
2441 handle(*hit)
2442 elif miss[0] is not None:
2443 handle(*miss)
2444 break 2451 break
2445 else: 2452 else:
2446 # Not touched in current dirstate. 2453 # Not touched in current dirstate.
2447 2454
2448 # file is unknown in parent, restore older version or ignore. 2455 # file is unknown in parent, restore older version or ignore.