Mercurial > hg-stable
comparison mercurial/hgweb/hgweb_mod.py @ 3226:5c6028778c5a
hgweb: add methods to get contexts from request
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Sun, 01 Oct 2006 12:56:58 -0700 |
parents | 325278542ea8 |
children | 35d61e653174 |
comparison
equal
deleted
inserted
replaced
3225:dedddde58c5b | 3226:5c6028778c5a |
---|---|
646 if value is None: | 646 if value is None: |
647 value = form[k] | 647 value = form[k] |
648 form[name] = value | 648 form[name] = value |
649 del form[k] | 649 del form[k] |
650 | 650 |
651 if form.has_key('manifest'): | |
652 changeid = form['manifest'][0] | |
653 try: | |
654 req.changectx = self.repo.changectx(changeid) | |
655 except hg.RepoError: | |
656 man = self.repo.manifest | |
657 mn = man.lookup(changeid) | |
658 req.changectx = self.repo.changectx(man.linkrev(mn)) | |
659 | |
660 if form.has_key('filenode'): | |
661 changeid = form['filenode'][0] | |
662 path = self.cleanpath(form['file'][0]) | |
663 try: | |
664 req.changectx = self.repo.changectx(changeid) | |
665 req.filectx = req.changectx.filectx(path) | |
666 except hg.RepoError: | |
667 req.filectx = self.repo.filectx(path, fileid=changeid) | |
668 req.changectx = req.filectx.changectx() | |
669 | |
670 self.refresh() | 651 self.refresh() |
671 | 652 |
672 expand_form(req.form) | 653 expand_form(req.form) |
673 | 654 |
674 m = os.path.join(self.templatepath, "map") | 655 m = os.path.join(self.templatepath, "map") |
708 if method: | 689 if method: |
709 method(req) | 690 method(req) |
710 else: | 691 else: |
711 req.write(self.t("error")) | 692 req.write(self.t("error")) |
712 | 693 |
694 def changectx(self, req): | |
695 if req.form.has_key('node'): | |
696 changeid = req.form['node'][0] | |
697 else: | |
698 changeid = req.form['manifest'][0] | |
699 try: | |
700 ctx = self.repo.changectx(changeid) | |
701 except hg.RepoError: | |
702 man = self.repo.manifest | |
703 mn = man.lookup(changeid) | |
704 ctx = self.repo.changectx(man.linkrev(mn)) | |
705 | |
706 return ctx | |
707 | |
708 def filectx(self, req): | |
709 path = self.cleanpath(req.form['file'][0]) | |
710 if req.form.has_key('node'): | |
711 changeid = req.form['node'][0] | |
712 else: | |
713 changeid = req.form['filenode'][0] | |
714 try: | |
715 ctx = self.repo.changectx(changeid) | |
716 fctx = ctx.filectx(path) | |
717 except hg.RepoError: | |
718 fctx = self.repo.filectx(path, fileid=changeid) | |
719 | |
720 return fctx | |
721 | |
713 def stripes(self, parity): | 722 def stripes(self, parity): |
714 "make horizontal stripes for easier reading" | 723 "make horizontal stripes for easier reading" |
715 if self.stripecount: | 724 if self.stripecount: |
716 return (1 + parity / self.stripecount) & 1 | 725 return (1 + parity / self.stripecount) & 1 |
717 else: | 726 else: |
718 return 0 | 727 return 0 |
719 | 728 |
720 def do_changelog(self, req): | 729 def do_changelog(self, req, shortlog = False): |
721 if req.form.has_key('rev'): | 730 if req.form.has_key('node'): |
722 hi = req.form['rev'][0] | 731 ctx = self.changectx(req) |
723 else: | 732 else: |
724 hi = self.repo.changelog.count() - 1 | 733 if req.form.has_key('rev'): |
725 try: | 734 hi = req.form['rev'][0] |
726 ctx = self.repo.changectx(hi) | 735 else: |
727 except hg.RepoError: | 736 hi = self.repo.changelog.count() - 1 |
728 req.write(self.search(hi)) # XXX redirect to 404 page? | 737 try: |
729 return | 738 ctx = self.repo.changectx(hi) |
730 | 739 except hg.RepoError: |
731 req.write(self.changelog(ctx)) | 740 req.write(self.search(hi)) # XXX redirect to 404 page? |
741 return | |
742 | |
743 req.write(self.changelog(ctx, shortlog = shortlog)) | |
732 | 744 |
733 def do_shortlog(self, req): | 745 def do_shortlog(self, req): |
734 if req.form.has_key('rev'): | 746 self.do_changelog(req, shortlog = True) |
735 hi = req.form['rev'][0] | |
736 else: | |
737 hi = self.repo.changelog.count() - 1 | |
738 try: | |
739 hi = self.repo.changectx(hi) | |
740 except hg.RepoError: | |
741 req.write(self.search(hi)) # XXX redirect to 404 page? | |
742 return | |
743 | |
744 req.write(self.changelog(ctx, shortlog = True)) | |
745 | 747 |
746 def do_changeset(self, req): | 748 def do_changeset(self, req): |
747 ctx = self.repo.changectx(req.form['node'][0]) | 749 ctx = self.repo.changectx(req.form['node'][0]) |
748 req.write(self.changeset(ctx)) | 750 req.write(self.changeset(ctx)) |
749 | 751 |
750 def do_manifest(self, req): | 752 def do_manifest(self, req): |
751 req.write(self.manifest(req.changectx, | 753 req.write(self.manifest(self.changectx(req), |
752 self.cleanpath(req.form['path'][0]))) | 754 self.cleanpath(req.form['path'][0]))) |
753 | 755 |
754 def do_tags(self, req): | 756 def do_tags(self, req): |
755 req.write(self.tags()) | 757 req.write(self.tags()) |
756 | 758 |
757 def do_summary(self, req): | 759 def do_summary(self, req): |
758 req.write(self.summary()) | 760 req.write(self.summary()) |
759 | 761 |
760 def do_filediff(self, req): | 762 def do_filediff(self, req): |
761 ctx = self.repo.changectx(req.form['node'][0]) | 763 req.write(self.filediff(self.filectx(req))) |
762 fctx = ctx.filectx(self.cleanpath(req.form['file'][0])) | |
763 req.write(self.filediff(fctx)) | |
764 | 764 |
765 def do_file(self, req): | 765 def do_file(self, req): |
766 req.write(self.filerevision(req.filectx)) | 766 req.write(self.filerevision(self.filectx(req))) |
767 | 767 |
768 def do_annotate(self, req): | 768 def do_annotate(self, req): |
769 req.write(self.fileannotate(req.filectx)) | 769 req.write(self.fileannotate(self.filectx(req))) |
770 | 770 |
771 def do_filelog(self, req): | 771 def do_filelog(self, req): |
772 req.write(self.filelog(req.filectx)) | 772 req.write(self.filelog(self.filectx(req))) |
773 | 773 |
774 def do_heads(self, req): | 774 def do_heads(self, req): |
775 resp = " ".join(map(hex, self.repo.heads())) + "\n" | 775 resp = " ".join(map(hex, self.repo.heads())) + "\n" |
776 req.httphdr("application/mercurial-0.1", length=len(resp)) | 776 req.httphdr("application/mercurial-0.1", length=len(resp)) |
777 req.write(resp) | 777 req.write(resp) |