Patchwork [1,of,2] config: give more fine-tuned sample hgrcs to this command

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date Aug. 20, 2014, 10:29 p.m.
Message ID <8538451ded180c75c024.1408573788@Iris>
Download mbox | patch
Permalink /patch/5536/
State Superseded
Commit f58b41f6708b5bb5ff43ad7f71881f5b116b2a4b
Headers show

Comments

Jordi Gutiérrez Hermoso - Aug. 20, 2014, 10:29 p.m.
# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh@octave.org>
# Date 1407963948 14400
#      Wed Aug 13 17:05:48 2014 -0400
# Node ID 8538451ded180c75c0245ca438df5ae2d02436ba
# Parent  2e9facb746fcbaa475d1b05b686fbce74df66701
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.
Pierre-Yves David - Aug. 21, 2014, 7:23 a.m.
On 08/20/2014 03:29 PM, Jordi Gutiérrez Hermoso wrote:
> # HG changeset patch
> # User Jordi Gutiérrez Hermoso <jordigh@octave.org>
> # Date 1407963948 14400
> #      Wed Aug 13 17:05:48 2014 -0400
> # Node ID 8538451ded180c75c0245ca438df5ae2d02436ba
> # Parent  2e9facb746fcbaa475d1b05b686fbce74df66701
> 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.
>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -156,6 +156,31 @@ subrepoopts = [
>        _('recurse into subrepositories'))
>   ]
>
> +samplehgrcs = {
> +    'user':
> +"""# example user config (see "hg help config" for more info)
> +[ui]
> +# name and email, e.g.
> +# username = Jane Doe <jdoe@example.com>
> +username =
> +
> +[extensions]
> +# uncomment these lines to enable some popular extensions
> +# (see "hg help extensions" for more info)
> +#
> +# pager =
> +# progress =
> +# color =""",
> +
> +    'local':
> +"""# example repository config (see "hg help config" for more info)
> +""",
> +
> +    'global':
> +"""# example system-wide hg config (see "hg help config" for more info)
> +""",
> +}
> +
>   # Commands start here, listed alphabetically

Do not put that in commands.py this module is already far too bit and 
this has barely too do with commands.

config.py could work.


>
>   @command('^add',
> @@ -1520,22 +1545,16 @@ def config(ui, repo, *values, **opts):
>               if os.path.exists(f):
>                   break
>           else:
> +            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(
> -                '# example config (see "hg help config" for more info)\n'
> -                '\n'
> -                '[ui]\n'
> -                '# name and email, e.g.\n'
> -                '# username = Jane Doe <jdoe@example.com>\n'
> -                'username =\n'
> -                '\n'
> -                '[extensions]\n'
> -                '# uncomment these lines to enable some popular extensions\n'
> -                '# (see "hg help extensions" for more info)\n'
> -                '# pager =\n'
> -                '# progress =\n'
> -                '# color =\n')
> +            fp.write(samplehgrc)
>               fp.close()
>
>           editor = ui.geteditor()
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -156,6 +156,31 @@  subrepoopts = [
      _('recurse into subrepositories'))
 ]
 
+samplehgrcs = {
+    'user':
+"""# example user config (see "hg help config" for more info)
+[ui]
+# name and email, e.g.
+# username = Jane Doe <jdoe@example.com>
+username =
+
+[extensions]
+# uncomment these lines to enable some popular extensions
+# (see "hg help extensions" for more info)
+#
+# pager =
+# progress =
+# color =""",
+
+    'local':
+"""# example repository config (see "hg help config" for more info)
+""",
+
+    'global':
+"""# example system-wide hg config (see "hg help config" for more info)
+""",
+}
+
 # Commands start here, listed alphabetically
 
 @command('^add',
@@ -1520,22 +1545,16 @@  def config(ui, repo, *values, **opts):
             if os.path.exists(f):
                 break
         else:
+            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(
-                '# example config (see "hg help config" for more info)\n'
-                '\n'
-                '[ui]\n'
-                '# name and email, e.g.\n'
-                '# username = Jane Doe <jdoe@example.com>\n'
-                'username =\n'
-                '\n'
-                '[extensions]\n'
-                '# uncomment these lines to enable some popular extensions\n'
-                '# (see "hg help extensions" for more info)\n'
-                '# pager =\n'
-                '# progress =\n'
-                '# color =\n')
+            fp.write(samplehgrc)
             fp.close()
 
         editor = ui.geteditor()