[Updated] D8887: mergeresult: add `files()` and use it

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Sat Aug 8 16:57:35 UTC 2020


Closed by commit rHGe5b4061f32be: mergeresult: add `files()` and use it (authored by pulkit).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8887?vs=22308&id=22345

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8887/new/

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

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

CHANGE DETAILS

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)



To: pulkit, #hg-reviewers, indygreg
Cc: indygreg, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20200808/c275bbe8/attachment-0002.html>


More information about the Mercurial-patches mailing list