Patchwork revert: fix --interactive on local modification (issue4576)

login
register
mail settings
Submitter Laurent Charignon
Date March 25, 2015, 11:09 p.m.
Message ID <3dbf2bb0b4df0c1bbdf0.1427324976@dev919.prn2.facebook.com>
Download mbox | patch
Permalink /patch/8270/
State Accepted
Headers show

Comments

Laurent Charignon - March 25, 2015, 11:09 p.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1427317274 25200
#      Wed Mar 25 14:01:14 2015 -0700
# Node ID 3dbf2bb0b4df0c1bbdf0ec8d9467290fce8fd797
# Parent  5b85a5bc5bbb9d8365953609d98e4dce7110e9b0
revert: fix --interactive on local modification (issue4576)

We were moving files during the backup phase and it was incompatible with the
way record/crecord is working
Matt Mackall - March 26, 2015, 10:37 p.m.
On Wed, 2015-03-25 at 16:09 -0700, Laurent Charignon wrote:
> # HG changeset patch
> # User Laurent Charignon <lcharignon@fb.com>
> # Date 1427317274 25200
> #      Wed Mar 25 14:01:14 2015 -0700
> # Node ID 3dbf2bb0b4df0c1bbdf0ec8d9467290fce8fd797
> # Parent  5b85a5bc5bbb9d8365953609d98e4dce7110e9b0
> revert: fix --interactive on local modification (issue4576)

Queued for default, thanks.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -3012,6 +3012,7 @@ 
             (unknown,       actions['unknown'],  discard),
             )
 
+        interactive = opts.get('interactive', False)
         wctx = repo[None]
         for abs, (rel, exact) in sorted(names.items()):
             # target file to be touch on disk (relative to cwd)
@@ -3030,7 +3031,10 @@ 
                             ui.note(_('saving current version of %s as %s\n') %
                                     (rel, bakname))
                             if not opts.get('dry_run'):
-                                util.rename(target, bakname)
+                                if interactive:
+                                    util.copyfile(target, bakname)
+                                else:
+                                    util.rename(target, bakname)
                     if ui.verbose or not exact:
                         if not isinstance(msg, basestring):
                             msg = msg(abs)
@@ -3043,7 +3047,6 @@ 
         if not opts.get('dry_run'):
             needdata = ('revert', 'add', 'undelete')
             _revertprefetch(repo, ctx, *[actions[name][0] for name in needdata])
-            interactive = opts.get('interactive', False)
             _performrevert(repo, parents, ctx, actions, interactive)
 
         # get the list of subrepos that must be reverted
diff --git a/tests/test-revert-interactive.t b/tests/test-revert-interactive.t
--- a/tests/test-revert-interactive.t
+++ b/tests/test-revert-interactive.t
@@ -205,3 +205,53 @@ 
   4
   5
   f
+  $ hg st
+  M f
+  M folder1/g
+  R folder1/i
+  $ hg revert --interactive f << EOF
+  > y
+  > y
+  > n
+  > n
+  > EOF
+  diff -r 59dd6e4ab63a f
+  2 hunks, 2 lines changed
+  examine changes to 'f'? [Ynesfdaq?] y
+  
+  @@ -1,5 +1,6 @@
+  +a
+   1
+   2
+   3
+   4
+   5
+  record change 1/2 to 'f'? [Ynesfdaq?] y
+  
+  @@ -1,5 +2,6 @@
+   1
+   2
+   3
+   4
+   5
+  +b
+  record change 2/2 to 'f'? [Ynesfdaq?] n
+  
+  $ hg st
+  M f
+  M folder1/g
+  R folder1/i
+  ? f.orig
+  $ cat f
+  a
+  1
+  2
+  3
+  4
+  5
+  $ cat f.orig
+  1
+  2
+  3
+  4
+  5