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

Matt Harbison mharbison72 at gmail.com
Sun Feb 11 20:30:14 UTC 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1518326637 18000
#      Sun Feb 11 00:23:57 2018 -0500
# Node ID 6185d42dfd88845eaaee2d4c6dd1a80c7bed5acc
# Parent  91aac8e6604d1aa08b2683c1d4c7d1936f226e48
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
   cmdutil.fileprefetchhooks.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2867,8 +2867,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 'cmdutil.fileprefetchhooks'",
+                              '4.6', stacklevel=1)
                 _revertprefetch(repo, ctx,
                                 *[actions[name][0] for name in needdata])
             oplist = [actions[name][0] for name in needdata]
@@ -2895,6 +2896,7 @@
 def _prefetchfiles(repo, ctx, files):
     """Let extensions changing the storage layer prefetch content for any non
     merge based command."""
+    fileprefetchhooks(repo, ctx, files)
 
 def _performrevert(repo, parents, ctx, actions, interactive=False,
                    tobackup=None):
@@ -3057,6 +3059,11 @@
 #  - (desturl,   destbranch,   destpeer,   outgoing)
 summaryremotehooks = util.hooks()
 
+# 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 list of state files kept by multistep operations like graft.
 # Since graft cannot be aborted, it is considered 'clearable' by update.
 # note: bisect is intentionally excluded


More information about the Mercurial-devel mailing list