[PATCH 2 of 2] config: highlight parse error caused by leading spaces (issue3214)

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Aug 21 01:13:43 CDT 2014


# HG changeset patch
# User Razvan Cojocaru <razvan.cojocaru93 at gmail.com>
# Date 1394983891 -7200
#      Sun Mar 16 17:31:31 2014 +0200
# Node ID 558fc3cc3194e4a3c8afa35dc6e234a47467bba9
# Parent  b09526f454bd930d851963bda21227f9932bccf8
config: highlight parse error caused by leading spaces (issue3214)

Added "Unexpected leading whitespace" message to parse error
when .hgrc has a line that starts with whitespace.
Helps new users unfamiliar with syntax of rc file.

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -56,10 +56,12 @@ def dispatch(req):
         return -1
     except error.ParseError, inst:
         if len(inst.args) > 1:
             ferr.write(_("hg: parse error at %s: %s\n") %
                              (inst.args[1], inst.args[0]))
+            if (inst.args[0][0] == ' '):
+                ferr.write(_("Unexpected leading whitespace\n"))
         else:
             ferr.write(_("hg: parse error: %s\n") % inst.args[0])
         return -1
 
     msg = ' '.join(' ' in a and repr(a) or a for a in req.args)
@@ -153,10 +155,12 @@ def _runcatch(req):
                 (inst.args[0], " ".join(inst.args[1])))
     except error.ParseError, inst:
         if len(inst.args) > 1:
             ui.warn(_("hg: parse error at %s: %s\n") %
                              (inst.args[1], inst.args[0]))
+            if (inst.args[0][0] == ' '):
+                ui.warn(_("unexpected leading whitespace\n"))
         else:
             ui.warn(_("hg: parse error: %s\n") % inst.args[0])
         return -1
     except error.LockHeld, inst:
         if inst.errno == errno.ETIMEDOUT:
diff --git a/tests/test-config.t b/tests/test-config.t
--- a/tests/test-config.t
+++ b/tests/test-config.t
@@ -17,10 +17,29 @@ Invalid syntax: no key
   > EOF
   $ hg showconfig
   hg: parse error at $TESTTMP/.hg/hgrc:1: =nokeyvalue
   [255]
 
+Test hint about invalid syntax from leading white space
+
+  $ cat > .hg/hgrc << EOF
+  >  key=value
+  > EOF
+  $ hg showconfig
+  hg: parse error at $TESTTMP/.hg/hgrc:1:  key=value
+  unexpected leading whitespace
+  [255]
+
+  $ cat > .hg/hgrc << EOF
+  >  [section]
+  > key=value
+  > EOF
+  $ hg showconfig
+  hg: parse error at $TESTTMP/.hg/hgrc:1:  [section]
+  unexpected leading whitespace
+  [255]
+
 reset hgrc
 
   $ echo > .hg/hgrc
 
 Test case sensitive configuration
diff --git a/tests/test-hgrc.t b/tests/test-hgrc.t
--- a/tests/test-hgrc.t
+++ b/tests/test-hgrc.t
@@ -41,10 +41,11 @@ issue1829: wrong indentation
 
   $ echo '[foo]' > $HGRC
   $ echo '  x = y' >> $HGRC
   $ hg version
   hg: parse error at $TESTTMP/hgrc:2:   x = y
+  Unexpected leading whitespace
   [255]
 
   $ python -c "print '[foo]\nbar = a\n b\n c \n  de\n fg \nbaz = bif cb \n'" \
   > > $HGRC
   $ hg showconfig foo


More information about the Mercurial-devel mailing list