Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/hgweb_mod.py @ 2666:ebf033bc8eb2
hgweb: Configurable zebra stripes
With this change, you can set
[web]
stripes=3
to get stripes every three lines (a-la fanfold paper), instead of every
line on source and directory listings. The default behaviour is stripes=1
which generates output similar to current, and you can also turn stripes
off by setting it to 0.
author | Frank Kingswood <frank@kingswood-consulting.co.uk> |
---|---|
date | Mon, 24 Jul 2006 23:06:05 -0700 |
parents | 064aef9162cc |
children | 109a22f5434a |
comparison
equal
deleted
inserted
replaced
2665:2efcd2b4c9fe | 2666:ebf033bc8eb2 |
---|---|
35 self.repo = repo | 35 self.repo = repo |
36 | 36 |
37 self.mtime = -1 | 37 self.mtime = -1 |
38 self.reponame = name | 38 self.reponame = name |
39 self.archives = 'zip', 'gz', 'bz2' | 39 self.archives = 'zip', 'gz', 'bz2' |
40 self.stripecount = 1 | |
40 self.templatepath = self.repo.ui.config("web", "templates", | 41 self.templatepath = self.repo.ui.config("web", "templates", |
41 templater.templatepath()) | 42 templater.templatepath()) |
42 | 43 |
43 def refresh(self): | 44 def refresh(self): |
44 mtime = get_mtime(self.repo.root) | 45 mtime = get_mtime(self.repo.root) |
45 if mtime != self.mtime: | 46 if mtime != self.mtime: |
46 self.mtime = mtime | 47 self.mtime = mtime |
47 self.repo = hg.repository(self.repo.ui, self.repo.root) | 48 self.repo = hg.repository(self.repo.ui, self.repo.root) |
48 self.maxchanges = int(self.repo.ui.config("web", "maxchanges", 10)) | 49 self.maxchanges = int(self.repo.ui.config("web", "maxchanges", 10)) |
50 self.stripecount = int(self.repo.ui.config("web", "stripes", 1)) | |
49 self.maxfiles = int(self.repo.ui.config("web", "maxfiles", 10)) | 51 self.maxfiles = int(self.repo.ui.config("web", "maxfiles", 10)) |
50 self.allowpull = self.repo.ui.configbool("web", "allowpull", True) | 52 self.allowpull = self.repo.ui.configbool("web", "allowpull", True) |
51 | 53 |
52 def archivelist(self, nodeid): | 54 def archivelist(self, nodeid): |
53 allowed = self.repo.ui.configlist("web", "allow_archive") | 55 allowed = self.repo.ui.configlist("web", "allow_archive") |
263 | 265 |
264 count += 1 | 266 count += 1 |
265 hn = hex(n) | 267 hn = hex(n) |
266 | 268 |
267 yield self.t('searchentry', | 269 yield self.t('searchentry', |
268 parity=count & 1, | 270 parity=self.stripes(count), |
269 author=changes[1], | 271 author=changes[1], |
270 parent=self.siblings(cl.parents(n), cl.rev), | 272 parent=self.siblings(cl.parents(n), cl.rev), |
271 child=self.siblings(cl.children(n), cl.rev), | 273 child=self.siblings(cl.children(n), cl.rev), |
272 changelogtag=self.showtag("changelogtag",n), | 274 changelogtag=self.showtag("changelogtag",n), |
273 manifest=hex(changes[0]), | 275 manifest=hex(changes[0]), |
374 | 376 |
375 def lines(): | 377 def lines(): |
376 for l, t in enumerate(text.splitlines(1)): | 378 for l, t in enumerate(text.splitlines(1)): |
377 yield {"line": t, | 379 yield {"line": t, |
378 "linenumber": "% 6d" % (l + 1), | 380 "linenumber": "% 6d" % (l + 1), |
379 "parity": l & 1} | 381 "parity": self.stripes(l)} |
380 | 382 |
381 yield self.t("filerevision", | 383 yield self.t("filerevision", |
382 file=f, | 384 file=f, |
383 filenode=node, | 385 filenode=node, |
384 path=_up(f), | 386 path=_up(f), |
407 cn = cl.node(changerev) | 409 cn = cl.node(changerev) |
408 cs = cl.read(cn) | 410 cs = cl.read(cn) |
409 mfn = cs[0] | 411 mfn = cs[0] |
410 | 412 |
411 def annotate(**map): | 413 def annotate(**map): |
412 parity = 1 | 414 parity = 0 |
413 last = None | 415 last = None |
414 for r, l in fl.annotate(n): | 416 for r, l in fl.annotate(n): |
415 try: | 417 try: |
416 cnode = ncache[r] | 418 cnode = ncache[r] |
417 except KeyError: | 419 except KeyError: |
487 continue | 489 continue |
488 | 490 |
489 yield {"file": full, | 491 yield {"file": full, |
490 "manifest": mnode, | 492 "manifest": mnode, |
491 "filenode": hex(fnode), | 493 "filenode": hex(fnode), |
492 "parity": parity, | 494 "parity": self.stripes(parity), |
493 "basename": f, | 495 "basename": f, |
494 "permissions": mff[full]} | 496 "permissions": mff[full]} |
495 parity = 1 - parity | 497 parity += 1 |
496 | 498 |
497 def dirlist(**map): | 499 def dirlist(**map): |
498 parity = 0 | 500 parity = 0 |
499 fl = files.keys() | 501 fl = files.keys() |
500 fl.sort() | 502 fl.sort() |
501 for f in fl: | 503 for f in fl: |
502 full, fnode = files[f] | 504 full, fnode = files[f] |
503 if fnode: | 505 if fnode: |
504 continue | 506 continue |
505 | 507 |
506 yield {"parity": parity, | 508 yield {"parity": self.stripes(parity), |
507 "path": os.path.join(path, f), | 509 "path": os.path.join(path, f), |
508 "manifest": mnode, | 510 "manifest": mnode, |
509 "basename": f[:-1]} | 511 "basename": f[:-1]} |
510 parity = 1 - parity | 512 parity += 1 |
511 | 513 |
512 yield self.t("manifest", | 514 yield self.t("manifest", |
513 manifest=mnode, | 515 manifest=mnode, |
514 rev=rev, | 516 rev=rev, |
515 node=hex(node), | 517 node=hex(node), |
528 | 530 |
529 def entries(notip=False, **map): | 531 def entries(notip=False, **map): |
530 parity = 0 | 532 parity = 0 |
531 for k,n in i: | 533 for k,n in i: |
532 if notip and k == "tip": continue | 534 if notip and k == "tip": continue |
533 yield {"parity": parity, | 535 yield {"parity": self.stripes(parity), |
534 "tag": k, | 536 "tag": k, |
535 "tagmanifest": hex(cl.read(n)[0]), | 537 "tagmanifest": hex(cl.read(n)[0]), |
536 "date": cl.read(n)[2], | 538 "date": cl.read(n)[2], |
537 "node": hex(n)} | 539 "node": hex(n)} |
538 parity = 1 - parity | 540 parity += 1 |
539 | 541 |
540 yield self.t("tags", | 542 yield self.t("tags", |
541 manifest=hex(mf), | 543 manifest=hex(mf), |
542 entries=lambda **x: entries(False, **x), | 544 entries=lambda **x: entries(False, **x), |
543 entriesnotip=lambda **x: entries(True, **x)) | 545 entriesnotip=lambda **x: entries(True, **x)) |
563 c = cl.read(n) | 565 c = cl.read(n) |
564 m = c[0] | 566 m = c[0] |
565 t = c[2] | 567 t = c[2] |
566 | 568 |
567 yield self.t("tagentry", | 569 yield self.t("tagentry", |
568 parity = parity, | 570 parity = self.stripes(parity), |
569 tag = k, | 571 tag = k, |
570 node = hex(n), | 572 node = hex(n), |
571 date = t, | 573 date = t, |
572 tagmanifest = hex(m)) | 574 tagmanifest = hex(m)) |
573 parity = 1 - parity | 575 parity += 1 |
574 | 576 |
575 def changelist(**map): | 577 def changelist(**map): |
576 parity = 0 | 578 parity = 0 |
577 cl = self.repo.changelog | 579 cl = self.repo.changelog |
578 l = [] # build a list in forward order for efficiency | 580 l = [] # build a list in forward order for efficiency |
750 if method: | 752 if method: |
751 method(req) | 753 method(req) |
752 else: | 754 else: |
753 req.write(self.t("error")) | 755 req.write(self.t("error")) |
754 | 756 |
757 def stripes(self, parity): | |
758 "make horizontal stripes for easier reading" | |
759 if self.stripecount: | |
760 return (1 + parity / self.stripecount) & 1 | |
761 else: | |
762 return 0 | |
763 | |
755 def do_changelog(self, req): | 764 def do_changelog(self, req): |
756 hi = self.repo.changelog.count() - 1 | 765 hi = self.repo.changelog.count() - 1 |
757 if req.form.has_key('rev'): | 766 if req.form.has_key('rev'): |
758 hi = req.form['rev'][0] | 767 hi = req.form['rev'][0] |
759 try: | 768 try: |