# HG changeset patch
# User Gregory Szorc <gregory.sz...@gmail.com>
# Date 1499379254 25200
#      Thu Jul 06 15:14:14 2017 -0700
# Node ID ffed7d6dd6977e36c31add7386c61c2dc9d46191
# Parent  926348830c7b95a0ddab2aa7ac110a8743fe6dec
sparse: move post commit actions into core

Instead of wrapping committablectx.markcommitted(), we inline
the call into localrepository.commit(), which is the only place
we call markcommitted().

The APIs and distribution of duties between
localrepository.commit() and committablecontext.markcommitted()
are unclear to me. As is the proper order for certain operations
to be performed. There is room to improve this code.

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,
@@ -99,9 +98,6 @@ testedwith = 'ships-with-hg-core'
 cmdtable = {}
 command = registrar.command(cmdtable)
 
-def uisetup(ui):
-    _setupcommit(ui)
-
 def extsetup(ui):
     sparse.enabled = True
 
@@ -141,27 +137,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/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -53,6 +53,7 @@ from . import (
     revset,
     revsetlang,
     scmutil,
+    sparse,
     store,
     subrepo,
     tags as tagsmod,
@@ -1742,6 +1743,7 @@ class localrepository(object):
             # update bookmarks, dirstate and mergestate
             bookmarks.update(self, [p1, p2], ret)
             cctx.markcommitted(ret)
+            sparse.aftercommit(self, ret)
             ms.reset()
             tr.close()
 
diff --git a/mercurial/sparse.py b/mercurial/sparse.py
--- a/mercurial/sparse.py
+++ b/mercurial/sparse.py
@@ -559,3 +559,17 @@ def refreshwdir(repo, origstatus, origsp
         dirstate.normallookup(file)
 
     return added, dropped, lookup
+
+def aftercommit(repo, node):
+    """Perform actions after a working directory commit."""
+    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)
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to