Mercurial > public > mercurial-scm > hg
comparison mercurial/hgweb/webcommands.py @ 37909:7fae76c2c564
hgweb: reuse graph node-related functions from templates
The difference between templatekw.getgraphnode() and webutil.getgraphnode() is
that the latter is not limited to 1 character.
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Tue, 08 May 2018 19:00:01 +0800 |
parents | 2095331ff926 |
children | 16c7a6ac8f94 |
comparison
equal
deleted
inserted
replaced
37908:8808d5d401ee | 37909:7fae76c2c564 |
---|---|
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, nullid, short | 16 from ..node import hex, 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, |
1312 dag = graphmod.dagwalker(web.repo, smartset.baseset(revs)) | 1312 dag = graphmod.dagwalker(web.repo, smartset.baseset(revs)) |
1313 # As we said one line above... not lazy. | 1313 # As we said one line above... not lazy. |
1314 tree = list(item for item in graphmod.colored(dag, web.repo) | 1314 tree = list(item for item in graphmod.colored(dag, web.repo) |
1315 if item[1] == graphmod.CHANGESET) | 1315 if item[1] == graphmod.CHANGESET) |
1316 | 1316 |
1317 def nodecurrent(ctx): | |
1318 wpnodes = web.repo.dirstate.parents() | |
1319 if wpnodes[1] == nullid: | |
1320 wpnodes = wpnodes[:1] | |
1321 if ctx.node() in wpnodes: | |
1322 return '@' | |
1323 return '' | |
1324 | |
1325 def nodesymbol(ctx): | |
1326 if ctx.obsolete(): | |
1327 return 'x' | |
1328 elif ctx.isunstable(): | |
1329 return '*' | |
1330 elif ctx.closesbranch(): | |
1331 return '_' | |
1332 else: | |
1333 return 'o' | |
1334 | |
1335 def fulltree(): | 1317 def fulltree(): |
1336 pos = web.repo[graphtop].rev() | 1318 pos = web.repo[graphtop].rev() |
1337 tree = [] | 1319 tree = [] |
1338 if pos != -1: | 1320 if pos != -1: |
1339 revs = web.repo.changelog.revs(pos, lastrev) | 1321 revs = web.repo.changelog.revs(pos, lastrev) |
1342 if item[1] == graphmod.CHANGESET) | 1324 if item[1] == graphmod.CHANGESET) |
1343 return tree | 1325 return tree |
1344 | 1326 |
1345 def jsdata(): | 1327 def jsdata(): |
1346 return [{'node': pycompat.bytestr(ctx), | 1328 return [{'node': pycompat.bytestr(ctx), |
1347 'graphnode': nodecurrent(ctx) + nodesymbol(ctx), | 1329 'graphnode': webutil.getgraphnode(web.repo, ctx), |
1348 'vertex': vtx, | 1330 'vertex': vtx, |
1349 'edges': edges} | 1331 'edges': edges} |
1350 for (id, type, ctx, vtx, edges) in fulltree()] | 1332 for (id, type, ctx, vtx, edges) in fulltree()] |
1351 | 1333 |
1352 def nodes(): | 1334 def nodes(): |