Patchwork [1,of,6,V3] cmdutil: convert the prefetchfiles() hook to a callback mechanism (API)

login
register
mail settings
Submitter Matt Harbison
Date Feb. 13, 2018, 5:39 a.m.
Message ID <7d3abc6fcc2f39cd890c.1518500354@Envy>
Download mbox | patch
Permalink /patch/27804/
State Accepted
Headers show

Comments

Matt Harbison - Feb. 13, 2018, 5:39 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1518326637 18000
#      Sun Feb 11 00:23:57 2018 -0500
# Node ID 7d3abc6fcc2f39cd890c0062121dcb0ac44df45a
# Parent  e99e6917138593d2dddf7e0f5506dbd3f6c87743
cmdutil: convert the prefetchfiles() hook to a callback mechanism (API)

Yuya suggested a list of callbacks instead of function wrapping.  This means
that one extension can't block another from processing the list.

.. api::

   File prefetching is now handled by registering a callback with
   scmutil.fileprefetchhooks.
Yuya Nishihara - Feb. 13, 2018, 11:12 a.m.
On Tue, 13 Feb 2018 00:39:14 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1518326637 18000
> #      Sun Feb 11 00:23:57 2018 -0500
> # Node ID 7d3abc6fcc2f39cd890c0062121dcb0ac44df45a
> # Parent  e99e6917138593d2dddf7e0f5506dbd3f6c87743
> cmdutil: convert the prefetchfiles() hook to a callback mechanism (API)

Queued, thanks.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2865,8 +2865,9 @@ 
         if not opts.get('dry_run'):
             needdata = ('revert', 'add', 'undelete')
             if _revertprefetch is not _revertprefetchstub:
-                ui.deprecwarn("'cmdutil._revertprefetch' is deprecated, use "
-                              "'cmdutil._prefetchfiles'", '4.6', stacklevel=1)
+                ui.deprecwarn("'cmdutil._revertprefetch' is deprecated, "
+                              "add a callback to 'scmutil.fileprefetchhooks'",
+                              '4.6', stacklevel=1)
                 _revertprefetch(repo, ctx,
                                 *[actions[name][0] for name in needdata])
             oplist = [actions[name][0] for name in needdata]
@@ -2893,6 +2894,7 @@ 
 def _prefetchfiles(repo, ctx, files):
     """Let extensions changing the storage layer prefetch content for any non
     merge based command."""
+    scmutil.fileprefetchhooks(repo, ctx, files)
 
 def _performrevert(repo, parents, ctx, actions, interactive=False,
                    tobackup=None):
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -1222,6 +1222,11 @@ 
     'unbundle',
 ]
 
+# a list of (repo, ctx, files) functions called by various commands to allow
+# extensions to ensure the corresponding files are available locally, before the
+# command uses them.
+fileprefetchhooks = util.hooks()
+
 # A marker that tells the evolve extension to suppress its own reporting
 _reportstroubledchangesets = True