# HG changeset patch # User Pierre-Yves David # Date 2014-08-30 00:30:24 # Node ID 3760ebf786b84ab2d9fc4108d14333c3ec3fedfc # Parent bf0ecb2243162f1fde972e1c5d63f1821048f04c 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. diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -2629,10 +2629,12 @@ def revert(ui, repo, ctx, parents, *pats # "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 @@ def revert(ui, repo, ctx, parents, *pats # 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 @@ def revert(ui, repo, ctx, parents, *pats 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)