[PATCH RESEND] templater: support using templates with non-standard names from map file
Alexander Plavin
alexander at plav.in
Fri Sep 6 14:34:55 CDT 2013
06.09.2013, 21:57, "Augie Fackler" <raf at durin42.com>:
> On Fri, Sep 06, 2013 at 11:23:11AM +0400, Alexander Plavin wrote:
>
>> 06.09.2013, 05:16, "Kevin Bullock" <kbullock+mercurial at ringworld.org>:
>>> On 2 Sep 2013, at 2:46 PM, Alexander Plavin wrote:
>>>> # HG changeset patch
>>>> # User Alexander Plavin <alexander at plav.in>
>>>> # Date 1374620882 -14400
>>>> # Wed Jul 24 03:08:02 2013 +0400
>>>> # Node ID c71151e59f50d5a112f9e7971df1f7417cdba2cd
>>>> # Parent 3dfc0bf05e89f5faa109827b921099cde038130c
>>>> templater: support using templates with non-standard names from map file
>>>>
>>>> This allows adding arbitrarily-named entries to a template map file, and then
>>>> referencing them, giving the ability to deduplicate and simplify templates code.
>>>>
>>>> diff -r 3dfc0bf05e89 -r c71151e59f50 mercurial/templater.py
>>>> --- a/mercurial/templater.py Sun Sep 01 10:40:11 2013 +0400
>>>> +++ b/mercurial/templater.py Wed Jul 24 03:08:02 2013 +0400
>>>> @@ -139,7 +139,12 @@
>>>> def runsymbol(context, mapping, key):
>>>> v = mapping.get(key)
>>>> if v is None:
>>>> - v = context._defaults.get(key, '')
>>>> + v = context._defaults.get(key)
>>>> + if v is None:
>>>> + try:
>>>> + v = context.process(key, mapping)
>>>> + except util.Abort:
>>> Not too keen on trapping util.Abort; is there a reasonable way to refactor the process() method to throw some other kind of exception (like KeyError), and have its current callers do the aborting?
>> util.Abort is raised in templater.load on excepting KeyError, and it
>> can't be simply changed there: templater.load is called in several
>> other places, not only in process(). These places include
>> extensions, for example the highlight extension, and other written
>> extensions could also use it.
>
> At a minimum, this could raise a subclass of util.Abort so you could
> catch a narrower exception type. I'm also -1 on catching util.Abort.
Nice suggestion, to subclass Abort - didn't think of it. And if that is 'at a minimum', what would be the (more) optimal solution?
>
>>> pacem in terris / мир / शान्ति / سَلاَم / 平和
>>> Kevin R. Bullock
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel at selenic.com
>> http://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list