comparison mercurial/cmdutil.py @ 22611:2ff28e07d7d6

revert: properly back up added files with local modification These files were previously not backed up because the backup mechanism was not smart enough. This leads to data lose for the user since uncommitted contents were discarded. We now properly move the modified version to <filename>.orig before deleting it. We have to use a small hack to do a different action if "--no-backup" is specified. This is needed because the backup process is actually a move (not a copy) so the file is already missing when we backup. The internet kitten is a bit disapointed about that, but such is life. This patch concludes the "lets refactor revert" phases. We can now open the "Lets find stupid bug with renames and merge" phases. I'm sure that now that the code is clearer we could do it in another simpler way, but I consider the current improvement good enough for now.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Sun, 31 Aug 2014 13:01:00 +0200
parents 0f323ed8effd
children 1e2f54a149e8
comparison
equal deleted inserted replaced
22610:0f323ed8effd 22611:2ff28e07d7d6
2638 check = 1 # check if the existing file differs from target 2638 check = 1 # check if the existing file differs from target
2639 discard = 0 # never do backup 2639 discard = 0 # never do backup
2640 if opts.get('no_backup'): 2640 if opts.get('no_backup'):
2641 backup = check = discard 2641 backup = check = discard
2642 2642
2643 backupanddel = actions['remove']
2644 if not opts.get('no_backup'):
2645 backupanddel = actions['drop']
2646
2643 disptable = ( 2647 disptable = (
2644 # dispatch table: 2648 # dispatch table:
2645 # file state 2649 # file state
2646 # action 2650 # action
2647 # make backup 2651 # make backup
2656 # Added since target 2660 # Added since target
2657 (added, actions['remove'], discard), 2661 (added, actions['remove'], discard),
2658 # Added in working directory 2662 # Added in working directory
2659 (dsadded, actions['forget'], discard), 2663 (dsadded, actions['forget'], discard),
2660 # Added since target, have local modification 2664 # Added since target, have local modification
2661 (modadded, actions['remove'], discard), 2665 (modadded, backupanddel, backup),
2662 # Added since target but file is missing in working directory 2666 # Added since target but file is missing in working directory
2663 (deladded, actions['drop'], discard), 2667 (deladded, actions['drop'], discard),
2664 # Removed since target, before working copy parent 2668 # Removed since target, before working copy parent
2665 (removed, actions['add'], discard), 2669 (removed, actions['add'], discard),
2666 # Same as `removed` but an unknown file exists at the same path 2670 # Same as `removed` but an unknown file exists at the same path