##// END OF EJS Templates
templating: make -T much more flexible...
Matt Mackall -
r20668:3a35ba26 default
parent child Browse files
Show More
@@ -218,7 +218,7 b' class kwtemplater(object):'
218 218 '''Replaces keywords in data with expanded template.'''
219 219 def kwsub(mobj):
220 220 kw = mobj.group(1)
221 ct = cmdutil.changeset_templater(self.ui, self.repo, False, None
221 ct = cmdutil.changeset_templater(self.ui, self.repo, False, None,
222 222 self.templates[kw], '', False)
223 223 self.ui.pushbuffer()
224 224 ct.show(ctx, root=self.repo.root, file=path)
@@ -1059,6 +1059,7 b' def gettemplate(ui, tmpl, style):'
1059 1059 tmpl = templater.parsestring(tmpl)
1060 1060 except SyntaxError:
1061 1061 tmpl = templater.parsestring(tmpl, quoted=False)
1062 return tmpl, None
1062 1063 else:
1063 1064 style = util.expandpath(ui.config('ui', 'style', ''))
1064 1065
@@ -1071,6 +1072,38 b' def gettemplate(ui, tmpl, style):'
1071 1072 mapfile = mapname
1072 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 1107 return tmpl, None
1075 1108
1076 1109 def show_changeset(ui, repo, opts, buffered=False):
@@ -63,6 +63,29 b' Make sure user/global hgrc does not affe'
63 63 $ echo 'logtemplate =' >> .hg/hgrc
64 64 $ echo 'style =' >> .hg/hgrc
65 65
66 Add some simple styles to settings
67
68 $ echo '[templates]' >> .hg/hgrc
69 $ printf 'simple = "{rev}\\n"\n' >> .hg/hgrc
70 $ printf 'simple2 = {rev}\\n\n' >> .hg/hgrc
71
72 $ hg log -l1 -Tsimple
73 8
74 $ hg log -l1 -Tsimple2
75 8
76
77 Test templates and style maps in files:
78
79 $ echo "{rev}" > tmpl
80 $ hg log -l1 -T./tmpl
81 8
82 $ hg log -l1 -Tblah/blah
83 blah/blah (no-eol)
84
85 $ printf 'changeset = "{rev}\\n"\n' > map-simple
86 $ hg log -l1 -T./map-simple
87 8
88
66 89 Default style is like normal output:
67 90
68 91 $ hg log > log.out
@@ -84,7 +107,7 b' Revision with no copies (used to print a'
84 107
85 108 Compact style works:
86 109
87 $ hg log --style compact
110 $ hg log -Tcompact
88 111 8[tip] 95c24699272e 2020-01-01 10:01 +0000 test
89 112 third
90 113
General Comments 0
You need to be logged in to leave comments. Login now