comparison mercurial/hgweb/webcommands.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 f36dc643ffdc
children e540846c67e0
comparison
equal deleted inserted replaced
31664:1cbeefa59343 31665:5e6d44511317
26 staticfile, 26 staticfile,
27 ) 27 )
28 28
29 from .. import ( 29 from .. import (
30 archival, 30 archival,
31 context,
31 encoding, 32 encoding,
32 error, 33 error,
33 graphmod, 34 graphmod,
34 revset, 35 revset,
35 revsetlang, 36 revsetlang,
966 revcount = max(revcount, 1) 967 revcount = max(revcount, 1)
967 tmpl.defaults['sessionvars']['revcount'] = revcount 968 tmpl.defaults['sessionvars']['revcount'] = revcount
968 except ValueError: 969 except ValueError:
969 pass 970 pass
970 971
972 lrange = webutil.linerange(req)
973
971 lessvars = copy.copy(tmpl.defaults['sessionvars']) 974 lessvars = copy.copy(tmpl.defaults['sessionvars'])
972 lessvars['revcount'] = max(revcount / 2, 1) 975 lessvars['revcount'] = max(revcount / 2, 1)
973 morevars = copy.copy(tmpl.defaults['sessionvars']) 976 morevars = copy.copy(tmpl.defaults['sessionvars'])
974 morevars['revcount'] = revcount * 2 977 morevars['revcount'] = revcount * 2
975 978
994 ctx = fctx.changectx() 997 ctx = fctx.changectx()
995 basectx = ctx.p1() 998 basectx = ctx.p1()
996 path = fctx.path() 999 path = fctx.path()
997 return webutil.diffs(web, tmpl, ctx, basectx, [path], diffstyle) 1000 return webutil.diffs(web, tmpl, ctx, basectx, [path], diffstyle)
998 1001
999 for i in revs: 1002 linerange = None
1000 iterfctx = fctx.filectx(i) 1003 if lrange is not None:
1001 diffs = None 1004 linerange = webutil.formatlinerange(*lrange)
1002 if patch: 1005 # deactivate numeric nav links when linerange is specified as this
1003 diffs = diff(iterfctx) 1006 # would required a dedicated "revnav" class
1004 entries.append(dict( 1007 nav = None
1005 parity=next(parity), 1008 ancestors = context.blockancestors(fctx, *lrange)
1006 filerev=i, 1009 for i, (c, lr) in enumerate(ancestors, 1):
1007 file=f, 1010 diffs = None
1008 diff=diffs, 1011 if patch:
1009 rename=webutil.renamelink(iterfctx), 1012 diffs = diff(c)
1010 **webutil.commonentry(repo, iterfctx))) 1013 # follow renames accross filtered (not in range) revisions
1011 entries.reverse() 1014 path = c.path()
1015 entries.append(dict(
1016 parity=next(parity),
1017 filerev=c.rev(),
1018 file=path,
1019 diff=diffs,
1020 linerange=webutil.formatlinerange(*lr),
1021 **webutil.commonentry(repo, c)))
1022 if i == revcount:
1023 break
1024 lessvars['linerange'] = webutil.formatlinerange(*lrange)
1025 morevars['linerange'] = lessvars['linerange']
1026 else:
1027 for i in revs:
1028 iterfctx = fctx.filectx(i)
1029 diffs = None
1030 if patch:
1031 diffs = diff(iterfctx)
1032 entries.append(dict(
1033 parity=next(parity),
1034 filerev=i,
1035 file=f,
1036 diff=diffs,
1037 rename=webutil.renamelink(iterfctx),
1038 **webutil.commonentry(repo, iterfctx)))
1039 entries.reverse()
1040 revnav = webutil.filerevnav(web.repo, fctx.path())
1041 nav = revnav.gen(end - 1, revcount, count)
1012 1042
1013 latestentry = entries[:1] 1043 latestentry = entries[:1]
1014 1044
1015 revnav = webutil.filerevnav(web.repo, fctx.path())
1016 nav = revnav.gen(end - 1, revcount, count)
1017 return tmpl("filelog", 1045 return tmpl("filelog",
1018 file=f, 1046 file=f,
1019 nav=nav, 1047 nav=nav,
1020 symrev=webutil.symrevorshortnode(req, fctx), 1048 symrev=webutil.symrevorshortnode(req, fctx),
1021 entries=entries, 1049 entries=entries,
1022 patch=patch, 1050 patch=patch,
1023 latestentry=latestentry, 1051 latestentry=latestentry,
1052 linerange=linerange,
1024 revcount=revcount, 1053 revcount=revcount,
1025 morevars=morevars, 1054 morevars=morevars,
1026 lessvars=lessvars, 1055 lessvars=lessvars,
1027 **webutil.commonentry(web.repo, fctx)) 1056 **webutil.commonentry(web.repo, fctx))
1028 1057