[PATCH 4 of 5 V2] config: give it a searchpaths option, for extra places for config files

Yuya Nishihara yuya at tcha.org
Wed May 6 01:40:25 CDT 2015


On Tue, 05 May 2015 17:39:12 -0400, Jordi GutiƩrrez Hermoso wrote:
> # HG changeset patch
> # User Jordi GutiƩrrez Hermoso <jordigh at octave.org>
> # Date 1430860459 14400
> #      Tue May 05 17:14:19 2015 -0400
> # Node ID b7e9b8d77e46052e639fca04b1aee2cfdefbd4f7
> # Parent  dabfe2777f993de4ed1ed16886559d5ebf42a385
> config: give it a searchpaths option, for extra places for config files
> 
> It is desirable to "derive" templates from the provided templates. A
> simple way to do this is e.g.
> 
>     %include map-cmdline.default
> 
> in your own mapfile. Then you only have to redefine a few templates
> instead of copying over the whole thing. This %include mechanism
> already works for the built-in templates because by default it *only*
> looks for files that are in the same directory as the including
> mapfile.
> 
> With this changeset, config grows an option to add more search paths
> for config files.
> 
> diff --git a/mercurial/config.py b/mercurial/config.py
> --- a/mercurial/config.py
> +++ b/mercurial/config.py
> @@ -10,10 +10,11 @@ import error, util
>  import os, errno
>  
>  class config(object):
> -    def __init__(self, data=None):
> +    def __init__(self, data=None, searchpaths=[]):
>          self._data = {}
>          self._source = {}
>          self._unset = []
> +        self._searchpaths = searchpaths
>          if data:
>              for k in data._data:
>                  self._data[k] = data[k].copy()
> @@ -110,18 +111,28 @@ class config(object):
>                  item = None
>                  cont = False
>              m = includere.match(l)
> -            if m:
> -                inc = util.expandpath(m.group(1))
> -                base = os.path.dirname(src)
> -                inc = os.path.normpath(os.path.join(base, inc))
> +            def includefile(inc):
>                  if include:
>                      try:
>                          include(inc, remap=remap, sections=sections)
> +                        return True
>                      except IOError, inst:
>                          if inst.errno != errno.ENOENT:
>                              raise error.ParseError(_("cannot include %s (%s)")
>                                                     % (inc, inst.strerror),
>                                                     "%s:%s" % (src, line))
> +                        else:
> +                            return False
> +            if m:
> +                expanded = util.expandpath(m.group(1))
> +                searchpaths = [os.path.dirname(src)] + self._searchpaths
> +
> +                for base in searchpaths:
> +                    inc = os.path.normpath(os.path.join(base, expanded))
> +
> +                    if includefile(inc):
> +                        continue

typo of "break" ?


More information about the Mercurial-devel mailing list