[PATCH 5 of 6] config: give it a mapfile option, for parsing them specially
Jordi GutiƩrrez Hermoso
jordigh at octave.org
Fri May 1 23:56:20 CDT 2015
# HG changeset patch
# User Jordi GutiƩrrez Hermoso <jordigh at octave.org>
# Date 1430344009 14400
# Wed Apr 29 17:46:49 2015 -0400
# Node ID c06e371d76b759b900b34120d8d3e90a63790660
# Parent 5adc92b85bfe045bfd527d836eccad53a5568e92
config: give it a mapfile option, for parsing them specially
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 optionally add the
templates directory to the %include path.
diff --git a/mercurial/config.py b/mercurial/config.py
--- a/mercurial/config.py
+++ b/mercurial/config.py
@@ -8,12 +8,14 @@
from i18n import _
import error, util
import os, errno
+import templater
class config(object):
- def __init__(self, data=None):
+ def __init__(self, data=None, mapfile=False):
self._data = {}
self._source = {}
self._unset = []
+ self._mapfile = mapfile
if data:
for k in data._data:
self._data[k] = data[k].copy()
@@ -110,18 +112,29 @@ 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))
+ base = os.path.dirname(src)
+ inc = os.path.normpath(os.path.join(base, expanded))
+
+ if not includefile(inc) and self._mapfile:
+ # For template mapfiles, try to include from the
+ # template directory, after looking in the current
+ # directory already failed.
+ includefile(templater.templatepath(expanded))
+
continue
if emptyre.match(l):
continue
More information about the Mercurial-devel
mailing list