On Thu, 12 Apr 2018 13:35:50 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbi...@yahoo.com>
> # Date 1523332699 14400
> #      Mon Apr 09 23:58:19 2018 -0400
> # Node ID 986b51f15e9bce19b2f67573ff76612540320d1b
> # Parent  2e0e61312a257708a70201427b31deba964e9b05
> dispatch: add a whitelist map of commands to implicitly loaded extensions
> 
> This was Augie's idea[1] (or at least my interpretation of it).  The goal is 
> to
> be able to load the lfs extension without user intervention where it is both
> harmless, and provides a user convenience.  The referenced thread discusses 
> the
> clone command and the cryptic error around that in some cases.  But the 
> obvious
> benefit is to be able transparently support cloning an lfs repository, or the
> sudden transition to lfs on a pull, without bothering the user.  The choice to
> use the lfs extension in the repository has already been made in both cases at
> that point, and neither command can accidentally introduce the feature.
> 
> The implementation is perhaps a bit more than imagined in the thread, because 
> I
> think there may be room to allow extensions like 'share' to force lfs on too, 
> in
> order to make the extension usage more invisible.  The largefiles extension
> could probably be given the same treatment.  For simplicity, I didn't bother
> allowing external extensions to be loadable like this.  The mechanism used 
> here
> was pilfered from acl.ensureenabled().
> 
> [1] 
> https://www.mercurial-scm.org/pipermail/mercurial-devel/2018-January/109851.html
> 
> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> --- a/mercurial/dispatch.py
> +++ b/mercurial/dispatch.py
> @@ -48,6 +48,15 @@ from .utils import (
>  
>  unrecoverablewrite = registrar.command.unrecoverablewrite
>  
> +# Map a command to a list of extensions that are forced on prior to running 
> the
> +# command (unless it has been explicitly disabled.)  The idea is to help the
> +# user by enabling extensions implicitly when requirements may be added by a
> +# remote exchange, instead of erroring out after a partial exchange.
> +extensionwhitelist = {
> +    commands.clone: ['lfs'],
> +    commands.pull: ['lfs'],
> +}

Perhaps we can't use a command function as key since it may be wrapped by
extensions.

>  class request(object):
>      def __init__(self, args, ui=None, repo=None, fin=None, fout=None,
>                   ferr=None, prereposetups=None):
> @@ -843,6 +852,20 @@ def _dispatch(req):
>          fullargs = args
>          cmd, func, args, options, cmdoptions = _parse(lui, args)
>  
> +        # resolve aliases back to the core function
> +        entrypoint = func
> +        if isinstance(entrypoint, cmdalias):
> +            entrypoint = entrypoint.fn
> +
> +        if entrypoint in extensionwhitelist:
> +            configured = [ext for (ext, _path) in 
> ui.configitems("extensions")]
> +            missing = [ext for ext in extensionwhitelist[entrypoint]
> +                       if ext not in configured]
> +            for ext in missing:
> +                ui.setconfig('extensions', ext, '', source='internal')
> +            if missing:
> +                extensions.loadall(ui, missing)

I'm -1 on this because loading extra Python module isn't always instant, and
the loaded extension persists forever, which can be a problem for command-server
process.
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to