mirror of
https://github.com/facebook/sapling.git
synced 2024-10-08 07:49:11 +03:00
templater: relax unquotestring() to fall back to bare string
This is convenient for our use case where quotes are optional except in a map file.
This commit is contained in:
parent
e2dfdaa910
commit
634500f64e
@ -1542,11 +1542,7 @@ def gettemplate(ui, tmpl, style):
|
||||
if not tmpl and not style: # template are stronger than style
|
||||
tmpl = ui.config('ui', 'logtemplate')
|
||||
if tmpl:
|
||||
try:
|
||||
tmpl = templater.unquotestring(tmpl)
|
||||
except SyntaxError:
|
||||
pass
|
||||
return tmpl, None
|
||||
return templater.unquotestring(tmpl), None
|
||||
else:
|
||||
style = util.expandpath(ui.config('ui', 'style', ''))
|
||||
|
||||
|
@ -171,11 +171,7 @@ def lookuptemplate(ui, topic, tmpl):
|
||||
# perhaps it's a reference to [templates]
|
||||
t = ui.config('templates', tmpl)
|
||||
if t:
|
||||
try:
|
||||
tmpl = templater.unquotestring(t)
|
||||
except SyntaxError:
|
||||
tmpl = t
|
||||
return tmpl, None
|
||||
return templater.unquotestring(t), None
|
||||
|
||||
if tmpl == 'list':
|
||||
ui.write(_("available styles: %s\n") % templater.stylelist())
|
||||
|
@ -867,9 +867,9 @@ def _flatten(thing):
|
||||
yield j
|
||||
|
||||
def unquotestring(s):
|
||||
'''unwrap quotes'''
|
||||
'''unwrap quotes if any; otherwise returns unmodified string'''
|
||||
if len(s) < 2 or s[0] != s[-1]:
|
||||
raise SyntaxError(_('unmatched quotes'))
|
||||
return s
|
||||
return s[1:-1]
|
||||
|
||||
class engine(object):
|
||||
@ -980,10 +980,10 @@ class templater(object):
|
||||
if not val:
|
||||
raise error.ParseError(_('missing value'), conf.source('', key))
|
||||
if val[0] in "'\"":
|
||||
try:
|
||||
self.cache[key] = unquotestring(val)
|
||||
except SyntaxError as inst:
|
||||
raise error.ParseError(inst.args[0], conf.source('', key))
|
||||
if val[0] != val[-1]:
|
||||
raise error.ParseError(_('unmatched quotes'),
|
||||
conf.source('', key))
|
||||
self.cache[key] = unquotestring(val)
|
||||
else:
|
||||
val = 'default', val
|
||||
if ':' in val[1]:
|
||||
|
Loading…
Reference in New Issue
Block a user