Patchwork D8887: mergeresult: add `files()` and use it

login
register
mail settings
Submitter phabricator
Date Aug. 5, 2020, 12:12 p.m.
Message ID <differential-rev-PHID-DREV-gsc3xab4yhzrgejcqcba-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46986/
State Superseded
Headers show

Comments

phabricator - Aug. 5, 2020, 12:12 p.m.
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  `files()` will return a list of files on which an action needs to be performed.
  
  This is a step to stop exposing the underlying map to the user of this object.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/largefiles/overrides.py
  mercurial/merge.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -151,11 +151,11 @@ 
                 warnconflicts.update(conflicts)
 
         checkunknowndirs = _unknowndirschecker()
-        for f, args, msg in mresult.getactions(
-            [
+        for f in mresult.files(
+            (
                 mergestatemod.ACTION_CREATED,
                 mergestatemod.ACTION_DELETED_CHANGED,
-            ]
+            )
         ):
             if _checkunknownfile(repo, wctx, mctx, f):
                 fileconflicts.add(f)
@@ -299,7 +299,7 @@ 
     if not narrowmatch.always():
         pmmf = set(wmf.walk(narrowmatch))
         if mresult:
-            for f, actionsfortype in pycompat.iteritems(mresult.actions):
+            for f in list(mresult.files()):
                 if not narrowmatch(f):
                     mresult.removefile(f)
     else:
@@ -308,7 +308,7 @@ 
 
     if mresult:
         # KEEP and EXEC are no-op
-        for f, args, msg in mresult.getactions(
+        for f in mresult.files(
             (
                 mergestatemod.ACTION_ADD,
                 mergestatemod.ACTION_ADD_MODIFIED,
@@ -319,7 +319,7 @@ 
             )
         ):
             pmmf.add(f)
-        for f, args, msg in mresult.getactions([mergestatemod.ACTION_REMOVE]):
+        for f in mresult.files((mergestatemod.ACTION_REMOVE,)):
             pmmf.discard(f)
         for f, args, msg in mresult.getactions(
             [mergestatemod.ACTION_DIR_RENAME_MOVE_LOCAL]
@@ -327,9 +327,7 @@ 
             f2, flags = args
             pmmf.discard(f2)
             pmmf.add(f)
-        for f, args, msg in mresult.getactions(
-            [mergestatemod.ACTION_LOCAL_DIR_RENAME_GET]
-        ):
+        for f in mresult.files((mergestatemod.ACTION_LOCAL_DIR_RENAME_GET,)):
             pmmf.add(f)
         for f, args, msg in mresult.getactions([mergestatemod.ACTION_MERGE]):
             f1, f2, fa, move, anc = args
@@ -414,7 +412,7 @@ 
     # The set of files deleted by all the actions.
     deletedfiles = set()
 
-    for (f, args, msg) in mresult.getactions(
+    for f in mresult.files(
         (
             mergestatemod.ACTION_CREATED,
             mergestatemod.ACTION_DELETED_CHANGED,
@@ -430,7 +428,7 @@ 
             # will be checked once we know what all the deleted files are.
             remoteconflicts.add(f)
     # Track the names of all deleted files.
-    for (f, args, msg) in mresult.getactions((mergestatemod.ACTION_REMOVE,)):
+    for f in mresult.files((mergestatemod.ACTION_REMOVE,)):
         deletedfiles.add(f)
     for (f, args, msg) in mresult.getactions((mergestatemod.ACTION_MERGE,)):
         f1, f2, fa, move, anc = args
@@ -470,7 +468,7 @@ 
     for p in localconflicts:
         if p not in deletedfiles:
             ctxname = bytes(wctx).rstrip(b'+')
-            pnew = util.safename(p, ctxname, wctx, set(mresult.actions.keys()))
+            pnew = util.safename(p, ctxname, wctx, set(mresult.files()))
             porig = wctx[p].copysource() or p
             mresult.addfile(
                 pnew,
@@ -491,9 +489,7 @@ 
         for f, p in _filesindirs(repo, mf, remoteconflicts):
             if f not in deletedfiles:
                 m, args, msg = mresult.getfile(p)
-                pnew = util.safename(
-                    p, ctxname, wctx, set(mresult.actions.keys())
-                )
+                pnew = util.safename(p, ctxname, wctx, set(mresult.files()))
                 if m in (
                     mergestatemod.ACTION_DELETED_CHANGED,
                     mergestatemod.ACTION_MERGE,
@@ -621,6 +617,22 @@ 
             return self._filemapping[filename]
         return default_return
 
+    def files(self, actions=None):
+        """ returns files on which provided action needs to perfromed
+
+        If actions is None, all files are returned
+        """
+        # TODO: think whether we should return renamedelete and
+        # diverge filenames also
+        if actions is None:
+            for f in self._filemapping:
+                yield f
+
+        else:
+            for a in actions:
+                for f in self._actionmapping[a]:
+                    yield f
+
     def removefile(self, filename):
         """ removes a file from the mergeresult object as the file might
         not merging anymore """
@@ -1029,18 +1041,14 @@ 
        remained the same."""
     # We force a copy of actions.items() because we're going to mutate
     # actions as we resolve trivial conflicts.
-    for f, args, msg in list(
-        mresult.getactions([mergestatemod.ACTION_CHANGED_DELETED])
-    ):
+    for f in list(mresult.files((mergestatemod.ACTION_CHANGED_DELETED,))):
         if f in ancestor and not wctx[f].cmp(ancestor[f]):
             # local did change but ended up with same content
             mresult.addfile(
                 f, mergestatemod.ACTION_REMOVE, None, b'prompt same'
             )
 
-    for f, args, msg in list(
-        mresult.getactions([mergestatemod.ACTION_DELETED_CHANGED])
-    ):
+    for f in list(mresult.files((mergestatemod.ACTION_DELETED_CHANGED,))):
         if f in ancestor and not mctx[f].cmp(ancestor[f]):
             # remote did change but ended up with same content
             mresult.removefile(f)  # don't get = keep local deleted
@@ -1304,16 +1312,14 @@ 
     # Skipping 'a', 'am', 'f', 'r', 'dm', 'e', 'k', 'p' and 'pr', because they
     # don't touch the context to be merged in.  'cd' is skipped, because
     # changed/deleted never resolves to something from the remote side.
-    files = []
-    for f, args, msg in mresult.getactions(
+    files = mresult.files(
         [
             mergestatemod.ACTION_GET,
             mergestatemod.ACTION_DELETED_CHANGED,
             mergestatemod.ACTION_LOCAL_DIR_RENAME_GET,
             mergestatemod.ACTION_MERGE,
         ]
-    ):
-        files.append(f)
+    )
 
     prefetch = scmutil.prefetchfiles
     matchfiles = scmutil.matchfiles
diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -562,7 +562,7 @@ 
 
     # Convert to dictionary with filename as key and action as value.
     lfiles = set()
-    for f in mresult.actions:
+    for f in mresult.files():
         splitstandin = lfutil.splitstandin(f)
         if splitstandin is not None and splitstandin in p1:
             lfiles.add(splitstandin)