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

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date Aug. 24, 2014, 11:51 p.m.
Message ID <cfec84ed3d8f5b9877f4.1408924295@Iris>
Download mbox | patch
Permalink /patch/5583/
State Accepted
Headers show

Comments

Jordi Gutiérrez Hermoso - Aug. 24, 2014, 11:51 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 cfec84ed3d8f5b9877f48ec079eb0583b51f56ad
# Parent  87bc71fdf83ba5ba2d85f8cf082819d30b93e31f
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.

The actual sample configs go in the config.py file, to minimise
clutter. In order to avoid an unnecessary import, the corresponding
import for this dictionary is at the file level.
Matt Mackall - Sept. 11, 2014, 5:37 p.m.
On Sun, 2014-08-24 at 19:51 -0400, Jordi Gutiérrez Hermoso wrote:
> diff --git a/mercurial/config.py b/mercurial/config.py
> --- a/mercurial/config.py
> +++ b/mercurial/config.py
> @@ -9,6 +9,31 @@ from i18n import _
>  import error, util
>  import os, errno
>  
> +samplehgrcs = {
> +    'user':
> +"""# example user config (see "hg help config" for more info)
> +[ui]
> +# name and email, e.g.
> +# username = Jane Doe <jdoe@example.com>

I moved these to ui, as config is intentionally completely generic code
and thus this data is at the wrong layer.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1519,22 +1519,18 @@  def config(ui, repo, *values, **opts):
             if os.path.exists(f):
                 break
         else:
+            from config import samplehgrcs
+
+            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()
diff --git a/mercurial/config.py b/mercurial/config.py
--- a/mercurial/config.py
+++ b/mercurial/config.py
@@ -9,6 +9,31 @@  from i18n import _
 import error, util
 import os, errno
 
+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)
+""",
+}
+
 class config(object):
     def __init__(self, data=None):
         self._data = {}