comparison mercurial/hgweb/webcommands.py @ 28211:446465888119

hgweb: add option to convert encoding of graphdata() Because future patches will change "|json" filter to handle input bytes transparently, i.e. use UTF-8b encoding, "{jsdata}" must keep data in UTF-8 bytes, whereas "{nodes}" are text. This patch inserts encodestr() where localstr is likely to survive.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 04 Jan 2016 23:05:09 +0900
parents 964ad57eff30
children d4419c01532b
comparison
equal deleted inserted replaced
28210:964ad57eff30 28211:446465888119
1133 continue 1133 continue
1134 cols = max(cols, max([edge[0] for edge in edges] or [0]), 1134 cols = max(cols, max([edge[0] for edge in edges] or [0]),
1135 max([edge[1] for edge in edges] or [0])) 1135 max([edge[1] for edge in edges] or [0]))
1136 return cols 1136 return cols
1137 1137
1138 def graphdata(usetuples): 1138 def graphdata(usetuples, encodestr):
1139 data = [] 1139 data = []
1140 1140
1141 row = 0 1141 row = 0
1142 for (id, type, ctx, vtx, edges) in tree: 1142 for (id, type, ctx, vtx, edges) in tree:
1143 if type != graphmod.CHANGESET: 1143 if type != graphmod.CHANGESET:
1144 continue 1144 continue
1145 node = str(ctx) 1145 node = str(ctx)
1146 age = templatefilters.age(ctx.date()) 1146 age = encodestr(templatefilters.age(ctx.date()))
1147 desc = templatefilters.firstline(ctx.description()) 1147 desc = templatefilters.firstline(encodestr(ctx.description()))
1148 desc = cgi.escape(templatefilters.nonempty(desc)) 1148 desc = cgi.escape(templatefilters.nonempty(desc))
1149 user = cgi.escape(templatefilters.person(ctx.user())) 1149 user = cgi.escape(templatefilters.person(encodestr(ctx.user())))
1150 branch = cgi.escape(ctx.branch()) 1150 branch = cgi.escape(encodestr(ctx.branch()))
1151 try: 1151 try:
1152 branchnode = web.repo.branchtip(branch) 1152 branchnode = web.repo.branchtip(branch)
1153 except error.RepoLookupError: 1153 except error.RepoLookupError:
1154 branchnode = None 1154 branchnode = None
1155 branch = branch, branchnode == ctx.node() 1155 branch = branch, branchnode == ctx.node()
1156 1156
1157 if usetuples: 1157 if usetuples:
1158 data.append((node, vtx, edges, desc, user, age, branch, 1158 data.append((node, vtx, edges, desc, user, age, branch,
1159 [cgi.escape(x) for x in ctx.tags()], 1159 [cgi.escape(encodestr(x)) for x in ctx.tags()],
1160 [cgi.escape(x) for x in ctx.bookmarks()])) 1160 [cgi.escape(encodestr(x))
1161 for x in ctx.bookmarks()]))
1161 else: 1162 else:
1162 edgedata = [{'col': edge[0], 'nextcol': edge[1], 1163 edgedata = [{'col': edge[0], 'nextcol': edge[1],
1163 'color': (edge[2] - 1) % 6 + 1, 1164 'color': (edge[2] - 1) % 6 + 1,
1164 'width': edge[3], 'bcolor': edge[4]} 1165 'width': edge[3], 'bcolor': edge[4]}
1165 for edge in edges] 1166 for edge in edges]
1193 lessvars=lessvars, morevars=morevars, downrev=downrev, 1194 lessvars=lessvars, morevars=morevars, downrev=downrev,
1194 cols=cols, rows=rows, 1195 cols=cols, rows=rows,
1195 canvaswidth=(cols + 1) * bg_height, 1196 canvaswidth=(cols + 1) * bg_height,
1196 truecanvasheight=rows * bg_height, 1197 truecanvasheight=rows * bg_height,
1197 canvasheight=canvasheight, bg_height=bg_height, 1198 canvasheight=canvasheight, bg_height=bg_height,
1198 jsdata=lambda **x: graphdata(True), 1199 jsdata=lambda **x: graphdata(True, str),
1199 nodes=lambda **x: graphdata(False), 1200 nodes=lambda **x: graphdata(False, str),
1200 node=ctx.hex(), changenav=changenav) 1201 node=ctx.hex(), changenav=changenav)
1201 1202
1202 def _getdoc(e): 1203 def _getdoc(e):
1203 doc = e[0].__doc__ 1204 doc = e[0].__doc__
1204 if doc: 1205 if doc: