diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py index bf0ecb2243162f1fde972e1c5d63f1821048f04c_bWVyY3VyaWFsL2NtZHV0aWwucHk=..3760ebf786b84ab2d9fc4108d14333c3ec3fedfc_bWVyY3VyaWFsL2NtZHV0aWwucHk= 100644 --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -2629,4 +2629,5 @@ # "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 @@ -2632,3 +2633,4 @@ 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'): @@ -2633,6 +2635,6 @@ discard = 0 # never do backup if opts.get('no_backup'): - backup = discard + backup = check = discard disptable = ( # dispatch table: @@ -2656,7 +2658,7 @@ # 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 @@ -2660,7 +2662,7 @@ # 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)