mercurial/cmdutil.py
changeset 37774 d6970628b95f
parent 37763 b54404d66f7e
child 37778 f10cb49951e1
equal deleted inserted replaced
37773:0f084741cd66 37774:d6970628b95f
   901                                                  editform=editform)
   901                                                  editform=editform)
   902     elif editform:
   902     elif editform:
   903         return lambda r, c, s: commiteditor(r, c, s, editform=editform)
   903         return lambda r, c, s: commiteditor(r, c, s, editform=editform)
   904     else:
   904     else:
   905         return commiteditor
   905         return commiteditor
       
   906 
       
   907 def _escapecommandtemplate(tmpl):
       
   908     parts = []
       
   909     for typ, start, end in templater.scantemplate(tmpl, raw=True):
       
   910         if typ == b'string':
       
   911             parts.append(stringutil.escapestr(tmpl[start:end]))
       
   912         else:
       
   913             parts.append(tmpl[start:end])
       
   914     return b''.join(parts)
       
   915 
       
   916 def rendercommandtemplate(ui, tmpl, props):
       
   917     r"""Expand a literal template 'tmpl' in a way suitable for command line
       
   918 
       
   919     '\' in outermost string is not taken as an escape character because it
       
   920     is a directory separator on Windows.
       
   921 
       
   922     >>> from . import ui as uimod
       
   923     >>> ui = uimod.ui()
       
   924     >>> rendercommandtemplate(ui, b'c:\\{path}', {b'path': b'foo'})
       
   925     'c:\\foo'
       
   926     >>> rendercommandtemplate(ui, b'{"c:\\{path}"}', {'path': b'foo'})
       
   927     'c:{path}'
       
   928     """
       
   929     if not tmpl:
       
   930         return tmpl
       
   931     t = formatter.maketemplater(ui, _escapecommandtemplate(tmpl))
       
   932     return t.renderdefault(props)
   906 
   933 
   907 def rendertemplate(ctx, tmpl, props=None):
   934 def rendertemplate(ctx, tmpl, props=None):
   908     """Expand a literal template 'tmpl' byte-string against one changeset
   935     """Expand a literal template 'tmpl' byte-string against one changeset
   909 
   936 
   910     Each props item must be a stringify-able value or a callable returning
   937     Each props item must be a stringify-able value or a callable returning