mercurial/formatter.py
changeset 45310 f3481e4fcc3a
parent 45309 65a812ed9e9f
child 45320 4aa484efc926
equal deleted inserted replaced
45309:65a812ed9e9f 45310:f3481e4fcc3a
   538 class templatespec(object):
   538 class templatespec(object):
   539     ref = attr.ib()
   539     ref = attr.ib()
   540     tmpl = attr.ib()
   540     tmpl = attr.ib()
   541     mapfile = attr.ib()
   541     mapfile = attr.ib()
   542     refargs = attr.ib(default=None)
   542     refargs = attr.ib(default=None)
       
   543     fp = attr.ib(default=None)
   543 
   544 
   544 
   545 
   545 def empty_templatespec():
   546 def empty_templatespec():
   546     return templatespec(None, None, None)
   547     return templatespec(None, None, None)
   547 
   548 
   554     if pycompat.ispy3:
   555     if pycompat.ispy3:
   555         assert not isinstance(tmpl, str), b'tmpl must not be a str'
   556         assert not isinstance(tmpl, str), b'tmpl must not be a str'
   556     return templatespec(b'', tmpl, None)
   557     return templatespec(b'', tmpl, None)
   557 
   558 
   558 
   559 
   559 def mapfile_templatespec(topic, mapfile):
   560 def mapfile_templatespec(topic, mapfile, fp=None):
   560     return templatespec(topic, None, mapfile)
   561     return templatespec(topic, None, mapfile, fp=fp)
   561 
   562 
   562 
   563 
   563 def lookuptemplate(ui, topic, tmpl):
   564 def lookuptemplate(ui, topic, tmpl):
   564     """Find the template matching the given -T/--template spec 'tmpl'
   565     """Find the template matching the given -T/--template spec 'tmpl'
   565 
   566 
   601     if not os.path.split(tmpl)[0]:
   602     if not os.path.split(tmpl)[0]:
   602         (mapname, fp) = templater.open_template(
   603         (mapname, fp) = templater.open_template(
   603             b'map-cmdline.' + tmpl
   604             b'map-cmdline.' + tmpl
   604         ) or templater.open_template(tmpl)
   605         ) or templater.open_template(tmpl)
   605         if mapname:
   606         if mapname:
   606             return mapfile_templatespec(topic, mapname)
   607             return mapfile_templatespec(topic, mapname, fp)
   607 
   608 
   608     # perhaps it's a reference to [templates]
   609     # perhaps it's a reference to [templates]
   609     if ui.config(b'templates', tmpl):
   610     if ui.config(b'templates', tmpl):
   610         return reference_templatespec(tmpl)
   611         return reference_templatespec(tmpl)
   611 
   612 
   643     """Create a templater from either a literal template or loading from
   644     """Create a templater from either a literal template or loading from
   644     a map file"""
   645     a map file"""
   645     assert not (spec.tmpl and spec.mapfile)
   646     assert not (spec.tmpl and spec.mapfile)
   646     if spec.mapfile:
   647     if spec.mapfile:
   647         return templater.templater.frommapfile(
   648         return templater.templater.frommapfile(
   648             spec.mapfile, defaults=defaults, resources=resources, cache=cache
   649             spec.mapfile,
       
   650             spec.fp,
       
   651             defaults=defaults,
       
   652             resources=resources,
       
   653             cache=cache,
   649         )
   654         )
   650     return maketemplater(
   655     return maketemplater(
   651         ui, spec.tmpl, defaults=defaults, resources=resources, cache=cache
   656         ui, spec.tmpl, defaults=defaults, resources=resources, cache=cache
   652     )
   657     )
   653 
   658