comparison mercurial/cmdutil.py @ 20666:e3eb480a9391

cmdutil: make helper function to process template args
author Matt Mackall <mpm@selenic.com>
date Sat, 08 Mar 2014 16:01:58 -0600
parents 4991cfc90f59
children e96e9f805c19
comparison
equal deleted inserted replaced
20665:945bc5497e6d 20666:e3eb480a9391
1045 msg = _("%s: no key named '%s'") 1045 msg = _("%s: no key named '%s'")
1046 raise util.Abort(msg % (self.t.mapfile, inst.args[0])) 1046 raise util.Abort(msg % (self.t.mapfile, inst.args[0]))
1047 except SyntaxError, inst: 1047 except SyntaxError, inst:
1048 raise util.Abort('%s: %s' % (self.t.mapfile, inst.args[0])) 1048 raise util.Abort('%s: %s' % (self.t.mapfile, inst.args[0]))
1049 1049
1050 def gettemplate(ui, tmpl, style):
1051 """
1052 Find the template matching the given template spec or style.
1053 """
1054
1055 # ui settings
1056 if not tmpl and not style:
1057 tmpl = ui.config('ui', 'logtemplate')
1058 if tmpl:
1059 try:
1060 tmpl = templater.parsestring(tmpl)
1061 except SyntaxError:
1062 tmpl = templater.parsestring(tmpl, quoted=False)
1063 else:
1064 style = util.expandpath(ui.config('ui', 'style', ''))
1065
1066 if style:
1067 mapfile = style
1068 if not os.path.split(mapfile)[0]:
1069 mapname = (templater.templatepath('map-cmdline.' + mapfile)
1070 or templater.templatepath(mapfile))
1071 if mapname:
1072 mapfile = mapname
1073 return None, mapfile
1074
1075 return tmpl, None
1076
1050 def show_changeset(ui, repo, opts, buffered=False): 1077 def show_changeset(ui, repo, opts, buffered=False):
1051 """show one changeset using template or regular display. 1078 """show one changeset using template or regular display.
1052 1079
1053 Display format will be the first non-empty hit of: 1080 Display format will be the first non-empty hit of:
1054 1. option 'template' 1081 1. option 'template'
1061 # options 1088 # options
1062 patch = None 1089 patch = None
1063 if opts.get('patch') or opts.get('stat'): 1090 if opts.get('patch') or opts.get('stat'):
1064 patch = scmutil.matchall(repo) 1091 patch = scmutil.matchall(repo)
1065 1092
1066 tmpl = opts.get('template') 1093 tmpl, mapfile = gettemplate(ui, opts.get('template'), opts.get('style'))
1067 style = None 1094
1068 if not tmpl: 1095 if not tmpl and not mapfile:
1069 style = opts.get('style')
1070
1071 # ui settings
1072 if not (tmpl or style):
1073 tmpl = ui.config('ui', 'logtemplate')
1074 if tmpl:
1075 try:
1076 tmpl = templater.parsestring(tmpl)
1077 except SyntaxError:
1078 tmpl = templater.parsestring(tmpl, quoted=False)
1079 else:
1080 style = util.expandpath(ui.config('ui', 'style', ''))
1081
1082 if not (tmpl or style):
1083 return changeset_printer(ui, repo, patch, opts, buffered) 1096 return changeset_printer(ui, repo, patch, opts, buffered)
1084
1085 mapfile = None
1086 if style and not tmpl:
1087 mapfile = style
1088 if not os.path.split(mapfile)[0]:
1089 mapname = (templater.templatepath('map-cmdline.' + mapfile)
1090 or templater.templatepath(mapfile))
1091 if mapname:
1092 mapfile = mapname
1093 1097
1094 try: 1098 try:
1095 t = changeset_templater(ui, repo, patch, opts, mapfile, buffered) 1099 t = changeset_templater(ui, repo, patch, opts, mapfile, buffered)
1096 except SyntaxError, inst: 1100 except SyntaxError, inst:
1097 raise util.Abort(inst.args[0]) 1101 raise util.Abort(inst.args[0])