# HG changeset patch # User Vincent Hatakeyama # Date 1610638614 -3600 # Thu Jan 14 16:36:54 2021 +0100 # Node ID 3dec151080ae036e55f8a98bbbb6b0e299edc60d # Parent 0079f9065352696085b3678b5ccc22644b386986 ✨ add a way to use expanded projects’ layout as the base layout for subelements. diff --git a/README.md b/README.md --- a/README.md +++ b/README.md @@ -129,6 +129,10 @@ `expand.blacklist=<...>` notations indicate a repository that contain a configuration and should be used by `confman` as such. +It is also possible to use `expand.nested` to use the layout of the other project as +the place to put the expanded elements. This can be combined with white and black list, +`.nested` just needs to be put before them. + Here's a real-life configuration tree: ![conf pythonianfr](pythonianfrconf.png) diff --git a/hgext3rd/confman/utils.py b/hgext3rd/confman/utils.py --- a/hgext3rd/confman/utils.py +++ b/hgext3rd/confman/utils.py @@ -201,11 +201,14 @@ # PATCH: level and filtering level=0, section_filter=None, + layout_prefix=None, ): sectionre = compilere(r'\[([^\[]+)\]') itemre = compilere(r'([^=\s][^=]*?)\s*=\s*(.*\S|)') # PATCH - expandre = compilere(r'(expand)(\.whitelist|\.blacklist|)(\.re|)\s*=\s*(.*)$') + expandre = compilere( + r'(expand)(\.nested|)(\.whitelist|\.blacklist|)(\.re|)\s*=\s*(.*)$' + ) # /PATCH contre = compilere(r'\s+(\S|\S.*\S)\s*$') emptyre = compilere(r'(;|#|\s*$)') @@ -282,16 +285,19 @@ if include: morewhite = () moreblack = () - if m.group(2) == '.whitelist': - morewhite = tuple(m.group(4).split()) - elif m.group(2) == '.blacklist': - moreblack += tuple(m.group(4).split()) + if m.group(3) == '.whitelist': + morewhite = tuple(m.group(5).split()) + elif m.group(3) == '.blacklist': + moreblack += tuple(m.group(5).split()) _section_filter = sectionfilter( - regexp=bool(m.group(3)), + regexp=bool(m.group(4)), parent=section_filter, morewhite=morewhite, moreblack=moreblack, ) + sub_layout_prefix = None + if m.group(2) == ".nested": + sub_layout_prefix = self.get(section, "layout") try: include( @@ -300,6 +306,7 @@ sections=sections, level=level + 1, section_filter=_section_filter, + layout_prefix=sub_layout_prefix, ) except IOError as inst: if inst.errno != errno.ENOENT: @@ -315,7 +322,10 @@ cont = True if sections and section not in sections: continue - self.set(section, item, m.group(2), "%s:%d" % (src, line)) + value = m.group(2) + if item == "layout" and layout_prefix: + value = os.path.join(layout_prefix, value) + self.set(section, item, value, "%s:%d" % (src, line)) continue m = unsetre.match(l) if m: @@ -331,7 +341,9 @@ l.rstrip().encode('utf-8'), ("%s:%s" % (src, line)).encode('utf-8') ) - def parse_guestrepo(self, dirpath, level=0, section_filter=None): + def parse_guestrepo( + self, dirpath, level=0, section_filter=None, layout_prefix=None + ): "Parse guestrepo files in dirpath" # a guestrepo configuration is made of two files: # .hggrmapping and .hgguestrepo @@ -355,7 +367,10 @@ for layout in guestconf[b'']: section, cset = guestconf[b''][layout][0].split(None, 1) if section_filter(section): - self.set(section.decode('utf-8'), 'layout', layout.decode('utf-8')) + decoded_layout = layout.decode('utf-8') + if layout_prefix: + decoded_layout = os.path.join(layout_prefix, decoded_layout) + self.set(section.decode('utf-8'), 'layout', decoded_layout) self.set(section.decode('utf-8'), 'track', cset.decode('utf-8')) def read(self, path, fp=None, sections=None, remap=None, **kwargs):