comparison mercurial/hgweb/webutil.py @ 31665:5e6d44511317

hgweb: handle a "linerange" request parameter in filelog command We now handle a "linerange" URL query parameter to filter filelog using a logic similar to followlines() revset. The URL syntax is: log/<rev>/<file>?linerange=<fromline>:<toline> As a result, filelog entries only consists of revision changing specified line range. The linerange information is propagated to "more"/"less" navigation links but not to numeric navigation links as this would apparently require a dedicated "revnav" class. Only update the "paper" template in this patch.
author Denis Laxalde <denis.laxalde@logilab.fr>
date Thu, 19 Jan 2017 17:41:00 +0100
parents c2dbd818e884
children aaebc80c9f1d
comparison
equal deleted inserted replaced
31664:1cbeefa59343 31665:5e6d44511317
16 from ..i18n import _ 16 from ..i18n import _
17 from ..node import hex, nullid, short 17 from ..node import hex, nullid, short
18 18
19 from .common import ( 19 from .common import (
20 ErrorResponse, 20 ErrorResponse,
21 HTTP_BAD_REQUEST,
21 HTTP_NOT_FOUND, 22 HTTP_NOT_FOUND,
22 paritygen, 23 paritygen,
23 ) 24 )
24 25
25 from .. import ( 26 from .. import (
314 fctx = repo[changeid][path] 315 fctx = repo[changeid][path]
315 except error.RepoError: 316 except error.RepoError:
316 fctx = repo.filectx(path, fileid=changeid) 317 fctx = repo.filectx(path, fileid=changeid)
317 318
318 return fctx 319 return fctx
320
321 def linerange(req):
322 linerange = req.form.get('linerange')
323 if linerange is None:
324 return None
325 if len(linerange) > 1:
326 raise ErrorResponse(HTTP_BAD_REQUEST,
327 'redundant linerange parameter')
328 try:
329 fromline, toline = map(int, linerange[0].split(':', 1))
330 except ValueError:
331 raise ErrorResponse(HTTP_BAD_REQUEST,
332 'invalid linerange parameter')
333 try:
334 return util.processlinerange(fromline, toline)
335 except error.ParseError as exc:
336 raise ErrorResponse(HTTP_BAD_REQUEST, str(exc))
337
338 def formatlinerange(fromline, toline):
339 return '%d:%d' % (fromline + 1, toline)
319 340
320 def commonentry(repo, ctx): 341 def commonentry(repo, ctx):
321 node = ctx.node() 342 node = ctx.node()
322 return { 343 return {
323 'rev': ctx.rev(), 344 'rev': ctx.rev(),