changeset 36194:39b3aab6231e

revert: use an exact matcher in interactive diff selection (issue5789) When going through _performrevert() in the interactive case, we build a matcher with files to revert and pass it patch.diff() for later selection of diff hunks to revert. The files set used to build the matcher comes from dirstate and accounts for patterns explicitly passed to revert ('hg revert -i <file>') and, in case of nonexistent pattern, this set is empty (which is expected). Unfortunately, the matcher built from scmutil.match(ctx, []) is wrong as it leads patch.diff() to rebuild a 'changes' tuple with dirstate information, ignoring user-specified pattern. This leads to the situation described in issue5789, where one gets prompted about reverting files unrelated to specified patterns because they made a typo or so. We fix this by building an exact matcher with the correct set of file paths (built earlier). Thanks to Yuya Nishihara for suggesting the correct fix.
author Denis Laxalde <denis.laxalde@logilab.fr>
date Wed, 14 Feb 2018 14:12:05 +0100
parents a228b2f55ad6
children 513d268eddfe
files mercurial/cmdutil.py tests/test-revert-interactive.t
diffstat 2 files changed, 4 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Sun Feb 11 20:37:44 2018 +0100
+++ b/mercurial/cmdutil.py	Wed Feb 14 14:12:05 2018 +0100
@@ -2903,7 +2903,6 @@
     parent, p2 = parents
     node = ctx.node()
     excluded_files = []
-    matcher_opts = {"exclude": excluded_files}
 
     def checkout(f):
         fc = ctx[f]
@@ -2924,7 +2923,7 @@
             if choice == 0:
                 repo.dirstate.drop(f)
             else:
-                excluded_files.append(repo.wjoin(f))
+                excluded_files.append(f)
         else:
             repo.dirstate.drop(f)
     for f in actions['remove'][0]:
@@ -2935,7 +2934,7 @@
             if choice == 0:
                 doremove(f)
             else:
-                excluded_files.append(repo.wjoin(f))
+                excluded_files.append(f)
         else:
             doremove(f)
     for f in actions['drop'][0]:
@@ -2955,8 +2954,8 @@
     newlyaddedandmodifiedfiles = set()
     if interactive:
         # Prompt the user for changes to revert
-        torevert = [repo.wjoin(f) for f in actions['revert'][0]]
-        m = scmutil.match(ctx, torevert, matcher_opts)
+        torevert = [f for f in actions['revert'][0] if f not in excluded_files]
+        m = scmutil.matchfiles(repo, torevert)
         diffopts = patch.difffeatureopts(repo.ui, whitespace=True)
         diffopts.nodates = True
         diffopts.git = True
--- a/tests/test-revert-interactive.t	Sun Feb 11 20:37:44 2018 +0100
+++ b/tests/test-revert-interactive.t	Wed Feb 14 14:12:05 2018 +0100
@@ -428,9 +428,5 @@
   b: no such file in rev b40d1912accf
   $ hg rev -i b
   b: no such file in rev b40d1912accf
-  diff --git a/a b/a
-  1 hunks, 1 lines changed
-  examine changes to 'a'? [Ynesfdaq?] abort: response expected
-  [255]
 
   $ cd ..