Patchwork [3,of,4] revert: explicitly track added but deleted file

login
register
mail settings
Submitter Pierre-Yves David
Date Sept. 10, 2014, 7:29 p.m.
Message ID <84ecfe0c320d1ee0eff3.1410377398@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5775/
State Accepted
Headers show

Comments

Pierre-Yves David - Sept. 10, 2014, 7:29 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1409358205 -7200
#      Sat Aug 30 02:23:25 2014 +0200
# Node ID 84ecfe0c320d1ee0eff3d98074b57b3d168ff9e7
# Parent  a53d6ad8083f8cb699b18cdb8cda6665f756f424
revert: explicitly track added but deleted file

Added + deleted file are file that needs to be untracked from the dirstate but
that are already missing on disk. The current `_performrevert` code is handling
that with exception catching. We will be able to do better with a dedicated set.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2422,13 +2422,12 @@  def revert(ui, repo, ctx, parents, *pats
 
         # split between files known in target manifest and the others
         smf = set(mf)
 
         # determine the exact nature of the deleted changesets
-        _deletedadded = _deleted - smf
-        deleted = _deleted - _deletedadded
-        added |= _deletedadded
+        deladded = _deleted - smf
+        deleted = _deleted - deladded
 
         # We need to account for the state of file in the dirstate
         #
         # Even, when we revert agains something else than parent. this will
         # slightly alter the behavior of revert (doing back up or not, delete
@@ -2485,10 +2484,15 @@  def revert(ui, repo, ctx, parents, *pats
         for abs in dsadded:
             if repo.dirstate[abs] != 'a':
                 added.add(abs)
         dsadded -= added
 
+        for abs in deladded:
+            if repo.dirstate[abs] == 'a':
+                dsadded.add(abs)
+        deladded -= dsadded
+
         # For files marked as removed, we check if an unknown file is present at
         # the same path. If a such file exists it may need to be backed up.
         # Making the distinction at that stage helps having a simpler backup
         # logic.
         removunk = set()
@@ -2536,10 +2540,12 @@  def revert(ui, repo, ctx, parents, *pats
             (dsmodified,    actions['revert'],   backup),
             # Added since target
             (added,         actions['remove'],   discard),
             # Added in working directory
             (dsadded,       actions['forget'],   discard),
+            # Added since target but file is missing in working directory
+            (deladded,      actions['remove'],   discard),
             # Removed since  target, before working copy parent
             (removed,       actions['add'],      discard),
             # Same as `removed` but an unknown file exist at the same path
             (removunk,      actions['add'],      backup),
             # Removed since targe, marked as such in working copy parent