comparison mercurial/cmdutil.py @ 22489:0d57bf80c7cb

revert: have an explicit action for "forget" The distinction between "remove" and "forget" used to be in special logic checking for the state of the file in the dirstate. Now that we have dedicated filtering, we can stop relying on this logic and have two distinct actions.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Mon, 01 Sep 2014 12:36:48 +0200
parents 6c52ed3f888e
children bcab7bc7280e
comparison
equal deleted inserted replaced
22488:6c52ed3f888e 22489:0d57bf80c7cb
2602 target = repo.wjoin(abs) 2602 target = repo.wjoin(abs)
2603 if os.path.lexists(target): 2603 if os.path.lexists(target):
2604 dsremovunk.add(abs) 2604 dsremovunk.add(abs)
2605 dsremoved -= dsremovunk 2605 dsremoved -= dsremovunk
2606 2606
2607 ## computation of the action to performs on `names` content.
2608
2609 def removeforget(abs):
2610 if repo.dirstate[abs] == 'a':
2611 return _('forgetting %s\n')
2612 return _('removing %s\n')
2613
2614 # action to be actually performed by revert 2607 # action to be actually performed by revert
2615 # (<list of file>, message>) tuple 2608 # (<list of file>, message>) tuple
2616 actions = {'revert': ([], _('reverting %s\n')), 2609 actions = {'revert': ([], _('reverting %s\n')),
2617 'add': ([], _('adding %s\n')), 2610 'add': ([], _('adding %s\n')),
2618 'remove': ([], removeforget), 2611 'remove': ([], _('removing %s\n')),
2612 'forget': ([], _('forgetting %s\n')),
2619 'undelete': ([], _('undeleting %s\n')), 2613 'undelete': ([], _('undeleting %s\n')),
2620 'noop': (None, _('no changes needed to %s\n')), 2614 'noop': (None, _('no changes needed to %s\n')),
2621 'unknown': (None, _('file not managed: %s\n')), 2615 'unknown': (None, _('file not managed: %s\n')),
2622 } 2616 }
2623 2617
2640 # Modified compared to target, local change 2634 # Modified compared to target, local change
2641 (dsmodified, actions['revert'], backup), 2635 (dsmodified, actions['revert'], backup),
2642 # Added since target 2636 # Added since target
2643 (added, actions['remove'], discard), 2637 (added, actions['remove'], discard),
2644 # Added in working directory 2638 # Added in working directory
2645 (dsadded, actions['remove'], discard), 2639 (dsadded, actions['forget'], discard),
2646 # Removed since target, before working copy parent 2640 # Removed since target, before working copy parent
2647 (removed, actions['add'], discard), 2641 (removed, actions['add'], discard),
2648 # Same as `removed` but an unknown file exists at the same path 2642 # Same as `removed` but an unknown file exists at the same path
2649 (removunk, actions['add'], backup), 2643 (removunk, actions['add'], backup),
2650 # Removed since targe, marked as such in working copy parent 2644 # Removed since targe, marked as such in working copy parent
2715 def checkout(f): 2709 def checkout(f):
2716 fc = ctx[f] 2710 fc = ctx[f]
2717 repo.wwrite(f, fc.data(), fc.flags()) 2711 repo.wwrite(f, fc.data(), fc.flags())
2718 2712
2719 audit_path = pathutil.pathauditor(repo.root) 2713 audit_path = pathutil.pathauditor(repo.root)
2714 for f in actions['forget'][0]:
2715 repo.dirstate.drop(f)
2720 for f in actions['remove'][0]: 2716 for f in actions['remove'][0]:
2721 if repo.dirstate[f] == 'a':
2722 repo.dirstate.drop(f)
2723 continue
2724 audit_path(f) 2717 audit_path(f)
2725 try: 2718 try:
2726 util.unlinkpath(repo.wjoin(f)) 2719 util.unlinkpath(repo.wjoin(f))
2727 except OSError: 2720 except OSError:
2728 pass 2721 pass