comparison mercurial/cmdutil.py @ 20668:3a35ba2681ec

templating: make -T much more flexible It can now accept styles and paths and references to settings in [templates].
author Matt Mackall <mpm@selenic.com>
date Sat, 08 Mar 2014 17:38:50 -0600
parents e96e9f805c19
children 2764148aa088 623ed0ed793e
comparison
equal deleted inserted replaced
20667:e96e9f805c19 20668:3a35ba2681ec
1057 if tmpl: 1057 if tmpl:
1058 try: 1058 try:
1059 tmpl = templater.parsestring(tmpl) 1059 tmpl = templater.parsestring(tmpl)
1060 except SyntaxError: 1060 except SyntaxError:
1061 tmpl = templater.parsestring(tmpl, quoted=False) 1061 tmpl = templater.parsestring(tmpl, quoted=False)
1062 return tmpl, None
1062 else: 1063 else:
1063 style = util.expandpath(ui.config('ui', 'style', '')) 1064 style = util.expandpath(ui.config('ui', 'style', ''))
1064 1065
1065 if style: 1066 if style:
1066 mapfile = style 1067 mapfile = style
1069 or templater.templatepath(mapfile)) 1070 or templater.templatepath(mapfile))
1070 if mapname: 1071 if mapname:
1071 mapfile = mapname 1072 mapfile = mapname
1072 return None, mapfile 1073 return None, mapfile
1073 1074
1075 if not tmpl:
1076 return None, None
1077
1078 # looks like a literal template?
1079 if '{' in tmpl:
1080 return tmpl, None
1081
1082 # perhaps a stock style?
1083 if not os.path.split(tmpl)[0]:
1084 mapname = (templater.templatepath('map-cmdline.' + tmpl)
1085 or templater.templatepath(tmpl))
1086 if mapname and os.path.isfile(mapname):
1087 return None, mapname
1088
1089 # perhaps it's a reference to [templates]
1090 t = ui.config('templates', tmpl)
1091 if t:
1092 try:
1093 tmpl = templater.parsestring(t)
1094 except SyntaxError:
1095 tmpl = templater.parsestring(t, quoted=False)
1096 return tmpl, None
1097
1098 # perhaps it's a path to a map or a template
1099 if ('/' in tmpl or '\\' in tmpl) and os.path.isfile(tmpl):
1100 # is it a mapfile for a style?
1101 if os.path.basename(tmpl).startswith("map-"):
1102 return None, os.path.realpath(tmpl)
1103 tmpl = open(tmpl).read()
1104 return tmpl, None
1105
1106 # constant string?
1074 return tmpl, None 1107 return tmpl, None
1075 1108
1076 def show_changeset(ui, repo, opts, buffered=False): 1109 def show_changeset(ui, repo, opts, buffered=False):
1077 """show one changeset using template or regular display. 1110 """show one changeset using template or regular display.
1078 1111