Patchwork D9118: changing-files: add a "salvaged" set to track file that were not removed

login
register
mail settings
Submitter phabricator
Date Sept. 29, 2020, 10:37 a.m.
Message ID <differential-rev-PHID-DREV-zb6bklta3lw5e775frkt-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47333/
State Superseded
Headers show

Comments

phabricator - Sept. 29, 2020, 10:37 a.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We need this set for the copy tracing algorithm. See documentation for details
  about this set.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9118

AFFECTED FILES
  mercurial/metadata.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/metadata.py b/mercurial/metadata.py
--- a/mercurial/metadata.py
+++ b/mercurial/metadata.py
@@ -31,6 +31,7 @@ 
     - added:   files actively added in the changeset.
     - merged:  files whose history got merged
     - removed: files removed in the revision
+    - salvaged: files that might have been deleted by a merge but were not
     - touched: files affected by the merge
 
     and copies information is held by 2 mappings
@@ -47,6 +48,7 @@ 
         added=None,
         removed=None,
         merged=None,
+        salvaged=None,
         p1_copies=None,
         p2_copies=None,
     ):
@@ -54,6 +56,7 @@ 
         self._merged = set(() if merged is None else merged)
         self._removed = set(() if removed is None else removed)
         self._touched = set(() if touched is None else touched)
+        self._salvaged = set(() if touched is None else touched)
         self._touched.update(self._added)
         self._touched.update(self._merged)
         self._touched.update(self._removed)
@@ -65,6 +68,7 @@ 
             self.added == other.added
             and self.merged == other.merged
             and self.removed == other.removed
+            and self.salvaged == other.salvaged
             and self.touched == other.touched
             and self.copied_from_p1 == other.copied_from_p1
             and self.copied_from_p2 == other.copied_from_p2
@@ -160,6 +164,27 @@ 
             self.mark_removed(f)
 
     @util.propertycache
+    def salvaged(self):
+        """files that might had been deleted by a merge, but were not
+
+        During a merge, the manifest merging might select some file for
+        removal, or for a removed/changed conflict. If at commit time the file
+        still exist in the final result. It the removal is "reverted" and the
+        file is "salvaged"
+        """
+        return frozenset(self._salvaged)
+
+    def mark_salvaged(self, filename):
+        if "salvaged" in vars(self):
+            del self.salvaged
+        self.mark_salvaged(filename)
+        self._salvaged.add(filename)
+
+    def update_salvaged(self, filenames):
+        for f in filenames:
+            self.mark_salvaged(f)
+
+    @property
     def touched(self):
         """files either actively modified, added or removed"""
         return frozenset(self._touched)