[PATCH] config: give more fine-tuned sample hgrcs to this command

Pierre-Yves David pierre-yves.david at ens-lyon.org
Wed Aug 13 16:55:21 CDT 2014



On 08/13/2014 02:14 PM, Jordi Gutiérrez Hermoso wrote:
> # HG changeset patch
> # User Jordi Gutiérrez Hermoso <jordigh at octave.org>
> # Date 1407963948 14400
> #      Wed Aug 13 17:05:48 2014 -0400
> # Node ID f9690691301dd804ccc03d0787112c3e18cb9226
> # Parent  e125a4ec265f9207667e82a62754dfd96f17c0a4
> config: give more fine-tuned sample hgrcs to this command
>
> The hgrc for user config is typically different from the hgrc at the
> system-wide or repository level. This patch provides different sample
> hgrcs for each level. Sometimes when copying repos around, the copy or
> the original don't have a default path yet, so at least for `hg config
> -l`, this ought to provide a more reasonable default and suggestions
> of what typically goes there.

I love the idea. The patch itself needs some rework:


1) you should extract the dictionnary into a module level command (can 
even be moved in config). Having the dictionnary in the body of the 
function makes it hard to read (because of the indent) and inflate the 
body of the function too much.

    Another option would be to have them as example file as we do for style.
    I prefers the dictionnary idea as it let extension to play with its 
content.

2) You should introduce each new config option in a separated patch so 
they can be discussed independently.


>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -1520,10 +1520,9 @@ def config(ui, repo, *values, **opts):
>               if os.path.exists(f):
>                   break
>           else:
> -            f = paths[0]
> -            fp = open(f, "w")
> -            fp.write(
> -                '# example config (see "hg help config" for more info)\n'
> +            samplehgrcs = {
> +                'user':
> +                '# example user config (see "hg help config" for more info)\n'
>                   '\n'
>                   '[ui]\n'
>                   '# name and email, e.g.\n'
> @@ -1535,7 +1534,41 @@ def config(ui, repo, *values, **opts):
>                   '# (see "hg help extensions" for more info)\n'
>                   '# pager =\n'
>                   '# progress =\n'
> -                '# color =\n')
> +                '# color =\n',
> +
> +                'local':
> +                '# example repository config (see "hg help config" for '
> +                    'more info)\n'
> +                '\n'
> +                '[paths]\n'
> +                '# Path aliases to other clones of this repo in external '
> +                     'URLs or filesystem paths,\n'
> +                '\n'
> +                '# default = http://example.com/hg/example-repo\n'
> +                '# myfork  = ssh://jdoe@example.net/hg/jdoes-fork\n'
> +                '# myclone = /home/jdoe/jdoes-clone\n',

Maybe adding a hit about default-push. not sur about the myfork and my 
clone things.

> +
> +                'global':
> +                '# example system-wide hg config (see "hg help config" for '
> +                    'more info)\n'
> +                '\n'
> +                '[extensions]\n'
> +                '# Uncomment these lines for some popular extensions\n'
> +                '# inotify =\n'
> +                '# win32mbcs =\n'
> +                '# win32text =\n',
> +                }

inotify is a DEPRECATED extension with no code in it. how can it be a 
popular extension?


> +
> +            if opts.get('global'):
> +                samplehgrc = samplehgrcs['global']
> +            elif opts.get('local'):
> +                samplehgrc = samplehgrcs['local']
> +            else:
> +                samplehgrc = samplehgrcs['user']
> +
> +            f = paths[0]
> +            fp = open(f, "w")
> +            fp.write(samplehgrc)
>               fp.close()
>
>           editor = ui.geteditor()
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list