comparison mercurial/hgweb/webcommands.py @ 10246:b9d02695bde4

hgweb: add less/more links to shortlog/filelog nav
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Thu, 14 Jan 2010 16:28:21 +0100
parents 207b94f6b65d
children e8c7410371e0
comparison
equal deleted inserted replaced
10245:207b94f6b65d 10246:b9d02695bde4
198 l = l[:limit] 198 l = l[:limit]
199 199
200 for e in l: 200 for e in l:
201 yield e 201 yield e
202 202
203 maxchanges = shortlog and web.maxshortchanges or web.maxchanges 203 revcount = shortlog and web.maxshortchanges or web.maxchanges
204 if 'revcount' in req.form:
205 revcount = int(req.form.get('revcount', [revcount])[0])
206 tmpl.defaults['sessionvars']['revcount'] = revcount
207
208 lessvars = copy.copy(tmpl.defaults['sessionvars'])
209 lessvars['revcount'] = revcount / 2
210 morevars = copy.copy(tmpl.defaults['sessionvars'])
211 morevars['revcount'] = revcount * 2
212
204 cl = web.repo.changelog 213 cl = web.repo.changelog
205 count = len(cl) 214 count = len(cl)
206 pos = ctx.rev() 215 pos = ctx.rev()
207 start = max(0, pos - maxchanges + 1) 216 start = max(0, pos - revcount + 1)
208 end = min(count, start + maxchanges) 217 end = min(count, start + revcount)
209 pos = end - 1 218 pos = end - 1
210 parity = paritygen(web.stripecount, offset=start-end) 219 parity = paritygen(web.stripecount, offset=start-end)
211 220
212 changenav = webutil.revnavgen(pos, maxchanges, count, web.repo.changectx) 221 changenav = webutil.revnavgen(pos, revcount, count, web.repo.changectx)
213 222
214 return tmpl(shortlog and 'shortlog' or 'changelog', 223 return tmpl(shortlog and 'shortlog' or 'changelog', changenav=changenav,
215 changenav=changenav, 224 node=hex(ctx.node()), rev=pos, changesets=count,
216 node=hex(ctx.node()),
217 rev=pos, changesets=count,
218 entries=lambda **x: changelist(limit=0,**x), 225 entries=lambda **x: changelist(limit=0,**x),
219 latestentry=lambda **x: changelist(limit=1,**x), 226 latestentry=lambda **x: changelist(limit=1,**x),
220 archives=web.archivelist("tip")) 227 archives=web.archivelist("tip"), revcount=revcount,
228 morevars=morevars, lessvars=lessvars)
221 229
222 def shortlog(web, req, tmpl): 230 def shortlog(web, req, tmpl):
223 return changelog(web, req, tmpl, shortlog = True) 231 return changelog(web, req, tmpl, shortlog = True)
224 232
225 def changeset(web, req, tmpl): 233 def changeset(web, req, tmpl):
565 frev = numrevs - 1 573 frev = numrevs - 1
566 while fl.linkrev(frev) > rev: 574 while fl.linkrev(frev) > rev:
567 frev -= 1 575 frev -= 1
568 fctx = web.repo.filectx(f, fl.linkrev(frev)) 576 fctx = web.repo.filectx(f, fl.linkrev(frev))
569 577
578 revcount = web.maxshortchanges
579 if 'revcount' in req.form:
580 revcount = int(req.form.get('revcount', [revcount])[0])
581 tmpl.defaults['sessionvars']['revcount'] = revcount
582
583 lessvars = copy.copy(tmpl.defaults['sessionvars'])
584 lessvars['revcount'] = revcount / 2
585 morevars = copy.copy(tmpl.defaults['sessionvars'])
586 morevars['revcount'] = revcount * 2
587
570 count = fctx.filerev() + 1 588 count = fctx.filerev() + 1
571 pagelen = web.maxshortchanges 589 start = max(0, fctx.filerev() - revcount + 1) # first rev on this page
572 start = max(0, fctx.filerev() - pagelen + 1) # first rev on this page 590 end = min(count, start + revcount) # last rev on this page
573 end = min(count, start + pagelen) # last rev on this page
574 parity = paritygen(web.stripecount, offset=start-end) 591 parity = paritygen(web.stripecount, offset=start-end)
575 592
576 def entries(limit=0, **map): 593 def entries(limit=0, **map):
577 l = [] 594 l = []
578 595
600 617
601 for e in l: 618 for e in l:
602 yield e 619 yield e
603 620
604 nodefunc = lambda x: fctx.filectx(fileid=x) 621 nodefunc = lambda x: fctx.filectx(fileid=x)
605 nav = webutil.revnavgen(end - 1, pagelen, count, nodefunc) 622 nav = webutil.revnavgen(end - 1, revcount, count, nodefunc)
606 return tmpl("filelog", file=f, node=hex(fctx.node()), nav=nav, 623 return tmpl("filelog", file=f, node=hex(fctx.node()), nav=nav,
607 entries=lambda **x: entries(limit=0, **x), 624 entries=lambda **x: entries(limit=0, **x),
608 latestentry=lambda **x: entries(limit=1, **x)) 625 latestentry=lambda **x: entries(limit=1, **x),
609 626 revcount=revcount, morevars=morevars, lessvars=lessvars)
610 627
611 def archive(web, req, tmpl): 628 def archive(web, req, tmpl):
612 type_ = req.form.get('type', [None])[0] 629 type_ = req.form.get('type', [None])[0]
613 allowed = web.configlist("web", "allow_archive") 630 allowed = web.configlist("web", "allow_archive")
614 key = req.form['node'][0] 631 key = req.form['node'][0]