comparison mercurial/hgweb/webcommands.py @ 6750:fb42030d79d6

add __len__ and __iter__ methods to repo and revlog
author Matt Mackall <mpm@selenic.com>
date Thu, 26 Jun 2008 14:35:50 -0500
parents f6c00b17387c
children f67d1468ac50
comparison
equal deleted inserted replaced
6749:51b0e799352f 6750:fb42030d79d6
108 cl = web.repo.changelog 108 cl = web.repo.changelog
109 count = 0 109 count = 0
110 qw = query.lower().split() 110 qw = query.lower().split()
111 111
112 def revgen(): 112 def revgen():
113 for i in xrange(cl.count() - 1, 0, -100): 113 for i in xrange(len(cl) - 1, 0, -100):
114 l = [] 114 l = []
115 for j in xrange(max(0, i - 100), i + 1): 115 for j in xrange(max(0, i - 100), i + 1):
116 ctx = web.repo[j] 116 ctx = web.repo[j]
117 l.append(ctx) 117 l.append(ctx)
118 l.reverse() 118 l.reverse()
166 ctx = webutil.changectx(web.repo, req) 166 ctx = webutil.changectx(web.repo, req)
167 else: 167 else:
168 if 'rev' in req.form: 168 if 'rev' in req.form:
169 hi = req.form['rev'][0] 169 hi = req.form['rev'][0]
170 else: 170 else:
171 hi = web.repo.changelog.count() - 1 171 hi = len(web.repo) - 1
172 try: 172 try:
173 ctx = web.repo[hi] 173 ctx = web.repo[hi]
174 except RepoError: 174 except RepoError:
175 return _search(web, tmpl, hi) # XXX redirect to 404 page? 175 return _search(web, tmpl, hi) # XXX redirect to 404 page?
176 176
203 for e in l: 203 for e in l:
204 yield e 204 yield e
205 205
206 maxchanges = shortlog and web.maxshortchanges or web.maxchanges 206 maxchanges = shortlog and web.maxshortchanges or web.maxchanges
207 cl = web.repo.changelog 207 cl = web.repo.changelog
208 count = cl.count() 208 count = len(cl)
209 pos = ctx.rev() 209 pos = ctx.rev()
210 start = max(0, pos - maxchanges + 1) 210 start = max(0, pos - maxchanges + 1)
211 end = min(count, start + maxchanges) 211 end = min(count, start + maxchanges)
212 pos = end - 1 212 pos = end - 1
213 parity = paritygen(web.stripecount, offset=start-end) 213 parity = paritygen(web.stripecount, offset=start-end)
407 branches=webutil.nodebranchdict(web.repo, ctx))) 407 branches=webutil.nodebranchdict(web.repo, ctx)))
408 408
409 yield l 409 yield l
410 410
411 cl = web.repo.changelog 411 cl = web.repo.changelog
412 count = cl.count() 412 count = len(cl)
413 start = max(0, count - web.maxchanges) 413 start = max(0, count - web.maxchanges)
414 end = min(count, start + web.maxchanges) 414 end = min(count, start + web.maxchanges)
415 415
416 return tmpl("summary", 416 return tmpl("summary",
417 desc=web.config("web", "description", "unknown"), 417 desc=web.config("web", "description", "unknown"),
496 496
497 def filelog(web, req, tmpl): 497 def filelog(web, req, tmpl):
498 fctx = webutil.filectx(web.repo, req) 498 fctx = webutil.filectx(web.repo, req)
499 f = fctx.path() 499 f = fctx.path()
500 fl = fctx.filelog() 500 fl = fctx.filelog()
501 count = fl.count() 501 count = len(fl)
502 pagelen = web.maxshortchanges 502 pagelen = web.maxshortchanges
503 pos = fctx.filerev() 503 pos = fctx.filerev()
504 start = max(0, pos - pagelen + 1) 504 start = max(0, pos - pagelen + 1)
505 end = min(count, start + pagelen) 505 end = min(count, start + pagelen)
506 pos = end - 1 506 pos = end - 1
577 577
578 def graph(web, req, tmpl): 578 def graph(web, req, tmpl):
579 rev = webutil.changectx(web.repo, req).rev() 579 rev = webutil.changectx(web.repo, req).rev()
580 bg_height = 39 580 bg_height = 39
581 581
582 max_rev = web.repo.changelog.count() - 1 582 max_rev = len(web.repo) - 1
583 revcount = min(max_rev, int(req.form.get('revcount', [25])[0])) 583 revcount = min(max_rev, int(req.form.get('revcount', [25])[0]))
584 revnode = web.repo.changelog.node(rev) 584 revnode = web.repo.changelog.node(rev)
585 revnode_hex = hex(revnode) 585 revnode_hex = hex(revnode)
586 uprev = min(max_rev, rev + revcount) 586 uprev = min(max_rev, rev + revcount)
587 downrev = max(0, rev - revcount) 587 downrev = max(0, rev - revcount)
588 lessrev = max(0, rev - revcount / 2) 588 lessrev = max(0, rev - revcount / 2)
589 589
590 maxchanges = web.maxshortchanges or web.maxchanges 590 maxchanges = web.maxshortchanges or web.maxchanges
591 count = web.repo.changelog.count() 591 count = len(web.repo)
592 changenav = webutil.revnavgen(rev, maxchanges, count, web.repo.changectx) 592 changenav = webutil.revnavgen(rev, maxchanges, count, web.repo.changectx)
593 593
594 tree = list(graphmod.graph(web.repo, rev, rev - revcount)) 594 tree = list(graphmod.graph(web.repo, rev, rev - revcount))
595 canvasheight = (len(tree) + 1) * bg_height - 27; 595 canvasheight = (len(tree) + 1) * bg_height - 27;
596 596