[PATCH 1 of 4] revert: split between newly added file and file added in other changeset

Pierre-Yves David pierre-yves.david at ens-lyon.org
Wed Sep 10 19:29:56 UTC 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1409415629 -7200
#      Sat Aug 30 18:20:29 2014 +0200
# Node ID 7434032ec939ece17af8285121e19956a072dac2
# Parent  7bfda6350dc7cbc50204212a22ed198cb15097fb
revert: split between newly added file and file added in other changeset

These two kinds of files are handled differently. One is deleted and the other
is just forgotten (the file is untracked but left in place). The distinction is
done in the `_performrevert` code itself and we would like to get ride of this.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2453,24 +2453,13 @@ def revert(ui, repo, ctx, parents, *pats
             # tell newly modified apart.
             dsmodified &= modified
             dsmodified |= modified & dsadded # dirstate added may needs backup
             modified -= dsmodified
 
-            # There are three categories of added files
-            #
-            # 1. addition that just happened in the dirstate
-            #    (should be forgotten)
-            # 2. file is added since target revision and has local changes
-            #    (should be backed up and removed)
-            # 3. file is added since target revision and is clean
-            #    (should be removed)
-            #
-            # However we do not need to split them yet. The current revert code
-            # will automatically recognize (1) when performing operation. And
-            # the backup system is currently unabled to handle (2).
-            #
-            # So we just put them all in the same group.
+            # We need to wait for some post processing to update this set
+            # before making the disctinction. the dirstate will be used for
+            # that purpose.
             dsadded = added
 
         # in case of merge, files that are actually added can be reported as
         # modified, we need to post process the result
         if p2 != nullid:
@@ -2489,10 +2478,17 @@ def revert(ui, repo, ctx, parents, *pats
             # XXX should we check for rename down to target node?
             if src and src not in names and repo.dirstate[src] == 'r':
                 dsremoved.add(src)
                 names[src] = (repo.pathto(src, cwd), True)
 
+        # distinct between file to forget and the other
+        added = set()
+        for abs in dsadded:
+            if repo.dirstate[abs] != 'a':
+                added.add(abs)
+        dsadded -= added
+
         # 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()
@@ -2543,10 +2539,12 @@ def revert(ui, repo, ctx, parents, *pats
             # Modified compared to target, but local file is deleted
             (deleted,       actions['revert'],   discard),
             # Modified compared to target, local change
             (dsmodified,    actions['revert'],   backup),
             # Added since target
+            (added,         actions['remove'],   discard),
+            # Added in working directory
             (dsadded,       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),



More information about the Mercurial-devel mailing list