Patchwork D8828: sparse: pass mergeresult obj in sparse.filterupdatesactions() (API)

login
register
mail settings
Submitter phabricator
Date July 25, 2020, 10:02 a.m.
Message ID <differential-rev-PHID-DREV-or4eep3yfaddojciemlc-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46899/
State Superseded
Headers show

Comments

phabricator - July 25, 2020, 10:02 a.m.
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Not able to see much which can be improved in this function by passing in
  mergeresult object but for API consistency and no function directly touching
  actions dict, it sounds like a good idea.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/merge.py
  mercurial/sparse.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/sparse.py b/mercurial/sparse.py
--- a/mercurial/sparse.py
+++ b/mercurial/sparse.py
@@ -366,16 +366,16 @@ 
     return result
 
 
-def filterupdatesactions(repo, wctx, mctx, branchmerge, actions):
+def filterupdatesactions(repo, wctx, mctx, branchmerge, mresult):
     """Filter updates to only lay out files that match the sparse rules."""
     if not enabled:
-        return actions
+        return
 
     oldrevs = [pctx.rev() for pctx in wctx.parents()]
     oldsparsematch = matcher(repo, oldrevs)
 
     if oldsparsematch.always():
-        return actions
+        return
 
     files = set()
     prunedactions = {}
@@ -390,7 +390,7 @@ 
         sparsematch = matcher(repo, [mctx.rev()])
 
     temporaryfiles = []
-    for file, action in pycompat.iteritems(actions):
+    for file, action in pycompat.iteritems(mresult.actions):
         type, args, msg = action
         files.add(file)
         if sparsematch(file):
@@ -457,7 +457,7 @@ 
             elif old and not new:
                 prunedactions[file] = (b'r', [], b'')
 
-    return prunedactions
+    mresult.setactions(prunedactions)
 
 
 def refreshwdir(repo, origstatus, origsparsematch, force=False):
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1130,10 +1130,7 @@ 
         fractions = _forgetremoved(wctx, mctx, branchmerge)
         mresult.updateactions(fractions)
 
-    prunedactions = sparse.filterupdatesactions(
-        repo, wctx, mctx, branchmerge, mresult.actions
-    )
-    mresult.setactions(prunedactions)
+    sparse.filterupdatesactions(repo, wctx, mctx, branchmerge, mresult)
     _resolvetrivial(repo, wctx, mctx, ancestors[0], mresult)
 
     return mresult