mercurial/hgweb/webcommands.py
changeset 36886 563fd95a6efb
parent 36885 c68e79dcf21c
child 36887 4daa22071d5d
equal deleted inserted replaced
36885:c68e79dcf21c 36886:563fd95a6efb
   106     path = webutil.cleanpath(web.repo, web.req.qsparams.get('file', ''))
   106     path = webutil.cleanpath(web.repo, web.req.qsparams.get('file', ''))
   107     if not path:
   107     if not path:
   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)
   115         except ErrorResponse:
   115         except ErrorResponse:
   116             raise inst
   116             raise inst
   155     return web.sendtemplate(
   155     return web.sendtemplate(
   156         'filerevision',
   156         'filerevision',
   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),
   164         **pycompat.strkwargs(webutil.commonentry(web.repo, fctx)))
   164         **pycompat.strkwargs(webutil.commonentry(web.repo, fctx)))
   165 
   165 
   188 
   188 
   189     path = webutil.cleanpath(web.repo, web.req.qsparams.get('file', ''))
   189     path = webutil.cleanpath(web.repo, web.req.qsparams.get('file', ''))
   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)
   197         except ErrorResponse:
   197         except ErrorResponse:
   198             raise inst
   198             raise inst
   379     For non-searches, the ``changelog`` template will be rendered.
   379     For non-searches, the ``changelog`` template will be rendered.
   380     """
   380     """
   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:
   389         ctx = web.repo['tip']
   389         ctx = web.repo['tip']
   390         symrev = 'tip'
   390         symrev = 'tip'
   479 
   479 
   480     The ``changeset`` template is rendered. Contents of the ``changesettag``,
   480     The ``changeset`` template is rendered. Contents of the ``changesettag``,
   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 
   492 def decodepath(path):
   492 def decodepath(path):
   493     """Hook for mapping a path in the repository to a path in the
   493     """Hook for mapping a path in the repository to a path in the
   513     directories and files.
   513     directories and files.
   514 
   514 
   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'
   523     path = webutil.cleanpath(web.repo, web.req.qsparams.get('file', ''))
   523     path = webutil.cleanpath(web.repo, web.req.qsparams.get('file', ''))
   524     mf = ctx.manifest()
   524     mf = ctx.manifest()
   790     This handler is registered under both the ``/diff`` and ``/filediff``
   790     This handler is registered under both the ``/diff`` and ``/filediff``
   791     paths. ``/diff`` is used in modern code.
   791     paths. ``/diff`` is used in modern code.
   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
   801 
   801 
   802     if fctx is not None:
   802     if fctx is not None:
   817         ctx = ctx
   817         ctx = ctx
   818 
   818 
   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)))
   826 
   826 
   827 diff = webcommand('diff')(filediff)
   827 diff = webcommand('diff')(filediff)
   841     The ``context`` query string argument can be used to control the lines of
   841     The ``context`` query string argument can be used to control the lines of
   842     context in the diff.
   842     context in the diff.
   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'])
   850 
   850 
   851     parsecontext = lambda v: v == 'full' and -1 or int(v)
   851     parsecontext = lambda v: v == 'full' and -1 or int(v)
   890         ctx = ctx
   890         ctx = ctx
   891 
   891 
   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),
   899         rightrev=rightrev,
   899         rightrev=rightrev,
   900         rightnode=hex(rightnode),
   900         rightnode=hex(rightnode),
   916     false and ``1`` and ``true`` are true. If not defined, the server
   916     false and ``1`` and ``true`` are true. If not defined, the server
   917     default settings are used.
   917     default settings are used.
   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()
   925 
   925 
   926     # parents() is called once per line and several lines likely belong to
   926     # parents() is called once per line and several lines likely belong to
   946         if fctx.isbinary():
   946         if fctx.isbinary():
   947             mt = (mimetypes.guess_type(fctx.path())[0]
   947             mt = (mimetypes.guess_type(fctx.path())[0]
   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)
   955         for lineno, (aline, l) in enumerate(lines):
   955         for lineno, (aline, l) in enumerate(lines):
   956             f = aline.fctx
   956             f = aline.fctx
   976                    "lineno": lineno + 1,
   976                    "lineno": lineno + 1,
   977                    "lineid": "l%d" % (lineno + 1),
   977                    "lineid": "l%d" % (lineno + 1),
   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(
   985         'fileannotate',
   985         'fileannotate',
   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),
   993         diffopts=diffopts,
   993         diffopts=diffopts,
   994         **pycompat.strkwargs(webutil.commonentry(web.repo, fctx)))
   994         **pycompat.strkwargs(webutil.commonentry(web.repo, fctx)))
  1006 
  1006 
  1007     The ``filelog`` template will be rendered.
  1007     The ``filelog`` template will be rendered.
  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:
  1015         f = webutil.cleanpath(web.repo, web.req.qsparams['file'])
  1015         f = webutil.cleanpath(web.repo, web.req.qsparams['file'])
  1016         fl = web.repo.file(f)
  1016         fl = web.repo.file(f)
  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
  1024         frev = numrevs - 1
  1024         frev = numrevs - 1
  1025         while fl.linkrev(frev) > rev:
  1025         while fl.linkrev(frev) > rev:
  1033             revcount = max(revcount, 1)
  1033             revcount = max(revcount, 1)
  1034             web.tmpl.defaults['sessionvars']['revcount'] = revcount
  1034             web.tmpl.defaults['sessionvars']['revcount'] = revcount
  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)
  1042     morevars = copy.copy(web.tmpl.defaults['sessionvars'])
  1042     morevars = copy.copy(web.tmpl.defaults['sessionvars'])
  1043     morevars['revcount'] = revcount * 2
  1043     morevars['revcount'] = revcount * 2
  1118 
  1118 
  1119     return web.sendtemplate(
  1119     return web.sendtemplate(
  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,
  1127         latestentry=latestentry,
  1127         latestentry=latestentry,
  1128         linerange=linerange,
  1128         linerange=linerange,
  1170     arch_version = key
  1170     arch_version = key
  1171     if cnode == key or key == 'tip':
  1171     if cnode == key or key == 'tip':
  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')
  1179     if file:
  1179     if file:
  1180         pats = ['path:' + file]
  1180         pats = ['path:' + file]
  1243 
  1243 
  1244     This handler will render the ``graph`` template.
  1244     This handler will render the ``graph`` template.
  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'
  1253     rev = ctx.rev()
  1253     rev = ctx.rev()
  1254 
  1254