On Wed, 29 Mar 2017 15:25:26 -0700, David Soria Parra wrote: > On Mon, Mar 27, 2017 at 11:38:06AM -0700, Jun Wu wrote: > > # HG changeset patch > > # User Jun Wu <qu...@fb.com> > > # Date 1490635856 25200 > > # Mon Mar 27 10:30:56 2017 -0700 > > # Node ID 4eb7c76340791f379a34f9df4ec42e0c8b9b2a2f > > # Parent 4a8d065bbad80d3b3401010375bc80165404aa87 > > RFC: implement immutable config objects > > I like the overall approach and that it's parallel to config.config() and > ui.config. We might in later patches combine config.config into this.
Yea, the idea sounds good and the next patch proves that this actually works. Nice. Random nitpicks in line. > > +class fileconfig(atomicconfig): > > + """immutable config constructed from config files""" > > + > > + def __init__(self, title, fp, sections=None, remap=None): > > + # Currently, just use the legacy, non-immutable "config" object to > > do > > + # the parsing, remap stuff. In the future we may want to detach > > from it > > + cfg = config() > > + cfg.read(title, fp, sections=sections, remap=remap) > > + > > + def cfgwalker(): > > + # visible config, with source > > + for section in cfg: > > + emptysection = True > > + for item, value in cfg.items(section): > > + emptysection = False > > + source = cfg.source(section, item) > > + yield (section, item, (value, source)) We might want to keep filename and line number separately in future version. > > +class filteredconfig(abstractimmutableconfig): > > + """immutable config that changes other configs""" > > + > > + def __init__(self, title, subconfig, filters=None): > > + """ > > + filters: a dict-ish, {section: filterfunc or sortdict-ish} > > + a filterfunc takes sortdict-ish and returns sortdict-ish > > + a sortdict-ish will replace the section directly > > + """ So this is more like "map" operation? I thought filterfunc would return booleans. > > + super(filteredconfig, self).__init__(title) > > + self._filters = filters or {} > > + self._subconfig = subconfig > > + self._cachedsections = {} > > + > > + def subconfigs(self, section=None): > I think this is actually not needed except for dumpconfig, which might just > be a > helper that knows about the internals. > > > + return (self._subconfig,) > > + > > + def sections(self): > > + return self._subconfig.sections() > > + > > + def getsection(self, section): > > + if section not in self._filters: > > + return self._subconfig.getsection(section) > > + items = self._cachedsections.get(section, None) > > + if items is None: > > + filter = self._filters[section] > > + if util.safehasattr(filter, '__call__'): > this should be `callable` > > > + items = filter(self._subconfig.getsection(section)) > > + else: > > + items = filter Do we really need to overload the type of filter? _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel