# HG changeset patch # User Yuya Nishihara # Date 1451916309 -32400 # Node ID 44646588811993f6388107e92f8db915852452ef # Parent 964ad57eff3033126042d1fbf2fb25b2bd39a010 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. diff -r 964ad57eff30 -r 446465888119 mercurial/hgweb/webcommands.py --- a/mercurial/hgweb/webcommands.py Mon Jan 04 22:55:05 2016 +0900 +++ b/mercurial/hgweb/webcommands.py Mon Jan 04 23:05:09 2016 +0900 @@ -1135,7 +1135,7 @@ max([edge[1] for edge in edges] or [0])) return cols - def graphdata(usetuples): + def graphdata(usetuples, encodestr): data = [] row = 0 @@ -1143,11 +1143,11 @@ if type != graphmod.CHANGESET: continue node = str(ctx) - age = templatefilters.age(ctx.date()) - desc = templatefilters.firstline(ctx.description()) + age = encodestr(templatefilters.age(ctx.date())) + desc = templatefilters.firstline(encodestr(ctx.description())) desc = cgi.escape(templatefilters.nonempty(desc)) - user = cgi.escape(templatefilters.person(ctx.user())) - branch = cgi.escape(ctx.branch()) + user = cgi.escape(templatefilters.person(encodestr(ctx.user()))) + branch = cgi.escape(encodestr(ctx.branch())) try: branchnode = web.repo.branchtip(branch) except error.RepoLookupError: @@ -1156,8 +1156,9 @@ if usetuples: data.append((node, vtx, edges, desc, user, age, branch, - [cgi.escape(x) for x in ctx.tags()], - [cgi.escape(x) for x in ctx.bookmarks()])) + [cgi.escape(encodestr(x)) for x in ctx.tags()], + [cgi.escape(encodestr(x)) + for x in ctx.bookmarks()])) else: edgedata = [{'col': edge[0], 'nextcol': edge[1], 'color': (edge[2] - 1) % 6 + 1, @@ -1195,8 +1196,8 @@ canvaswidth=(cols + 1) * bg_height, truecanvasheight=rows * bg_height, canvasheight=canvasheight, bg_height=bg_height, - jsdata=lambda **x: graphdata(True), - nodes=lambda **x: graphdata(False), + jsdata=lambda **x: graphdata(True, str), + nodes=lambda **x: graphdata(False, str), node=ctx.hex(), changenav=changenav) def _getdoc(e):