[PATCH 1 of 2] showconfig: add --edit option for editing .hg/hgrc

Mads Kiilerich mads at kiilerich.com
Wed Apr 28 18:27:43 CDT 2010


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1272496822 -7200
# Node ID b2096a6e1d57b1c1161da46a7f9f072c33dc4add
# Parent  61b835a5a6ee897415b94acf5703d21f374b4999
showconfig: add --edit option for editing .hg/hgrc

Users should never touch any files in .hg - with .hg/hgrc being the primary
exception.

This introduces an option to edit the repository hgrc, and we can thus tell the
users that they should never touch any files in .hg.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -858,7 +858,7 @@
         error = _(".hg/dirstate inconsistent with current parent's manifest")
         raise util.Abort(error)
 
-def showconfig(ui, repo, *values, **opts):
+def showconfig(ui, repo, edit=False, *values, **opts):
     """show combined config settings from all hgrc files
 
     With no arguments, print names and values of all config items.
@@ -871,7 +871,18 @@
 
     With --debug, the source (filename and line number) is printed
     for each config item.
+
+    With --edit, the repository hgrc is opened in an editor.
     """
+    if edit:
+        if not repo:
+            raise error.RepoError(_("There is no Mercurial repository"
+                                    " here (.hg not found)"))
+        txt = ui.edit(repo.opener('hgrc').read(), None)
+        fp = repo.opener('hgrc', 'w')
+        fp.write(txt)
+        fp.close()
+        return
 
     untrusted = bool(opts.get('untrusted'))
     if values:
@@ -3871,8 +3882,9 @@
          _('[OPTION]...')),
     "showconfig|debugconfig":
         (showconfig,
-         [('u', 'untrusted', None, _('show untrusted configuration options'))],
-         _('[-u] [NAME]...')),
+         [('u', 'untrusted', None, _('show untrusted configuration options')),
+          ('e', 'edit', None, _('edit repository config file manually'))],
+         _('[-eu] [NAME]...')),
     "^summary|sum":
         (summary,
          [('', 'remote', None, _('check for push and pull'))], '[--remote]'),


More information about the Mercurial-devel mailing list