Patchwork [08,of,11,sparse,V3] sparse: refactor update actions filtering and call from core

login
register
mail settings
Submitter Gregory Szorc
Date July 7, 2017, 1:18 a.m.
Message ID <e01ed081c4879c8e29e6.1499390309@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/22080/
State Accepted
Headers show

Comments

Gregory Szorc - July 7, 2017, 1:18 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1499383771 25200
#      Thu Jul 06 16:29:31 2017 -0700
# Node ID e01ed081c4879c8e29e62cf4b4cd2ad0ea981ae0
# Parent  30d600e49f0e82abe5742a7483a05301e5a2b739
sparse: refactor update actions filtering and call from core

merge.calculateupdates() now filters the update actions through sparse
by default.

The filtering no-ops if sparse isn't enabled or no sparse config
is defined.

The function has been refactored to behave more like a filter
instead of a wrapper of merge.calculateupdates().

We should arguably take sparse into account earlier in
merge.calculateupdates(). This patch preserves the old behavior
of applying sparse at the end of update calculation, which is the
simplest and safest approach.

Patch

diff --git a/hgext/sparse.py b/hgext/sparse.py
--- a/hgext/sparse.py
+++ b/hgext/sparse.py
@@ -102,7 +102,6 @@  cmdtable = {}
 command = registrar.command(cmdtable)
 
 def uisetup(ui):
-    _setupupdates(ui)
     _setupcommit(ui)
 
 def extsetup(ui):
@@ -136,10 +135,6 @@  def replacefilecache(cls, propname, repl
         raise AttributeError(_("type '%s' has no property '%s'") % (origcls,
                              propname))
 
-def _setupupdates(ui):
-    extensions.wrapfunction(mergemod, 'calculateupdates',
-                            sparse.calculateupdates)
-
 def _setupcommit(ui):
     def _refreshoncommit(orig, self, node):
         """Refresh the checkout when commits touch .hgsparse
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -975,7 +975,10 @@  def _resolvetrivial(repo, wctx, mctx, an
 def calculateupdates(repo, wctx, mctx, ancestors, branchmerge, force,
                      acceptremote, followcopies, matcher=None,
                      mergeforce=False):
-    "Calculate the actions needed to merge mctx into wctx using ancestors"
+    """Calculate the actions needed to merge mctx into wctx using ancestors"""
+    # Avoid cycle.
+    from . import sparse
+
     if len(ancestors) == 1: # default
         actions, diverge, renamedelete = manifestmerge(
             repo, wctx, mctx, ancestors[0], branchmerge, force, matcher,
@@ -1074,7 +1077,10 @@  def calculateupdates(repo, wctx, mctx, a
         fractions = _forgetremoved(wctx, mctx, branchmerge)
         actions.update(fractions)
 
-    return actions, diverge, renamedelete
+    prunedactions = sparse.filterupdatesactions(repo, wctx, mctx, branchmerge,
+                                                actions)
+
+    return prunedactions, diverge, renamedelete
 
 def batchremove(repo, wctx, actions):
     """apply removes to the working directory
diff --git a/mercurial/sparse.py b/mercurial/sparse.py
--- a/mercurial/sparse.py
+++ b/mercurial/sparse.py
@@ -301,18 +301,16 @@  def matcher(repo, revs=None, includetemp
 
     return result
 
-def calculateupdates(orig, repo, wctx, mctx, ancestors, branchmerge, *arg,
-                      **kwargs):
-    """Filter updates to only lay out files that match the sparse rules.
-    """
-    actions, diverge, renamedelete = orig(repo, wctx, mctx, ancestors,
-                                          branchmerge, *arg, **kwargs)
+def filterupdatesactions(repo, wctx, mctx, branchmerge, actions):
+    """Filter updates to only lay out files that match the sparse rules."""
+    if not enabled:
+        return actions
 
     oldrevs = [pctx.rev() for pctx in wctx.parents()]
     oldsparsematch = matcher(repo, oldrevs)
 
     if oldsparsematch.always():
-        return actions, diverge, renamedelete
+        return actions
 
     files = set()
     prunedactions = {}
@@ -383,4 +381,4 @@  def calculateupdates(orig, repo, wctx, m
             elif old and not new:
                 prunedactions[file] = ('r', [], '')
 
-    return prunedactions, diverge, renamedelete
+    return prunedactions