Patchwork [6,of,6] revert: use modified information from both status

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 14, 2014, 9:36 p.m.
Message ID <7feb3dcb531e721c313d.1408052160@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5399/
State Accepted
Headers show

Comments

Pierre-Yves David - Aug. 14, 2014, 9:36 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1403627238 -3600
#      Tue Jun 24 17:27:18 2014 +0100
# Node ID 7feb3dcb531e721c313d1a5a9572556adfc94e8c
# Parent  cb437f41f3d1523b2a56791a3694434d037c1fff
revert: use modified information from both status

Using status information against the target make sure we are catching all
files with modification that needs revert.

We still need to distinguish fresh modification for backup purpose.

test-largefile is affected because it reverted a file that needs no content
change.
Matt Mackall - Aug. 15, 2014, 4:03 p.m.
On Thu, 2014-08-14 at 14:36 -0700, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1403627238 -3600
> #      Tue Jun 24 17:27:18 2014 +0100
> # Node ID 7feb3dcb531e721c313d1a5a9572556adfc94e8c
> # Parent  cb437f41f3d1523b2a56791a3694434d037c1fff
> revert: use modified information from both status

These are queued for default, thanks. I fixed up the unshelve revert
output noise with ui.push/popbuffer and dropped that piece.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2399,18 +2399,22 @@  def revert(ui, repo, ctx, parents, *pats
             changes = repo.status(node1=parent, match=m)
             dsmodified = set(changes[0])
             dsadded    = set(changes[1])
             dsremoved  = set(changes[2])
             dsadded |= _deletedadded
-            dsmodified |= _deletedmodified
 
             # only take in account for remove that between wc and target.
             clean |= dsremoved - removed
             dsremoved &= removed
             # distinct between dirstate remove and other
             removed -= dsremoved
 
+            # tell newly modified appart.
+            dsmodified &= modified
+            dsmodified |= modified & dsadded # dirstate added may needs backup
+            modified -= dsmodified
+
         # if f is a rename, update `names` to also revert the source
         cwd = repo.getcwd()
         for f in dsadded:
             src = repo.dirstate.copied(f)
             if src and src not in names and repo.dirstate[src] == 'r':
@@ -2439,10 +2443,11 @@  def revert(ui, repo, ctx, parents, *pats
         disptable = (
             # dispatch table:
             #   file state
             #   action
             #   make backup
+            (modified,         (actions['revert'],   False)),
             (dsmodified,       (actions['revert'],   True)),
             (missingmodified,  (actions['remove'],   True)),
             (dsadded,          (actions['revert'],   True)),
             (missingadded,     (actions['remove'],   False)),
             (removed,          (actions['add'],      True)),
diff --git a/tests/test-largefiles.t b/tests/test-largefiles.t
--- a/tests/test-largefiles.t
+++ b/tests/test-largefiles.t
@@ -1303,11 +1303,10 @@  revert some files to an older revision
   $ hg revert --no-backup -r 8 sub2
   reverting .hglf/sub2/large6 (glob)
   $ cat sub2/large6
   large6
   $ hg revert --no-backup -C -r '.^' sub2
-  reverting .hglf/sub2/large6 (glob)
   $ hg revert --no-backup sub2
   reverting .hglf/sub2/large6 (glob)
   $ hg status
 
 "verify --large" actually verifies largefiles
diff --git a/tests/test-revert.t b/tests/test-revert.t
--- a/tests/test-revert.t
+++ b/tests/test-revert.t
@@ -910,11 +910,10 @@  check revert output
 
 Misbehavior:
 
 - report "reverting" when file needs no changes
 |
-| - reverting modified_revert
 | - reverting removed_revert
 
   $ hg revert --all --rev 'desc(base)'
   removing added_clean
   removing added_deleted
@@ -928,11 +927,10 @@  Misbehavior:
   forgetting missing_deleted
   forgetting missing_wc
   reverting modified_clean
   reverting modified_deleted
   undeleting modified_removed
-  reverting modified_revert
   undeleting modified_untracked-clean
   undeleting modified_untracked-revert
   undeleting modified_untracked-wc
   reverting modified_wc
   adding removed_clean
@@ -1102,11 +1100,10 @@  revert all files individually and check 
 
 Misbehavior:
 
 - fails to report no change to revert for
 |
-| - modified_revert
 | - removed_revert
 
   $ for file in `python ../gen-revert-cases.py filelist`; do
   >   echo '### revert for:' $file;
   >   hg revert $file --rev 'desc(base)';
@@ -1178,10 +1175,11 @@  Misbehavior:
   ### revert for: modified_deleted
   
   ### revert for: modified_removed
   
   ### revert for: modified_revert
+  no changes needed to modified_revert
   
   ### revert for: modified_untracked-clean
   
   ### revert for: modified_untracked-revert