# HG changeset patch # User Matt Harbison # Date 2018-02-11 05:23:57 # Node ID f52a9336ac5fb78f08b45221dd4de4d5bfeaf94e # Parent 6767e7ce2c319ddbef390f3938f4545ffe117023 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. diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -2865,8 +2865,9 @@ def revert(ui, repo, ctx, parents, *pats 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 _revertprefetchstub(repo, ctx, *file 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 @@ class simplekeyvaluefile(object): '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