Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/webcommands.py @ 35566:baca93a47992
hgweb: make different kinds of commits look differently on /graph
Regular hg log -G uses different symbols for some graph nodes, such as commits
that close branches and hidden commits. It also marks the currently checked out
commit with "@". Since hg serve is sometimes used/recommended as a more visual
alternative to CLI, it makes sense to port these features to hgweb.
"graphnode" includes the style of a particular node and also if it's currently
checked out or not, both at the same time. This is different from hg log -G
(which uses templatekw.showgraphnode), where there's only place for one
character, but hgweb doesn't have this limitation, since it uses <canvas> and
not plain text. I'm using one string of 1 or 2 characters in this patch, it's
not the most self-explanatory format, but it's concise, uses the same
characters as hg log -G, and is internal to hgweb (i.e. not used for
json-graph).
I'm more or less fine with how things look visually, but there's still room for
improvement. Feel free to criticise or point me to good-looking graphs of this
kind for inspiration.
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Tue, 19 Dec 2017 20:41:25 +0800 |
parents | acd8a2454b47 |
children | 0ef50a5e3ae1 |
comparison
equal
deleted
inserted
replaced
35565:bdae51a83dfb | 35566:baca93a47992 |
---|---|
11 import mimetypes | 11 import mimetypes |
12 import os | 12 import os |
13 import re | 13 import re |
14 | 14 |
15 from ..i18n import _ | 15 from ..i18n import _ |
16 from ..node import hex, short | 16 from ..node import hex, nullid, short |
17 | 17 |
18 from .common import ( | 18 from .common import ( |
19 ErrorResponse, | 19 ErrorResponse, |
20 HTTP_FORBIDDEN, | 20 HTTP_FORBIDDEN, |
21 HTTP_NOT_FOUND, | 21 HTTP_NOT_FOUND, |
1246 dag = graphmod.dagwalker(web.repo, smartset.baseset(revs)) | 1246 dag = graphmod.dagwalker(web.repo, smartset.baseset(revs)) |
1247 # As we said one line above... not lazy. | 1247 # As we said one line above... not lazy. |
1248 tree = list(item for item in graphmod.colored(dag, web.repo) | 1248 tree = list(item for item in graphmod.colored(dag, web.repo) |
1249 if item[1] == graphmod.CHANGESET) | 1249 if item[1] == graphmod.CHANGESET) |
1250 | 1250 |
1251 def nodecurrent(ctx): | |
1252 wpnodes = web.repo.dirstate.parents() | |
1253 if wpnodes[1] == nullid: | |
1254 wpnodes = wpnodes[:1] | |
1255 if ctx.node() in wpnodes: | |
1256 return '@' | |
1257 return '' | |
1258 | |
1259 def nodesymbol(ctx): | |
1260 if ctx.obsolete(): | |
1261 return 'x' | |
1262 elif ctx.isunstable(): | |
1263 return '*' | |
1264 elif ctx.closesbranch(): | |
1265 return '_' | |
1266 else: | |
1267 return 'o' | |
1268 | |
1251 def fulltree(): | 1269 def fulltree(): |
1252 pos = web.repo[graphtop].rev() | 1270 pos = web.repo[graphtop].rev() |
1253 tree = [] | 1271 tree = [] |
1254 if pos != -1: | 1272 if pos != -1: |
1255 revs = web.repo.changelog.revs(pos, lastrev) | 1273 revs = web.repo.changelog.revs(pos, lastrev) |
1258 if item[1] == graphmod.CHANGESET) | 1276 if item[1] == graphmod.CHANGESET) |
1259 return tree | 1277 return tree |
1260 | 1278 |
1261 def jsdata(): | 1279 def jsdata(): |
1262 return [{'node': pycompat.bytestr(ctx), | 1280 return [{'node': pycompat.bytestr(ctx), |
1281 'graphnode': nodecurrent(ctx) + nodesymbol(ctx), | |
1263 'vertex': vtx, | 1282 'vertex': vtx, |
1264 'edges': edges} | 1283 'edges': edges} |
1265 for (id, type, ctx, vtx, edges) in fulltree()] | 1284 for (id, type, ctx, vtx, edges) in fulltree()] |
1266 | 1285 |
1267 def nodes(): | 1286 def nodes(): |