##// END OF EJS Templates
hgweb: pass modern request type into various webutil functions (API)...
Gregory Szorc -
r36902:563fd95a default
parent child Browse files
Show More
@@ -75,7 +75,7 b' def filerevision_highlight(orig, web, re'
75 def annotate_highlight(orig, web, req, tmpl):
75 def annotate_highlight(orig, web, req, tmpl):
76 mt = ''.join(web.tmpl('mimetype', encoding=encoding.encoding))
76 mt = ''.join(web.tmpl('mimetype', encoding=encoding.encoding))
77 if 'html' in mt:
77 if 'html' in mt:
78 fctx = webutil.filectx(web.repo, req)
78 fctx = webutil.filectx(web.repo, web.req)
79 pygmentize(web, 'annotateline', fctx, web.tmpl)
79 pygmentize(web, 'annotateline', fctx, web.tmpl)
80
80
81 return orig(web, req, web.tmpl)
81 return orig(web, req, web.tmpl)
@@ -108,7 +108,7 b' def rawfile(web, req, tmpl):'
108 return manifest(web, req, None)
108 return manifest(web, req, None)
109
109
110 try:
110 try:
111 fctx = webutil.filectx(web.repo, req)
111 fctx = webutil.filectx(web.repo, web.req)
112 except error.LookupError as inst:
112 except error.LookupError as inst:
113 try:
113 try:
114 return manifest(web, req, None)
114 return manifest(web, req, None)
@@ -157,7 +157,7 b' def _filerevision(web, req, fctx):'
157 file=f,
157 file=f,
158 path=webutil.up(f),
158 path=webutil.up(f),
159 text=lines(),
159 text=lines(),
160 symrev=webutil.symrevorshortnode(req, fctx),
160 symrev=webutil.symrevorshortnode(web.req, fctx),
161 rename=webutil.renamelink(fctx),
161 rename=webutil.renamelink(fctx),
162 permissions=fctx.manifest().flags(f),
162 permissions=fctx.manifest().flags(f),
163 ishead=int(ishead),
163 ishead=int(ishead),
@@ -190,7 +190,7 b' def file(web, req, tmpl):'
190 if not path:
190 if not path:
191 return manifest(web, req, None)
191 return manifest(web, req, None)
192 try:
192 try:
193 return _filerevision(web, req, webutil.filectx(web.repo, req))
193 return _filerevision(web, req, webutil.filectx(web.repo, web.req))
194 except error.LookupError as inst:
194 except error.LookupError as inst:
195 try:
195 try:
196 return manifest(web, req, None)
196 return manifest(web, req, None)
@@ -381,8 +381,8 b' def changelog(web, req, tmpl, shortlog=F'
381
381
382 query = ''
382 query = ''
383 if 'node' in web.req.qsparams:
383 if 'node' in web.req.qsparams:
384 ctx = webutil.changectx(web.repo, req)
384 ctx = webutil.changectx(web.repo, web.req)
385 symrev = webutil.symrevorshortnode(req, ctx)
385 symrev = webutil.symrevorshortnode(web.req, ctx)
386 elif 'rev' in web.req.qsparams:
386 elif 'rev' in web.req.qsparams:
387 return _search(web)
387 return _search(web)
388 else:
388 else:
@@ -481,11 +481,11 b' def changeset(web, req, tmpl):'
481 ``changesetbookmark``, ``filenodelink``, ``filenolink``, and the many
481 ``changesetbookmark``, ``filenodelink``, ``filenolink``, and the many
482 templates related to diffs may all be used to produce the output.
482 templates related to diffs may all be used to produce the output.
483 """
483 """
484 ctx = webutil.changectx(web.repo, req)
484 ctx = webutil.changectx(web.repo, web.req)
485
485
486 return web.sendtemplate(
486 return web.sendtemplate(
487 'changeset',
487 'changeset',
488 **webutil.changesetentry(web, req, ctx))
488 **webutil.changesetentry(web, ctx))
489
489
490 rev = webcommand('rev')(changeset)
490 rev = webcommand('rev')(changeset)
491
491
@@ -515,8 +515,8 b' def manifest(web, req, tmpl):'
515 The ``manifest`` template will be rendered for this handler.
515 The ``manifest`` template will be rendered for this handler.
516 """
516 """
517 if 'node' in web.req.qsparams:
517 if 'node' in web.req.qsparams:
518 ctx = webutil.changectx(web.repo, req)
518 ctx = webutil.changectx(web.repo, web.req)
519 symrev = webutil.symrevorshortnode(req, ctx)
519 symrev = webutil.symrevorshortnode(web.req, ctx)
520 else:
520 else:
521 ctx = web.repo['tip']
521 ctx = web.repo['tip']
522 symrev = 'tip'
522 symrev = 'tip'
@@ -792,9 +792,9 b' def filediff(web, req, tmpl):'
792 """
792 """
793 fctx, ctx = None, None
793 fctx, ctx = None, None
794 try:
794 try:
795 fctx = webutil.filectx(web.repo, req)
795 fctx = webutil.filectx(web.repo, web.req)
796 except LookupError:
796 except LookupError:
797 ctx = webutil.changectx(web.repo, req)
797 ctx = webutil.changectx(web.repo, web.req)
798 path = webutil.cleanpath(web.repo, web.req.qsparams['file'])
798 path = webutil.cleanpath(web.repo, web.req.qsparams['file'])
799 if path not in ctx.files():
799 if path not in ctx.files():
800 raise
800 raise
@@ -819,7 +819,7 b' def filediff(web, req, tmpl):'
819 return web.sendtemplate(
819 return web.sendtemplate(
820 'filediff',
820 'filediff',
821 file=path,
821 file=path,
822 symrev=webutil.symrevorshortnode(req, ctx),
822 symrev=webutil.symrevorshortnode(web.req, ctx),
823 rename=rename,
823 rename=rename,
824 diff=diffs,
824 diff=diffs,
825 **pycompat.strkwargs(webutil.commonentry(web.repo, ctx)))
825 **pycompat.strkwargs(webutil.commonentry(web.repo, ctx)))
@@ -843,7 +843,7 b' def comparison(web, req, tmpl):'
843
843
844 The ``filecomparison`` template is rendered.
844 The ``filecomparison`` template is rendered.
845 """
845 """
846 ctx = webutil.changectx(web.repo, req)
846 ctx = webutil.changectx(web.repo, web.req)
847 if 'file' not in web.req.qsparams:
847 if 'file' not in web.req.qsparams:
848 raise ErrorResponse(HTTP_NOT_FOUND, 'file not given')
848 raise ErrorResponse(HTTP_NOT_FOUND, 'file not given')
849 path = webutil.cleanpath(web.repo, web.req.qsparams['file'])
849 path = webutil.cleanpath(web.repo, web.req.qsparams['file'])
@@ -892,7 +892,7 b' def comparison(web, req, tmpl):'
892 return web.sendtemplate(
892 return web.sendtemplate(
893 'filecomparison',
893 'filecomparison',
894 file=path,
894 file=path,
895 symrev=webutil.symrevorshortnode(req, ctx),
895 symrev=webutil.symrevorshortnode(web.req, ctx),
896 rename=rename,
896 rename=rename,
897 leftrev=leftrev,
897 leftrev=leftrev,
898 leftnode=hex(leftnode),
898 leftnode=hex(leftnode),
@@ -918,7 +918,7 b' def annotate(web, req, tmpl):'
918
918
919 The ``fileannotate`` template is rendered.
919 The ``fileannotate`` template is rendered.
920 """
920 """
921 fctx = webutil.filectx(web.repo, req)
921 fctx = webutil.filectx(web.repo, web.req)
922 f = fctx.path()
922 f = fctx.path()
923 parity = paritygen(web.stripecount)
923 parity = paritygen(web.stripecount)
924 ishead = fctx.filerev() in fctx.filelog().headrevs()
924 ishead = fctx.filerev() in fctx.filelog().headrevs()
@@ -948,7 +948,7 b' def annotate(web, req, tmpl):'
948 or 'application/octet-stream')
948 or 'application/octet-stream')
949 lines = [((fctx.filectx(fctx.filerev()), 1), '(binary:%s)' % mt)]
949 lines = [((fctx.filectx(fctx.filerev()), 1), '(binary:%s)' % mt)]
950 else:
950 else:
951 lines = webutil.annotate(req, fctx, web.repo.ui)
951 lines = webutil.annotate(web.req, fctx, web.repo.ui)
952
952
953 previousrev = None
953 previousrev = None
954 blockparitygen = paritygen(1)
954 blockparitygen = paritygen(1)
@@ -978,7 +978,7 b' def annotate(web, req, tmpl):'
978 "linenumber": "% 6d" % (lineno + 1),
978 "linenumber": "% 6d" % (lineno + 1),
979 "revdate": f.date()}
979 "revdate": f.date()}
980
980
981 diffopts = webutil.difffeatureopts(req, web.repo.ui, 'annotate')
981 diffopts = webutil.difffeatureopts(web.req, web.repo.ui, 'annotate')
982 diffopts = {k: getattr(diffopts, k) for k in diffopts.defaults}
982 diffopts = {k: getattr(diffopts, k) for k in diffopts.defaults}
983
983
984 return web.sendtemplate(
984 return web.sendtemplate(
@@ -986,7 +986,7 b' def annotate(web, req, tmpl):'
986 file=f,
986 file=f,
987 annotate=annotate,
987 annotate=annotate,
988 path=webutil.up(f),
988 path=webutil.up(f),
989 symrev=webutil.symrevorshortnode(req, fctx),
989 symrev=webutil.symrevorshortnode(web.req, fctx),
990 rename=webutil.renamelink(fctx),
990 rename=webutil.renamelink(fctx),
991 permissions=fctx.manifest().flags(f),
991 permissions=fctx.manifest().flags(f),
992 ishead=int(ishead),
992 ishead=int(ishead),
@@ -1008,7 +1008,7 b' def filelog(web, req, tmpl):'
1008 """
1008 """
1009
1009
1010 try:
1010 try:
1011 fctx = webutil.filectx(web.repo, req)
1011 fctx = webutil.filectx(web.repo, web.req)
1012 f = fctx.path()
1012 f = fctx.path()
1013 fl = fctx.filelog()
1013 fl = fctx.filelog()
1014 except error.LookupError:
1014 except error.LookupError:
@@ -1017,7 +1017,7 b' def filelog(web, req, tmpl):'
1017 numrevs = len(fl)
1017 numrevs = len(fl)
1018 if not numrevs: # file doesn't exist at all
1018 if not numrevs: # file doesn't exist at all
1019 raise
1019 raise
1020 rev = webutil.changectx(web.repo, req).rev()
1020 rev = webutil.changectx(web.repo, web.req).rev()
1021 first = fl.linkrev(0)
1021 first = fl.linkrev(0)
1022 if rev < first: # current rev is from before file existed
1022 if rev < first: # current rev is from before file existed
1023 raise
1023 raise
@@ -1035,7 +1035,7 b' def filelog(web, req, tmpl):'
1035 except ValueError:
1035 except ValueError:
1036 pass
1036 pass
1037
1037
1038 lrange = webutil.linerange(req)
1038 lrange = webutil.linerange(web.req)
1039
1039
1040 lessvars = copy.copy(web.tmpl.defaults['sessionvars'])
1040 lessvars = copy.copy(web.tmpl.defaults['sessionvars'])
1041 lessvars['revcount'] = max(revcount // 2, 1)
1041 lessvars['revcount'] = max(revcount // 2, 1)
@@ -1120,7 +1120,7 b' def filelog(web, req, tmpl):'
1120 'filelog',
1120 'filelog',
1121 file=f,
1121 file=f,
1122 nav=nav,
1122 nav=nav,
1123 symrev=webutil.symrevorshortnode(req, fctx),
1123 symrev=webutil.symrevorshortnode(web.req, fctx),
1124 entries=entries,
1124 entries=entries,
1125 descend=descend,
1125 descend=descend,
1126 patch=patch,
1126 patch=patch,
@@ -1172,7 +1172,7 b' def archive(web, req, tmpl):'
1172 arch_version = short(cnode)
1172 arch_version = short(cnode)
1173 name = "%s-%s" % (reponame, arch_version)
1173 name = "%s-%s" % (reponame, arch_version)
1174
1174
1175 ctx = webutil.changectx(web.repo, req)
1175 ctx = webutil.changectx(web.repo, web.req)
1176 pats = []
1176 pats = []
1177 match = scmutil.match(ctx, [])
1177 match = scmutil.match(ctx, [])
1178 file = web.req.qsparams.get('file')
1178 file = web.req.qsparams.get('file')
@@ -1245,8 +1245,8 b' def graph(web, req, tmpl):'
1245 """
1245 """
1246
1246
1247 if 'node' in web.req.qsparams:
1247 if 'node' in web.req.qsparams:
1248 ctx = webutil.changectx(web.repo, req)
1248 ctx = webutil.changectx(web.repo, web.req)
1249 symrev = webutil.symrevorshortnode(req, ctx)
1249 symrev = webutil.symrevorshortnode(web.req, ctx)
1250 else:
1250 else:
1251 ctx = web.repo['tip']
1251 ctx = web.repo['tip']
1252 symrev = 'tip'
1252 symrev = 'tip'
@@ -177,7 +177,7 b' def difffeatureopts(req, ui, section):'
177 section=section, whitespace=True)
177 section=section, whitespace=True)
178
178
179 for k in ('ignorews', 'ignorewsamount', 'ignorewseol', 'ignoreblanklines'):
179 for k in ('ignorews', 'ignorewsamount', 'ignorewseol', 'ignoreblanklines'):
180 v = req.req.qsparams.get(k)
180 v = req.qsparams.get(k)
181 if v is not None:
181 if v is not None:
182 v = util.parsebool(v)
182 v = util.parsebool(v)
183 setattr(diffopts, k, v if v is not None else True)
183 setattr(diffopts, k, v if v is not None else True)
@@ -295,19 +295,19 b' def changeidctx(repo, changeid):'
295
295
296 def changectx(repo, req):
296 def changectx(repo, req):
297 changeid = "tip"
297 changeid = "tip"
298 if 'node' in req.req.qsparams:
298 if 'node' in req.qsparams:
299 changeid = req.req.qsparams['node']
299 changeid = req.qsparams['node']
300 ipos = changeid.find(':')
300 ipos = changeid.find(':')
301 if ipos != -1:
301 if ipos != -1:
302 changeid = changeid[(ipos + 1):]
302 changeid = changeid[(ipos + 1):]
303 elif 'manifest' in req.req.qsparams:
303 elif 'manifest' in req.qsparams:
304 changeid = req.req.qsparams['manifest']
304 changeid = req.qsparams['manifest']
305
305
306 return changeidctx(repo, changeid)
306 return changeidctx(repo, changeid)
307
307
308 def basechangectx(repo, req):
308 def basechangectx(repo, req):
309 if 'node' in req.req.qsparams:
309 if 'node' in req.qsparams:
310 changeid = req.req.qsparams['node']
310 changeid = req.qsparams['node']
311 ipos = changeid.find(':')
311 ipos = changeid.find(':')
312 if ipos != -1:
312 if ipos != -1:
313 changeid = changeid[:ipos]
313 changeid = changeid[:ipos]
@@ -316,13 +316,13 b' def basechangectx(repo, req):'
316 return None
316 return None
317
317
318 def filectx(repo, req):
318 def filectx(repo, req):
319 if 'file' not in req.req.qsparams:
319 if 'file' not in req.qsparams:
320 raise ErrorResponse(HTTP_NOT_FOUND, 'file not given')
320 raise ErrorResponse(HTTP_NOT_FOUND, 'file not given')
321 path = cleanpath(repo, req.req.qsparams['file'])
321 path = cleanpath(repo, req.qsparams['file'])
322 if 'node' in req.req.qsparams:
322 if 'node' in req.qsparams:
323 changeid = req.req.qsparams['node']
323 changeid = req.qsparams['node']
324 elif 'filenode' in req.req.qsparams:
324 elif 'filenode' in req.qsparams:
325 changeid = req.req.qsparams['filenode']
325 changeid = req.qsparams['filenode']
326 else:
326 else:
327 raise ErrorResponse(HTTP_NOT_FOUND, 'node or filenode not given')
327 raise ErrorResponse(HTTP_NOT_FOUND, 'node or filenode not given')
328 try:
328 try:
@@ -333,7 +333,7 b' def filectx(repo, req):'
333 return fctx
333 return fctx
334
334
335 def linerange(req):
335 def linerange(req):
336 linerange = req.req.qsparams.getall('linerange')
336 linerange = req.qsparams.getall('linerange')
337 if not linerange:
337 if not linerange:
338 return None
338 return None
339 if len(linerange) > 1:
339 if len(linerange) > 1:
@@ -412,12 +412,12 b' def changelistentry(web, ctx):'
412 return entry
412 return entry
413
413
414 def symrevorshortnode(req, ctx):
414 def symrevorshortnode(req, ctx):
415 if 'node' in req.req.qsparams:
415 if 'node' in req.qsparams:
416 return templatefilters.revescape(req.req.qsparams['node'])
416 return templatefilters.revescape(req.qsparams['node'])
417 else:
417 else:
418 return short(ctx.node())
418 return short(ctx.node())
419
419
420 def changesetentry(web, req, ctx):
420 def changesetentry(web, ctx):
421 '''Obtain a dictionary to be used to render the "changeset" template.'''
421 '''Obtain a dictionary to be used to render the "changeset" template.'''
422
422
423 showtags = showtag(web.repo, web.tmpl, 'changesettag', ctx.node())
423 showtags = showtag(web.repo, web.tmpl, 'changesettag', ctx.node())
@@ -433,13 +433,13 b' def changesetentry(web, req, ctx):'
433 node=ctx.hex(), file=f, blockno=blockno + 1,
433 node=ctx.hex(), file=f, blockno=blockno + 1,
434 parity=next(parity)))
434 parity=next(parity)))
435
435
436 basectx = basechangectx(web.repo, req)
436 basectx = basechangectx(web.repo, web.req)
437 if basectx is None:
437 if basectx is None:
438 basectx = ctx.p1()
438 basectx = ctx.p1()
439
439
440 style = web.config('web', 'style')
440 style = web.config('web', 'style')
441 if 'style' in req.req.qsparams:
441 if 'style' in web.req.qsparams:
442 style = req.req.qsparams['style']
442 style = web.req.qsparams['style']
443
443
444 diff = diffs(web, ctx, basectx, None, style)
444 diff = diffs(web, ctx, basectx, None, style)
445
445
@@ -449,7 +449,7 b' def changesetentry(web, req, ctx):'
449
449
450 return dict(
450 return dict(
451 diff=diff,
451 diff=diff,
452 symrev=symrevorshortnode(req, ctx),
452 symrev=symrevorshortnode(web.req, ctx),
453 basenode=basectx.hex(),
453 basenode=basectx.hex(),
454 changesettag=showtags,
454 changesettag=showtags,
455 changesetbookmark=showbookmarks,
455 changesetbookmark=showbookmarks,
General Comments 0
You need to be logged in to leave comments. Login now