Show More
@@ -30,7 +30,6 b' from __future__ import absolute_import' | |||
|
30 | 30 | |
|
31 | 31 | from . import highlight |
|
32 | 32 | from mercurial.hgweb import ( |
|
33 | common, | |
|
34 | 33 | webcommands, |
|
35 | 34 | webutil, |
|
36 | 35 | ) |
@@ -84,9 +83,12 b' def annotate_highlight(orig, web, req, t' | |||
|
84 | 83 | def generate_css(web, req, tmpl): |
|
85 | 84 | pg_style = web.config('web', 'pygments_style', 'colorful') |
|
86 | 85 | fmter = highlight.HtmlFormatter(style=pg_style) |
|
87 | req.respond(common.HTTP_OK, 'text/css') | |
|
88 | return ['/* pygments_style = %s */\n\n' % pg_style, | |
|
89 | fmter.get_style_defs('')] | |
|
86 | web.res.headers['Content-Type'] = 'text/css' | |
|
87 | web.res.setbodybytes(''.join([ | |
|
88 | '/* pygments_style = %s */\n\n' % pg_style, | |
|
89 | fmter.get_style_defs(''), | |
|
90 | ])) | |
|
91 | return web.res | |
|
90 | 92 | |
|
91 | 93 | def extsetup(): |
|
92 | 94 | # monkeypatch in the new version |
@@ -400,8 +400,11 b' class hgweb(object):' | |||
|
400 | 400 | msg = 'no such method: %s' % cmd |
|
401 | 401 | raise ErrorResponse(HTTP_BAD_REQUEST, msg) |
|
402 | 402 | elif cmd == 'file' and req.qsparams.get('style') == 'raw': |
|
403 | rctx.ctype = ctype | |
|
403 | res.status = '200 Script output follows' | |
|
404 | res.headers['Content-Type'] = ctype | |
|
404 | 405 | content = webcommands.rawfile(rctx, wsgireq, tmpl) |
|
406 | assert content is res | |
|
407 | return res.sendresponse() | |
|
405 | 408 | else: |
|
406 | 409 | # Set some globals appropriate for web handlers. Commands can |
|
407 | 410 | # override easily enough. |
@@ -106,17 +106,13 b' def rawfile(web, req, tmpl):' | |||
|
106 | 106 | |
|
107 | 107 | path = webutil.cleanpath(web.repo, req.req.qsparams.get('file', '')) |
|
108 | 108 | if not path: |
|
109 |
|
|
|
110 | req.respond(HTTP_OK, web.ctype) | |
|
111 | return content | |
|
109 | return manifest(web, req, tmpl) | |
|
112 | 110 | |
|
113 | 111 | try: |
|
114 | 112 | fctx = webutil.filectx(web.repo, req) |
|
115 | 113 | except error.LookupError as inst: |
|
116 | 114 | try: |
|
117 |
|
|
|
118 | req.respond(HTTP_OK, web.ctype) | |
|
119 | return content | |
|
115 | return manifest(web, req, tmpl) | |
|
120 | 116 | except ErrorResponse: |
|
121 | 117 | raise inst |
|
122 | 118 | |
@@ -133,8 +129,12 b' def rawfile(web, req, tmpl):' | |||
|
133 | 129 | if mt.startswith('text/'): |
|
134 | 130 | mt += '; charset="%s"' % encoding.encoding |
|
135 | 131 | |
|
136 | req.respond(HTTP_OK, mt, path, body=text) | |
|
137 | return [] | |
|
132 | web.res.headers['Content-Type'] = mt | |
|
133 | filename = (path.rpartition('/')[-1] | |
|
134 | .replace('\\', '\\\\').replace('"', '\\"')) | |
|
135 | web.res.headers['Content-Disposition'] = 'inline; filename="%s"' % filename | |
|
136 | web.res.setbodybytes(text) | |
|
137 | return web.res | |
|
138 | 138 | |
|
139 | 139 | def _filerevision(web, req, tmpl, fctx): |
|
140 | 140 | f = fctx.path() |
@@ -153,15 +153,18 b' def _filerevision(web, req, tmpl, fctx):' | |||
|
153 | 153 | "linenumber": "% 6d" % (lineno + 1), |
|
154 | 154 | "parity": next(parity)} |
|
155 | 155 | |
|
156 | return tmpl("filerevision", | |
|
157 | file=f, | |
|
158 | path=webutil.up(f), | |
|
159 | text=lines(), | |
|
160 | symrev=webutil.symrevorshortnode(req, fctx), | |
|
161 |
|
|
|
162 | permissions=fctx.manifest().flags(f), | |
|
163 | ishead=int(ishead), | |
|
164 | **pycompat.strkwargs(webutil.commonentry(web.repo, fctx))) | |
|
156 | web.res.setbodygen(tmpl( | |
|
157 | 'filerevision', | |
|
158 | file=f, | |
|
159 | path=webutil.up(f), | |
|
160 | text=lines(), | |
|
161 | symrev=webutil.symrevorshortnode(req, fctx), | |
|
162 | rename=webutil.renamelink(fctx), | |
|
163 | permissions=fctx.manifest().flags(f), | |
|
164 | ishead=int(ishead), | |
|
165 | **pycompat.strkwargs(webutil.commonentry(web.repo, fctx)))) | |
|
166 | ||
|
167 | return web.res | |
|
165 | 168 | |
|
166 | 169 | @webcommand('file') |
|
167 | 170 | def file(web, req, tmpl): |
@@ -335,11 +338,20 b' def _search(web, req, tmpl):' | |||
|
335 | 338 | tip = web.repo['tip'] |
|
336 | 339 | parity = paritygen(web.stripecount) |
|
337 | 340 | |
|
338 | return tmpl('search', query=query, node=tip.hex(), symrev='tip', | |
|
339 | entries=changelist, archives=web.archivelist("tip"), | |
|
340 | morevars=morevars, lessvars=lessvars, | |
|
341 | modedesc=searchfunc[1], | |
|
342 | showforcekw=showforcekw, showunforcekw=showunforcekw) | |
|
341 | web.res.setbodygen(tmpl( | |
|
342 | 'search', | |
|
343 | query=query, | |
|
344 | node=tip.hex(), | |
|
345 | symrev='tip', | |
|
346 | entries=changelist, | |
|
347 | archives=web.archivelist('tip'), | |
|
348 | morevars=morevars, | |
|
349 | lessvars=lessvars, | |
|
350 | modedesc=searchfunc[1], | |
|
351 | showforcekw=showforcekw, | |
|
352 | showunforcekw=showunforcekw)) | |
|
353 | ||
|
354 | return web.res | |
|
343 | 355 | |
|
344 | 356 | @webcommand('changelog') |
|
345 | 357 | def changelog(web, req, tmpl, shortlog=False): |
@@ -423,12 +435,23 b' def changelog(web, req, tmpl, shortlog=F' | |||
|
423 | 435 | else: |
|
424 | 436 | nextentry = [] |
|
425 | 437 | |
|
426 | return tmpl('shortlog' if shortlog else 'changelog', changenav=changenav, | |
|
427 | node=ctx.hex(), rev=pos, symrev=symrev, changesets=count, | |
|
428 | entries=entries, | |
|
429 | latestentry=latestentry, nextentry=nextentry, | |
|
430 | archives=web.archivelist("tip"), revcount=revcount, | |
|
431 | morevars=morevars, lessvars=lessvars, query=query) | |
|
438 | web.res.setbodygen(tmpl( | |
|
439 | 'shortlog' if shortlog else 'changelog', | |
|
440 | changenav=changenav, | |
|
441 | node=ctx.hex(), | |
|
442 | rev=pos, | |
|
443 | symrev=symrev, | |
|
444 | changesets=count, | |
|
445 | entries=entries, | |
|
446 | latestentry=latestentry, | |
|
447 | nextentry=nextentry, | |
|
448 | archives=web.archivelist('tip'), | |
|
449 | revcount=revcount, | |
|
450 | morevars=morevars, | |
|
451 | lessvars=lessvars, | |
|
452 | query=query)) | |
|
453 | ||
|
454 | return web.res | |
|
432 | 455 | |
|
433 | 456 | @webcommand('shortlog') |
|
434 | 457 | def shortlog(web, req, tmpl): |
@@ -461,8 +484,9 b' def changeset(web, req, tmpl):' | |||
|
461 | 484 | templates related to diffs may all be used to produce the output. |
|
462 | 485 | """ |
|
463 | 486 | ctx = webutil.changectx(web.repo, req) |
|
464 | ||
|
465 |
|
|
|
487 | web.res.setbodygen(tmpl('changeset', | |
|
488 | **webutil.changesetentry(web, req, tmpl, ctx))) | |
|
489 | return web.res | |
|
466 | 490 | |
|
467 | 491 | rev = webcommand('rev')(changeset) |
|
468 | 492 | |
@@ -563,15 +587,18 b' def manifest(web, req, tmpl):' | |||
|
563 | 587 | "emptydirs": "/".join(emptydirs), |
|
564 | 588 | "basename": d} |
|
565 | 589 | |
|
566 | return tmpl("manifest", | |
|
567 | symrev=symrev, | |
|
568 | path=abspath, | |
|
569 |
|
|
|
570 | upparity=next(parity), | |
|
571 | fentries=filelist, | |
|
572 |
|
|
|
573 | archives=web.archivelist(hex(node)), | |
|
574 | **pycompat.strkwargs(webutil.commonentry(web.repo, ctx))) | |
|
590 | web.res.setbodygen(tmpl( | |
|
591 | 'manifest', | |
|
592 | symrev=symrev, | |
|
593 | path=abspath, | |
|
594 | up=webutil.up(abspath), | |
|
595 | upparity=next(parity), | |
|
596 | fentries=filelist, | |
|
597 | dentries=dirlist, | |
|
598 | archives=web.archivelist(hex(node)), | |
|
599 | **pycompat.strkwargs(webutil.commonentry(web.repo, ctx)))) | |
|
600 | ||
|
601 | return web.res | |
|
575 | 602 | |
|
576 | 603 | @webcommand('tags') |
|
577 | 604 | def tags(web, req, tmpl): |
@@ -600,11 +627,14 b' def tags(web, req, tmpl):' | |||
|
600 | 627 | "date": web.repo[n].date(), |
|
601 | 628 | "node": hex(n)} |
|
602 | 629 | |
|
603 | return tmpl("tags", | |
|
604 | node=hex(web.repo.changelog.tip()), | |
|
605 | entries=lambda **x: entries(False, False, **x), | |
|
606 |
|
|
|
607 |
|
|
|
630 | web.res.setbodygen(tmpl( | |
|
631 | 'tags', | |
|
632 | node=hex(web.repo.changelog.tip()), | |
|
633 | entries=lambda **x: entries(False, False, **x), | |
|
634 | entriesnotip=lambda **x: entries(True, False, **x), | |
|
635 | latestentry=lambda **x: entries(True, True, **x))) | |
|
636 | ||
|
637 | return web.res | |
|
608 | 638 | |
|
609 | 639 | @webcommand('bookmarks') |
|
610 | 640 | def bookmarks(web, req, tmpl): |
@@ -638,11 +668,14 b' def bookmarks(web, req, tmpl):' | |||
|
638 | 668 | else: |
|
639 | 669 | latestrev = -1 |
|
640 | 670 | |
|
641 | return tmpl("bookmarks", | |
|
642 | node=hex(web.repo.changelog.tip()), | |
|
643 | lastchange=[{"date": web.repo[latestrev].date()}], | |
|
644 | entries=lambda **x: entries(latestonly=False, **x), | |
|
645 |
|
|
|
671 | web.res.setbodygen(tmpl( | |
|
672 | 'bookmarks', | |
|
673 | node=hex(web.repo.changelog.tip()), | |
|
674 | lastchange=[{'date': web.repo[latestrev].date()}], | |
|
675 | entries=lambda **x: entries(latestonly=False, **x), | |
|
676 | latestentry=lambda **x: entries(latestonly=True, **x))) | |
|
677 | ||
|
678 | return web.res | |
|
646 | 679 | |
|
647 | 680 | @webcommand('branches') |
|
648 | 681 | def branches(web, req, tmpl): |
@@ -660,8 +693,14 b' def branches(web, req, tmpl):' | |||
|
660 | 693 | """ |
|
661 | 694 | entries = webutil.branchentries(web.repo, web.stripecount) |
|
662 | 695 | latestentry = webutil.branchentries(web.repo, web.stripecount, 1) |
|
663 | return tmpl('branches', node=hex(web.repo.changelog.tip()), | |
|
664 | entries=entries, latestentry=latestentry) | |
|
696 | ||
|
697 | web.res.setbodygen(tmpl( | |
|
698 | 'branches', | |
|
699 | node=hex(web.repo.changelog.tip()), | |
|
700 | entries=entries, | |
|
701 | latestentry=latestentry)) | |
|
702 | ||
|
703 | return web.res | |
|
665 | 704 | |
|
666 | 705 | @webcommand('summary') |
|
667 | 706 | def summary(web, req, tmpl): |
@@ -731,18 +770,22 b' def summary(web, req, tmpl):' | |||
|
731 | 770 | desc = web.config("web", "description") |
|
732 | 771 | if not desc: |
|
733 | 772 | desc = 'unknown' |
|
734 | return tmpl("summary", | |
|
735 | desc=desc, | |
|
736 | owner=get_contact(web.config) or "unknown", | |
|
737 | lastchange=tip.date(), | |
|
738 | tags=tagentries, | |
|
739 | bookmarks=bookmarks, | |
|
740 | branches=webutil.branchentries(web.repo, web.stripecount, 10), | |
|
741 | shortlog=changelist, | |
|
742 | node=tip.hex(), | |
|
743 | symrev='tip', | |
|
744 | archives=web.archivelist("tip"), | |
|
745 | labels=web.configlist('web', 'labels')) | |
|
773 | ||
|
774 | web.res.setbodygen(tmpl( | |
|
775 | 'summary', | |
|
776 | desc=desc, | |
|
777 | owner=get_contact(web.config) or 'unknown', | |
|
778 | lastchange=tip.date(), | |
|
779 | tags=tagentries, | |
|
780 | bookmarks=bookmarks, | |
|
781 | branches=webutil.branchentries(web.repo, web.stripecount, 10), | |
|
782 | shortlog=changelist, | |
|
783 | node=tip.hex(), | |
|
784 | symrev='tip', | |
|
785 | archives=web.archivelist('tip'), | |
|
786 | labels=web.configlist('web', 'labels'))) | |
|
787 | ||
|
788 | return web.res | |
|
746 | 789 | |
|
747 | 790 | @webcommand('filediff') |
|
748 | 791 | def filediff(web, req, tmpl): |
@@ -782,12 +825,16 b' def filediff(web, req, tmpl):' | |||
|
782 | 825 | else: |
|
783 | 826 | rename = [] |
|
784 | 827 | ctx = ctx |
|
785 | return tmpl("filediff", | |
|
786 | file=path, | |
|
787 | symrev=webutil.symrevorshortnode(req, ctx), | |
|
788 | rename=rename, | |
|
789 | diff=diffs, | |
|
790 | **pycompat.strkwargs(webutil.commonentry(web.repo, ctx))) | |
|
828 | ||
|
829 | web.res.setbodygen(tmpl( | |
|
830 | 'filediff', | |
|
831 | file=path, | |
|
832 | symrev=webutil.symrevorshortnode(req, ctx), | |
|
833 | rename=rename, | |
|
834 | diff=diffs, | |
|
835 | **pycompat.strkwargs(webutil.commonentry(web.repo, ctx)))) | |
|
836 | ||
|
837 | return web.res | |
|
791 | 838 | |
|
792 | 839 | diff = webcommand('diff')(filediff) |
|
793 | 840 | |
@@ -853,16 +900,20 b' def comparison(web, req, tmpl):' | |||
|
853 | 900 | else: |
|
854 | 901 | rename = [] |
|
855 | 902 | ctx = ctx |
|
856 | return tmpl('filecomparison', | |
|
857 | file=path, | |
|
858 | symrev=webutil.symrevorshortnode(req, ctx), | |
|
859 | rename=rename, | |
|
860 | leftrev=leftrev, | |
|
861 | leftnode=hex(leftnode), | |
|
862 |
|
|
|
863 |
|
|
|
864 | comparison=comparison, | |
|
865 | **pycompat.strkwargs(webutil.commonentry(web.repo, ctx))) | |
|
903 | ||
|
904 | web.res.setbodygen(tmpl( | |
|
905 | 'filecomparison', | |
|
906 | file=path, | |
|
907 | symrev=webutil.symrevorshortnode(req, ctx), | |
|
908 | rename=rename, | |
|
909 | leftrev=leftrev, | |
|
910 | leftnode=hex(leftnode), | |
|
911 | rightrev=rightrev, | |
|
912 | rightnode=hex(rightnode), | |
|
913 | comparison=comparison, | |
|
914 | **pycompat.strkwargs(webutil.commonentry(web.repo, ctx)))) | |
|
915 | ||
|
916 | return web.res | |
|
866 | 917 | |
|
867 | 918 | @webcommand('annotate') |
|
868 | 919 | def annotate(web, req, tmpl): |
@@ -944,16 +995,19 b' def annotate(web, req, tmpl):' | |||
|
944 | 995 | diffopts = webutil.difffeatureopts(req, web.repo.ui, 'annotate') |
|
945 | 996 | diffopts = {k: getattr(diffopts, k) for k in diffopts.defaults} |
|
946 | 997 | |
|
947 | return tmpl("fileannotate", | |
|
948 | file=f, | |
|
949 | annotate=annotate, | |
|
950 | path=webutil.up(f), | |
|
951 | symrev=webutil.symrevorshortnode(req, fctx), | |
|
952 |
|
|
|
953 | permissions=fctx.manifest().flags(f), | |
|
954 | ishead=int(ishead), | |
|
955 | diffopts=diffopts, | |
|
956 | **pycompat.strkwargs(webutil.commonentry(web.repo, fctx))) | |
|
998 | web.res.setbodygen(tmpl( | |
|
999 | 'fileannotate', | |
|
1000 | file=f, | |
|
1001 | annotate=annotate, | |
|
1002 | path=webutil.up(f), | |
|
1003 | symrev=webutil.symrevorshortnode(req, fctx), | |
|
1004 | rename=webutil.renamelink(fctx), | |
|
1005 | permissions=fctx.manifest().flags(f), | |
|
1006 | ishead=int(ishead), | |
|
1007 | diffopts=diffopts, | |
|
1008 | **pycompat.strkwargs(webutil.commonentry(web.repo, fctx)))) | |
|
1009 | ||
|
1010 | return web.res | |
|
957 | 1011 | |
|
958 | 1012 | @webcommand('filelog') |
|
959 | 1013 | def filelog(web, req, tmpl): |
@@ -1318,17 +1372,26 b' def graph(web, req, tmpl):' | |||
|
1318 | 1372 | |
|
1319 | 1373 | rows = len(tree) |
|
1320 | 1374 | |
|
1321 | return tmpl('graph', rev=rev, symrev=symrev, revcount=revcount, | |
|
1322 | uprev=uprev, | |
|
1323 | lessvars=lessvars, morevars=morevars, downrev=downrev, | |
|
1324 | graphvars=graphvars, | |
|
1325 | rows=rows, | |
|
1326 | bg_height=bg_height, | |
|
1327 | changesets=count, | |
|
1328 | nextentry=nextentry, | |
|
1329 | jsdata=lambda **x: jsdata(), | |
|
1330 | nodes=lambda **x: nodes(), | |
|
1331 | node=ctx.hex(), changenav=changenav) | |
|
1375 | web.res.setbodygen(tmpl( | |
|
1376 | 'graph', | |
|
1377 | rev=rev, | |
|
1378 | symrev=symrev, | |
|
1379 | revcount=revcount, | |
|
1380 | uprev=uprev, | |
|
1381 | lessvars=lessvars, | |
|
1382 | morevars=morevars, | |
|
1383 | downrev=downrev, | |
|
1384 | graphvars=graphvars, | |
|
1385 | rows=rows, | |
|
1386 | bg_height=bg_height, | |
|
1387 | changesets=count, | |
|
1388 | nextentry=nextentry, | |
|
1389 | jsdata=lambda **x: jsdata(), | |
|
1390 | nodes=lambda **x: nodes(), | |
|
1391 | node=ctx.hex(), | |
|
1392 | changenav=changenav)) | |
|
1393 | ||
|
1394 | return web.res | |
|
1332 | 1395 | |
|
1333 | 1396 | def _getdoc(e): |
|
1334 | 1397 | doc = e[0].__doc__ |
@@ -1384,8 +1447,13 b' def help(web, req, tmpl):' | |||
|
1384 | 1447 | for c, doc in other: |
|
1385 | 1448 | yield {'topic': c, 'summary': doc} |
|
1386 | 1449 | |
|
1387 | return tmpl('helptopics', topics=topics, earlycommands=earlycommands, | |
|
1388 | othercommands=othercommands, title='Index') | |
|
1450 | web.res.setbodygen(tmpl( | |
|
1451 | 'helptopics', | |
|
1452 | topics=topics, | |
|
1453 | earlycommands=earlycommands, | |
|
1454 | othercommands=othercommands, | |
|
1455 | title='Index')) | |
|
1456 | return web.res | |
|
1389 | 1457 | |
|
1390 | 1458 | # Render an index of sub-topics. |
|
1391 | 1459 | if topicname in helpmod.subtopics: |
@@ -1397,8 +1465,12 b' def help(web, req, tmpl):' | |||
|
1397 | 1465 | 'summary': summary, |
|
1398 | 1466 | }) |
|
1399 | 1467 | |
|
1400 | return tmpl('helptopics', topics=topics, title=topicname, | |
|
1401 | subindex=True) | |
|
1468 | web.res.setbodygen(tmpl( | |
|
1469 | 'helptopics', | |
|
1470 | topics=topics, | |
|
1471 | title=topicname, | |
|
1472 | subindex=True)) | |
|
1473 | return web.res | |
|
1402 | 1474 | |
|
1403 | 1475 | u = webutil.wsgiui.load() |
|
1404 | 1476 | u.verbose = True |
@@ -1418,7 +1490,13 b' def help(web, req, tmpl):' | |||
|
1418 | 1490 | doc = helpmod.help_(u, commands, topic, subtopic=subtopic) |
|
1419 | 1491 | except error.Abort: |
|
1420 | 1492 | raise ErrorResponse(HTTP_NOT_FOUND) |
|
1421 | return tmpl('help', topic=topicname, doc=doc) | |
|
1493 | ||
|
1494 | web.res.setbodygen(tmpl( | |
|
1495 | 'help', | |
|
1496 | topic=topicname, | |
|
1497 | doc=doc)) | |
|
1498 | ||
|
1499 | return web.res | |
|
1422 | 1500 | |
|
1423 | 1501 | # tell hggettext to extract docstrings from these functions: |
|
1424 | 1502 | i18nfunctions = commands.values() |
General Comments 0
You need to be logged in to leave comments.
Login now