revert: distinguish between "check" and "backup" strategy
authorPierre-Yves David <pierre-yves.david@fb.com>
Sat, 30 Aug 2014 02:30:24 +0200
changeset 22609 3760ebf786b8
parent 22608 bf0ecb224316
child 22610 0f323ed8effd
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.
mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Sat Aug 30 02:28:27 2014 +0200
+++ b/mercurial/cmdutil.py	Sat Aug 30 02:30:24 2014 +0200
@@ -2629,10 +2629,12 @@
         # "constant" that convey the backup strategy.
         # All set to `discard` if `no-backup` is set do avoid checking
         # no_backup lower in the code.
+        # These values are ordered for comparison purposes
         backup = 2  # unconditionally do backup
+        check = 1   # check if the existing file differs from target
         discard = 0 # never do backup
         if opts.get('no_backup'):
-            backup = discard
+            backup = check = discard
 
         disptable = (
             # dispatch table:
@@ -2656,11 +2658,11 @@
             # Removed since  target, before working copy parent
             (removed,       actions['add'],      discard),
             # Same as `removed` but an unknown file exists at the same path
-            (removunk,      actions['add'],      backup),
+            (removunk,      actions['add'],      check),
             # Removed since targe, marked as such in working copy parent
             (dsremoved,     actions['undelete'], discard),
             # Same as `dsremoved` but an unknown file exists at the same path
-            (dsremovunk,    actions['undelete'], backup),
+            (dsremovunk,    actions['undelete'], check),
             ## the following sets does not result in any file changes
             # File with no modification
             (clean,         actions['noop'],     discard),
@@ -2683,12 +2685,13 @@
                     continue
                 if xlist is not None:
                     xlist.append(abs)
-                    if (dobackup and wctx[abs].cmp(ctx[abs])):
-                        bakname = "%s.orig" % rel
-                        ui.note(_('saving current version of %s as %s\n') %
-                                (rel, bakname))
-                        if not opts.get('dry_run'):
-                            util.rename(target, bakname)
+                    if dobackup and (backup <= dobackup
+                                     or wctx[abs].cmp(ctx[abs])):
+                            bakname = "%s.orig" % rel
+                            ui.note(_('saving current version of %s as %s\n') %
+                                    (rel, bakname))
+                            if not opts.get('dry_run'):
+                                util.rename(target, bakname)
                     if ui.verbose or not exact:
                         if not isinstance(msg, basestring):
                             msg = msg(abs)