Patchwork D12117: merge-actions: have an attribute for narrow safetiness

login
register
mail settings
Submitter phabricator
Date Jan. 30, 2022, 8:15 p.m.
Message ID <differential-rev-PHID-DREV-lhq5q4xsl3y42aztns2q-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50444/
State New
Headers show

Comments

phabricator - Jan. 30, 2022, 8:15 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This allow the core doing narrow filtering to process action without
  explicitely listing all possible actions. This is important to make the actions
  system more flexible in the future.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/merge.py
  mercurial/mergestate.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/mergestate.py b/mercurial/mergestate.py
--- a/mercurial/mergestate.py
+++ b/mercurial/mergestate.py
@@ -107,17 +107,22 @@ 
     _short: internal representation used to identify each action
 
     no_op:  True if the action does affect the file content or tracking status
+
+    narrow_safe:
+        True if the action can be safely used for a file outside of the narrow
+        set
     """
 
     ALL_ACTIONS = weakref.WeakSet()
     NO_OP_ACTIONS = weakref.WeakSet()
 
-    def __init__(self, short, no_op=False):
+    def __init__(self, short, no_op=False, narrow_safe=False):
         self._short = short
         self.ALL_ACTIONS.add(self)
         self.no_op = no_op
         if self.no_op:
             self.NO_OP_ACTIONS.add(self)
+        self.narrow_safe = narrow_safe
 
     def __hash__(self):
         return hash(self._short)
@@ -138,14 +143,14 @@ 
         return self._short < other._short
 
 
-ACTION_FORGET = MergeAction(b'f')
-ACTION_REMOVE = MergeAction(b'r')
-ACTION_ADD = MergeAction(b'a')
-ACTION_GET = MergeAction(b'g')
+ACTION_FORGET = MergeAction(b'f', narrow_safe=True)
+ACTION_REMOVE = MergeAction(b'r', narrow_safe=True)
+ACTION_ADD = MergeAction(b'a', narrow_safe=True)
+ACTION_GET = MergeAction(b'g', narrow_safe=True)
 ACTION_PATH_CONFLICT = MergeAction(b'p')
 ACTION_PATH_CONFLICT_RESOLVE = MergeAction('pr')
-ACTION_ADD_MODIFIED = MergeAction(b'am')
-ACTION_CREATED = MergeAction(b'c')
+ACTION_ADD_MODIFIED = MergeAction(b'am', narrow_safe=True)
+ACTION_CREATED = MergeAction(b'c', narrow_safe=True)
 ACTION_DELETED_CHANGED = MergeAction(b'dc')
 ACTION_CHANGED_DELETED = MergeAction(b'cd')
 ACTION_MERGE = MergeAction(b'm')
@@ -159,8 +164,8 @@ 
 # the file is absent on the ancestor and remote side of the merge
 # hence this file is new and we should keep it
 ACTION_KEEP_NEW = MergeAction(b'kn', no_op=True)
-ACTION_EXEC = MergeAction(b'e')
-ACTION_CREATED_MERGE = MergeAction(b'cm')
+ACTION_EXEC = MergeAction(b'e', narrow_safe=True)
+ACTION_CREATED_MERGE = MergeAction(b'cm', narrow_safe=True)
 
 
 # Used by concert to detect situation it does not like, not sure what the exact
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -509,17 +509,6 @@ 
     Raise an exception if the merge cannot be completed because the repo is
     narrowed.
     """
-    # TODO: handle with nonconflicttypes
-    nonconflicttypes = {
-        mergestatemod.ACTION_ADD,
-        mergestatemod.ACTION_ADD_MODIFIED,
-        mergestatemod.ACTION_CREATED,
-        mergestatemod.ACTION_CREATED_MERGE,
-        mergestatemod.ACTION_FORGET,
-        mergestatemod.ACTION_GET,
-        mergestatemod.ACTION_REMOVE,
-        mergestatemod.ACTION_EXEC,
-    }
     # We mutate the items in the dict during iteration, so iterate
     # over a copy.
     for f, action in mresult.filemap():
@@ -529,7 +518,7 @@ 
             mresult.removefile(f)  # just updating, ignore changes outside clone
         elif action[0].no_op:
             mresult.removefile(f)  # merge does not affect file
-        elif action[0] in nonconflicttypes:
+        elif action[0].narrow_safe:  # TODO: handle these cases
             msg = _(
                 b'merge affects file \'%s\' outside narrow, '
                 b'which is not yet supported'