Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 22609:3760ebf786b8
revert: distinguish between "check" and "backup" strategy
"check" behaves as backup did before. We check if the current file differs
from destination and we create a backup if it does. This is used for untracked
files that will be overwritten by formerly-deleted files. We have to do the manual
check since no status output can provide the content comparison.
"backup" is now doing unconditional backup. This can be used for files seen as
modified compared to both the target and the working directory. In such a case, we
know that the file differs from target without actually comparing any content.
This new "backup" strategy will be especially useful in the case of files added
between the target and the working directory -parent- with additional modifications
in the working directory -itself-. In that case we know we need to back it up, but we
cannot run the content check as the files does not exists in target.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Sat, 30 Aug 2014 02:30:24 +0200 |
parents | bf0ecb224316 |
children | 0f323ed8effd |
comparison
equal
deleted
inserted
replaced
22608:bf0ecb224316 | 22609:3760ebf786b8 |
---|---|
2627 } | 2627 } |
2628 | 2628 |
2629 # "constant" that convey the backup strategy. | 2629 # "constant" that convey the backup strategy. |
2630 # All set to `discard` if `no-backup` is set do avoid checking | 2630 # All set to `discard` if `no-backup` is set do avoid checking |
2631 # no_backup lower in the code. | 2631 # no_backup lower in the code. |
2632 # These values are ordered for comparison purposes | |
2632 backup = 2 # unconditionally do backup | 2633 backup = 2 # unconditionally do backup |
2634 check = 1 # check if the existing file differs from target | |
2633 discard = 0 # never do backup | 2635 discard = 0 # never do backup |
2634 if opts.get('no_backup'): | 2636 if opts.get('no_backup'): |
2635 backup = discard | 2637 backup = check = discard |
2636 | 2638 |
2637 disptable = ( | 2639 disptable = ( |
2638 # dispatch table: | 2640 # dispatch table: |
2639 # file state | 2641 # file state |
2640 # action | 2642 # action |
2654 # Added since target but file is missing in working directory | 2656 # Added since target but file is missing in working directory |
2655 (deladded, actions['drop'], discard), | 2657 (deladded, actions['drop'], discard), |
2656 # Removed since target, before working copy parent | 2658 # Removed since target, before working copy parent |
2657 (removed, actions['add'], discard), | 2659 (removed, actions['add'], discard), |
2658 # Same as `removed` but an unknown file exists at the same path | 2660 # Same as `removed` but an unknown file exists at the same path |
2659 (removunk, actions['add'], backup), | 2661 (removunk, actions['add'], check), |
2660 # Removed since targe, marked as such in working copy parent | 2662 # Removed since targe, marked as such in working copy parent |
2661 (dsremoved, actions['undelete'], discard), | 2663 (dsremoved, actions['undelete'], discard), |
2662 # Same as `dsremoved` but an unknown file exists at the same path | 2664 # Same as `dsremoved` but an unknown file exists at the same path |
2663 (dsremovunk, actions['undelete'], backup), | 2665 (dsremovunk, actions['undelete'], check), |
2664 ## the following sets does not result in any file changes | 2666 ## the following sets does not result in any file changes |
2665 # File with no modification | 2667 # File with no modification |
2666 (clean, actions['noop'], discard), | 2668 (clean, actions['noop'], discard), |
2667 # Existing file, not tracked anywhere | 2669 # Existing file, not tracked anywhere |
2668 (unknown, actions['unknown'], discard), | 2670 (unknown, actions['unknown'], discard), |
2681 for table, (xlist, msg), dobackup in disptable: | 2683 for table, (xlist, msg), dobackup in disptable: |
2682 if abs not in table: | 2684 if abs not in table: |
2683 continue | 2685 continue |
2684 if xlist is not None: | 2686 if xlist is not None: |
2685 xlist.append(abs) | 2687 xlist.append(abs) |
2686 if (dobackup and wctx[abs].cmp(ctx[abs])): | 2688 if dobackup and (backup <= dobackup |
2687 bakname = "%s.orig" % rel | 2689 or wctx[abs].cmp(ctx[abs])): |
2688 ui.note(_('saving current version of %s as %s\n') % | 2690 bakname = "%s.orig" % rel |
2689 (rel, bakname)) | 2691 ui.note(_('saving current version of %s as %s\n') % |
2690 if not opts.get('dry_run'): | 2692 (rel, bakname)) |
2691 util.rename(target, bakname) | 2693 if not opts.get('dry_run'): |
2694 util.rename(target, bakname) | |
2692 if ui.verbose or not exact: | 2695 if ui.verbose or not exact: |
2693 if not isinstance(msg, basestring): | 2696 if not isinstance(msg, basestring): |
2694 msg = msg(abs) | 2697 msg = msg(abs) |
2695 ui.status(msg % rel) | 2698 ui.status(msg % rel) |
2696 elif exact: | 2699 elif exact: |