Show More
@@ -19,21 +19,36 b' from mercurial.i18n import _' | |||
|
19 | 19 | from mercurial.error import ParseError, RepoLookupError, Abort |
|
20 | 20 | from mercurial import revset |
|
21 | 21 | |
|
22 | # __all__ is populated with the allowed commands. Be sure to add to it if | |
|
23 | # you're adding a new command, or the new command won't work. | |
|
22 | __all__ = [] | |
|
23 | ||
|
24 | class webcommand(object): | |
|
25 | """Decorator used to register a web command handler. | |
|
26 | ||
|
27 | The decorator takes as its positional arguments the name/path the | |
|
28 | command should be accessible under. | |
|
29 | ||
|
30 | Usage: | |
|
24 | 31 |
|
|
25 | __all__ = [ | |
|
26 | 'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev', | |
|
27 | 'manifest', 'tags', 'bookmarks', 'branches', 'summary', 'filediff', 'diff', | |
|
28 | 'comparison', 'annotate', 'filelog', 'archive', 'static', 'graph', 'help', | |
|
29 | ] | |
|
32 | @webcommand('mycommand') | |
|
33 | def mycommand(web, req, tmpl): | |
|
34 | pass | |
|
35 | """ | |
|
30 | 36 | |
|
37 | def __init__(self, name): | |
|
38 | self.name = name | |
|
39 | ||
|
40 | def __call__(self, func): | |
|
41 | __all__.append(self.name) | |
|
42 | return func | |
|
43 | ||
|
44 | @webcommand('log') | |
|
31 | 45 | def log(web, req, tmpl): |
|
32 | 46 | if 'file' in req.form and req.form['file'][0]: |
|
33 | 47 | return filelog(web, req, tmpl) |
|
34 | 48 | else: |
|
35 | 49 | return changelog(web, req, tmpl) |
|
36 | 50 | |
|
51 | @webcommand('rawfile') | |
|
37 | 52 | def rawfile(web, req, tmpl): |
|
38 | 53 | guessmime = web.configbool('web', 'guessmime', False) |
|
39 | 54 | |
@@ -98,6 +113,7 b' def _filerevision(web, tmpl, fctx):' | |||
|
98 | 113 | rename=webutil.renamelink(fctx), |
|
99 | 114 | permissions=fctx.manifest().flags(f)) |
|
100 | 115 | |
|
116 | @webcommand('file') | |
|
101 | 117 | def file(web, req, tmpl): |
|
102 | 118 | path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
|
103 | 119 | if not path: |
@@ -267,6 +283,7 b' def _search(web, req, tmpl):' | |||
|
267 | 283 | modedesc=searchfunc[1], |
|
268 | 284 | showforcekw=showforcekw, showunforcekw=showunforcekw) |
|
269 | 285 | |
|
286 | @webcommand('changelog') | |
|
270 | 287 | def changelog(web, req, tmpl, shortlog=False): |
|
271 | 288 | |
|
272 | 289 | query = '' |
@@ -326,9 +343,11 b' def changelog(web, req, tmpl, shortlog=F' | |||
|
326 | 343 | archives=web.archivelist("tip"), revcount=revcount, |
|
327 | 344 | morevars=morevars, lessvars=lessvars, query=query) |
|
328 | 345 | |
|
346 | @webcommand('shortlog') | |
|
329 | 347 | def shortlog(web, req, tmpl): |
|
330 | 348 | return changelog(web, req, tmpl, shortlog=True) |
|
331 | 349 | |
|
350 | @webcommand('changeset') | |
|
332 | 351 | def changeset(web, req, tmpl): |
|
333 | 352 | ctx = webutil.changectx(web.repo, req) |
|
334 | 353 | basectx = webutil.basechangectx(web.repo, req) |
@@ -382,7 +401,7 b' def changeset(web, req, tmpl):' | |||
|
382 | 401 | inbranch=webutil.nodeinbranch(web.repo, ctx), |
|
383 | 402 | branches=webutil.nodebranchdict(web.repo, ctx)) |
|
384 | 403 | |
|
385 | rev = changeset | |
|
404 | rev = webcommand('rev')(changeset) | |
|
386 | 405 | |
|
387 | 406 | def decodepath(path): |
|
388 | 407 | """Hook for mapping a path in the repository to a path in the |
@@ -392,6 +411,7 b' def decodepath(path):' | |||
|
392 | 411 | the virtual file system presented by the manifest command below.""" |
|
393 | 412 | return path |
|
394 | 413 | |
|
414 | @webcommand('manifest') | |
|
395 | 415 | def manifest(web, req, tmpl): |
|
396 | 416 | ctx = webutil.changectx(web.repo, req) |
|
397 | 417 | path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
@@ -474,6 +494,7 b' def manifest(web, req, tmpl):' | |||
|
474 | 494 | inbranch=webutil.nodeinbranch(web.repo, ctx), |
|
475 | 495 | branches=webutil.nodebranchdict(web.repo, ctx)) |
|
476 | 496 | |
|
497 | @webcommand('tags') | |
|
477 | 498 | def tags(web, req, tmpl): |
|
478 | 499 | i = list(reversed(web.repo.tagslist())) |
|
479 | 500 | parity = paritygen(web.stripecount) |
@@ -496,6 +517,7 b' def tags(web, req, tmpl):' | |||
|
496 | 517 | entriesnotip=lambda **x: entries(True, False, **x), |
|
497 | 518 | latestentry=lambda **x: entries(True, True, **x)) |
|
498 | 519 | |
|
520 | @webcommand('bookmarks') | |
|
499 | 521 | def bookmarks(web, req, tmpl): |
|
500 | 522 | i = [b for b in web.repo._bookmarks.items() if b[1] in web.repo] |
|
501 | 523 | parity = paritygen(web.stripecount) |
@@ -516,6 +538,7 b' def bookmarks(web, req, tmpl):' | |||
|
516 | 538 | entries=lambda **x: entries(latestonly=False, **x), |
|
517 | 539 | latestentry=lambda **x: entries(latestonly=True, **x)) |
|
518 | 540 | |
|
541 | @webcommand('branches') | |
|
519 | 542 | def branches(web, req, tmpl): |
|
520 | 543 | tips = [] |
|
521 | 544 | heads = web.repo.heads() |
@@ -547,6 +570,7 b' def branches(web, req, tmpl):' | |||
|
547 | 570 | entries=lambda **x: entries(0, **x), |
|
548 | 571 | latestentry=lambda **x: entries(1, **x)) |
|
549 | 572 | |
|
573 | @webcommand('summary') | |
|
550 | 574 | def summary(web, req, tmpl): |
|
551 | 575 | i = reversed(web.repo.tagslist()) |
|
552 | 576 | |
@@ -632,6 +656,7 b' def summary(web, req, tmpl):' | |||
|
632 | 656 | node=tip.hex(), |
|
633 | 657 | archives=web.archivelist("tip")) |
|
634 | 658 | |
|
659 | @webcommand('filediff') | |
|
635 | 660 | def filediff(web, req, tmpl): |
|
636 | 661 | fctx, ctx = None, None |
|
637 | 662 | try: |
@@ -672,8 +697,9 b' def filediff(web, req, tmpl):' | |||
|
672 | 697 | child=webutil.children(ctx), |
|
673 | 698 | diff=diffs) |
|
674 | 699 | |
|
675 | diff = filediff | |
|
700 | diff = webcommand('diff')(filediff) | |
|
676 | 701 | |
|
702 | @webcommand('comparison') | |
|
677 | 703 | def comparison(web, req, tmpl): |
|
678 | 704 | ctx = webutil.changectx(web.repo, req) |
|
679 | 705 | if 'file' not in req.form: |
@@ -732,6 +758,7 b' def comparison(web, req, tmpl):' | |||
|
732 | 758 | rightnode=hex(rightnode), |
|
733 | 759 | comparison=comparison) |
|
734 | 760 | |
|
761 | @webcommand('annotate') | |
|
735 | 762 | def annotate(web, req, tmpl): |
|
736 | 763 | fctx = webutil.filectx(web.repo, req) |
|
737 | 764 | f = fctx.path() |
@@ -784,6 +811,7 b' def annotate(web, req, tmpl):' | |||
|
784 | 811 | child=webutil.children(fctx), |
|
785 | 812 | permissions=fctx.manifest().flags(f)) |
|
786 | 813 | |
|
814 | @webcommand('filelog') | |
|
787 | 815 | def filelog(web, req, tmpl): |
|
788 | 816 | |
|
789 | 817 | try: |
@@ -862,6 +890,7 b' def filelog(web, req, tmpl):' | |||
|
862 | 890 | latestentry=latestentry, |
|
863 | 891 | revcount=revcount, morevars=morevars, lessvars=lessvars) |
|
864 | 892 | |
|
893 | @webcommand('archive') | |
|
865 | 894 | def archive(web, req, tmpl): |
|
866 | 895 | type_ = req.form.get('type', [None])[0] |
|
867 | 896 | allowed = web.configlist("web", "allow_archive") |
@@ -911,6 +940,7 b' def archive(web, req, tmpl):' | |||
|
911 | 940 | return [] |
|
912 | 941 | |
|
913 | 942 | |
|
943 | @webcommand('static') | |
|
914 | 944 | def static(web, req, tmpl): |
|
915 | 945 | fname = req.form['file'][0] |
|
916 | 946 | # a repo owner may set web.static in .hg/hgrc to get any file |
@@ -924,6 +954,7 b' def static(web, req, tmpl):' | |||
|
924 | 954 | staticfile(static, fname, req) |
|
925 | 955 | return [] |
|
926 | 956 | |
|
957 | @webcommand('graph') | |
|
927 | 958 | def graph(web, req, tmpl): |
|
928 | 959 | |
|
929 | 960 | ctx = webutil.changectx(web.repo, req) |
@@ -1047,6 +1078,7 b' def _getdoc(e):' | |||
|
1047 | 1078 | doc = _('(no help text available)') |
|
1048 | 1079 | return doc |
|
1049 | 1080 | |
|
1081 | @webcommand('help') | |
|
1050 | 1082 | def help(web, req, tmpl): |
|
1051 | 1083 | from mercurial import commands # avoid cycle |
|
1052 | 1084 |
General Comments 0
You need to be logged in to leave comments.
Login now