Patchwork [01,of,11,sparse] sparse: move post commit actions into core

login
register
mail settings
Submitter Gregory Szorc
Date July 8, 2017, 11:28 p.m.
Message ID <05fba83e64406ea50517.1499556536@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/22127/
State Accepted
Headers show

Comments

Gregory Szorc - July 8, 2017, 11:28 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1499453470 25200
#      Fri Jul 07 11:51:10 2017 -0700
# Node ID 05fba83e64406ea5051763c4c14c4067b2b72254
# Parent  4672db164c986da4442bd864cd044512d975c3f2
sparse: move post commit actions into core

Instead of wrapping committablectx.markcommitted(), we inline
the call into workingctx.markcommitted().

Per smf's review, workingctx is the proper location for this
code, as committablectx is the shared base class for it and
memctx. Since this code touches the working directory, it belongs
in workingctx.

Patch

diff --git a/hgext/sparse.py b/hgext/sparse.py
--- a/hgext/sparse.py
+++ b/hgext/sparse.py
@@ -79,7 +79,6 @@  from mercurial.node import nullid
 from mercurial import (
     cmdutil,
     commands,
-    context,
     dirstate,
     error,
     extensions,
@@ -100,9 +99,6 @@  testedwith = 'ships-with-hg-core'
 cmdtable = {}
 command = registrar.command(cmdtable)
 
-def uisetup(ui):
-    _setupcommit(ui)
-
 def extsetup(ui):
     sparse.enabled = True
 
@@ -134,27 +130,6 @@  def replacefilecache(cls, propname, repl
         raise AttributeError(_("type '%s' has no property '%s'") % (origcls,
                              propname))
 
-def _setupcommit(ui):
-    def _refreshoncommit(orig, self, node):
-        """Refresh the checkout when commits touch .hgsparse
-        """
-        orig(self, node)
-        repo = self._repo
-
-        ctx = repo[node]
-        profiles = sparse.patternsforrev(repo, ctx.rev())[2]
-
-        # profiles will only have data if sparse is enabled.
-        if set(profiles) & set(ctx.files()):
-            origstatus = repo.status()
-            origsparsematch = sparse.matcher(repo)
-            sparse.refreshwdir(repo, origstatus, origsparsematch, force=True)
-
-        sparse.prunetemporaryincludes(repo)
-
-    extensions.wrapfunction(context.committablectx, 'markcommitted',
-        _refreshoncommit)
-
 def _setuplog(ui):
     entry = commands.table['^log|history']
     entry[1].append(('', 'sparse', None,
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -38,6 +38,7 @@  from . import (
     repoview,
     revlog,
     scmutil,
+    sparse,
     subrepo,
     util,
 )
@@ -1803,6 +1804,11 @@  class workingctx(committablectx):
             match.bad = bad
         return match
 
+    def markcommitted(self, node):
+        super(workingctx, self).markcommitted(node)
+
+        sparse.aftercommit(self._repo, node)
+
 class committablefilectx(basefilectx):
     """A committablefilectx provides common functionality for a file context
     that wants the ability to commit, e.g. workingfilectx or memfilectx."""
diff --git a/mercurial/sparse.py b/mercurial/sparse.py
--- a/mercurial/sparse.py
+++ b/mercurial/sparse.py
@@ -478,3 +478,19 @@  def refreshwdir(repo, origstatus, origsp
         dirstate.normallookup(file)
 
     return added, dropped, lookup
+
+def aftercommit(repo, node):
+    """Perform actions after a working directory commit."""
+    # This function is called unconditionally, even if sparse isn't
+    # enabled.
+    ctx = repo[node]
+
+    profiles = patternsforrev(repo, ctx.rev())[2]
+
+    # profiles will only have data if sparse is enabled.
+    if set(profiles) & set(ctx.files()):
+        origstatus = repo.status()
+        origsparsematch = matcher(repo)
+        refreshwdir(repo, origstatus, origsparsematch, force=True)
+
+    prunetemporaryincludes(repo)