Bug 1047592 - mercurial-setup should error when trying to read a config with %include. r=gps
authorPatrick Cloke <clokep@gmail.com>
Tue, 05 Aug 2014 09:42:33 -0400
changeset 197945 41a1dc07bb48c7c66abbbd1ca3aff93dc77e69fa
parent 197944 e53c1891fd6be0cb222ef9ab6d00b69d29ee4fda
child 197946 e4ce6be46c38f4b1f832621ec78aef3ce9b68180
push id27256
push userkwierso@gmail.com
push dateWed, 06 Aug 2014 00:06:20 +0000
treeherdermozilla-central@6cbdd4d523a7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1047592
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1047592 - mercurial-setup should error when trying to read a config with %include. r=gps
tools/mercurial/hgsetup/config.py
tools/mercurial/hgsetup/wizard.py
--- a/tools/mercurial/hgsetup/config.py
+++ b/tools/mercurial/hgsetup/config.py
@@ -11,16 +11,20 @@ import os
 
 HOST_FINGERPRINTS = {
     'bitbucket.org': '45:ad:ae:1a:cf:0e:73:47:06:07:e0:88:f5:cc:10:e5:fa:1c:f7:99',
     'bugzilla.mozilla.org': '47:13:a2:14:0c:46:45:53:12:0d:e5:36:16:a5:60:26:3e:da:3a:60',
     'hg.mozilla.org': 'af:27:b9:34:47:4e:e5:98:01:f6:83:2b:51:c9:aa:d8:df:fb:1a:27',
 }
 
 
+class HgIncludeException(Exception):
+    pass
+
+
 class MercurialConfig(object):
     """Interface for manipulating a Mercurial config file."""
 
     def __init__(self, infiles=None):
         """Create a new instance, optionally from an existing hgrc file."""
 
         if infiles:
             # If multiple files were specified, figure out which file we're using:
@@ -30,16 +34,25 @@ class MercurialConfig(object):
                     picky_infiles = [(os.path.getsize(path), path) for path in picky_infiles]
                     infiles = [max(picky_infiles)[1]]
 
             infile = infiles[0]
             self.config_path = infile
         else:
             infile = None
 
+        # Mercurial configuration files allow an %include directive to include
+        # other files, this is not supported by ConfigObj, so throw a useful
+        # error saying this.
+        with open(infile, 'r') as f:
+            for line in f:
+                if line.startswith('%include'):
+                    raise HgIncludeException(
+                        '%include directive is not supported by MercurialConfig')
+
         # write_empty_values is necessary to prevent built-in extensions (which
         # have no value) from being dropped on write.
         # list_values aren't needed by Mercurial and disabling them prevents
         # quotes from being added.
         self._c = ConfigObj(infile=infile, encoding='utf-8',
             write_empty_values=True, list_values=False)
 
     @property
--- a/tools/mercurial/hgsetup/wizard.py
+++ b/tools/mercurial/hgsetup/wizard.py
@@ -18,16 +18,17 @@ from StringIO import StringIO
 
 from mozversioncontrol import get_hg_version
 from mozversioncontrol.repoupdate import (
     update_mercurial_repo,
     update_git_repo,
 )
 
 from .config import (
+    HgIncludeException,
     HOST_FINGERPRINTS,
     MercurialConfig,
 )
 
 
 INITIAL_MESSAGE = '''
 I'm going to help you ensure your Mercurial is configured for optimal
 development on Mozilla projects.
@@ -190,16 +191,20 @@ class MercurialSetupWizard(object):
         try:
             c = MercurialConfig(config_paths)
         except ConfigObjError as e:
             print('Error importing existing Mercurial config!\n')
             for error in e.errors:
                 print(error.message)
 
             return 1
+        except HgIncludeException as e:
+            print(e.message)
+
+            return 1
 
         print(INITIAL_MESSAGE)
         raw_input()
 
         hg_version = get_hg_version(hg)
         if hg_version < OLDEST_NON_LEGACY_VERSION:
             print(LEGACY_MERCURIAL % hg_version)
             print('')