Show More
@@ -37,6 +37,8 b' class hgweb(object):' | |||
|
37 | 37 | self.mtime = -1 |
|
38 | 38 | self.reponame = name |
|
39 | 39 | self.archives = 'zip', 'gz', 'bz2' |
|
40 | self.templatepath = self.repo.ui.config("web", "templates", | |
|
41 | templater.templatepath()) | |
|
40 | 42 | |
|
41 | 43 | def refresh(self): |
|
42 | 44 | mtime = get_mtime(self.repo.root) |
@@ -644,13 +646,13 b' class hgweb(object):' | |||
|
644 | 646 | # tags -> list of changesets corresponding to tags |
|
645 | 647 | # find tag, changeset, file |
|
646 | 648 | |
|
649 | def cleanpath(self, path): | |
|
650 | p = util.normpath(path) | |
|
651 | if p[:2] == "..": | |
|
652 | raise Exception("suspicious path") | |
|
653 | return p | |
|
654 | ||
|
647 | 655 | def run(self, req=hgrequest()): |
|
648 | def clean(path): | |
|
649 | p = util.normpath(path) | |
|
650 | if p[:2] == "..": | |
|
651 | raise Exception("suspicious path") | |
|
652 | return p | |
|
653 | ||
|
654 | 656 | def header(**map): |
|
655 | 657 | yield self.t("header", **map) |
|
656 | 658 | |
@@ -686,15 +688,13 b' class hgweb(object):' | |||
|
686 | 688 | |
|
687 | 689 | expand_form(req.form) |
|
688 | 690 | |
|
689 | t = self.repo.ui.config("web", "templates", templater.templatepath()) | |
|
690 | static = self.repo.ui.config("web", "static", os.path.join(t,"static")) | |
|
691 | m = os.path.join(t, "map") | |
|
691 | m = os.path.join(self.templatepath, "map") | |
|
692 | 692 | style = self.repo.ui.config("web", "style", "") |
|
693 | 693 | if req.form.has_key('style'): |
|
694 | 694 | style = req.form['style'][0] |
|
695 | 695 | if style: |
|
696 | 696 | b = os.path.basename("map-" + style) |
|
697 | p = os.path.join(t, b) | |
|
697 | p = os.path.join(self.templatepath, b) | |
|
698 | 698 | if os.path.isfile(p): |
|
699 | 699 | m = p |
|
700 | 700 | |
@@ -719,110 +719,117 b' class hgweb(object):' | |||
|
719 | 719 | req.form['cmd'] = [self.t.cache['default'],] |
|
720 | 720 | |
|
721 | 721 | cmd = req.form['cmd'][0] |
|
722 | if cmd == 'changelog': | |
|
723 | hi = self.repo.changelog.count() - 1 | |
|
724 | if req.form.has_key('rev'): | |
|
725 | hi = req.form['rev'][0] | |
|
726 | try: | |
|
727 | hi = self.repo.changelog.rev(self.repo.lookup(hi)) | |
|
728 | except hg.RepoError: | |
|
729 | req.write(self.search(hi)) # XXX redirect to 404 page? | |
|
730 | return | |
|
731 | 722 | |
|
732 | req.write(self.changelog(hi)) | |
|
733 | ||
|
734 | elif cmd == 'changeset': | |
|
735 | req.write(self.changeset(req.form['node'][0])) | |
|
736 | ||
|
737 | elif cmd == 'manifest': | |
|
738 | req.write(self.manifest(req.form['manifest'][0], | |
|
739 | clean(req.form['path'][0]))) | |
|
740 | ||
|
741 | elif cmd == 'tags': | |
|
742 | req.write(self.tags()) | |
|
743 | ||
|
744 | elif cmd == 'summary': | |
|
745 | req.write(self.summary()) | |
|
746 | ||
|
747 | elif cmd == 'filediff': | |
|
748 | req.write(self.filediff(clean(req.form['file'][0]), | |
|
749 | req.form['node'][0])) | |
|
750 | ||
|
751 | elif cmd == 'file': | |
|
752 | req.write(self.filerevision(clean(req.form['file'][0]), | |
|
753 | req.form['filenode'][0])) | |
|
754 | ||
|
755 | elif cmd == 'annotate': | |
|
756 | req.write(self.fileannotate(clean(req.form['file'][0]), | |
|
757 | req.form['filenode'][0])) | |
|
758 | ||
|
759 | elif cmd == 'filelog': | |
|
760 | req.write(self.filelog(clean(req.form['file'][0]), | |
|
761 | req.form['filenode'][0])) | |
|
762 | ||
|
763 | elif cmd == 'heads': | |
|
764 | resp = " ".join(map(hex, self.repo.heads())) + "\n" | |
|
765 | req.httphdr("application/mercurial-0.1", length=len(resp)) | |
|
766 | req.write(resp) | |
|
767 | ||
|
768 | elif cmd == 'branches': | |
|
769 | nodes = [] | |
|
770 | if req.form.has_key('nodes'): | |
|
771 | nodes = map(bin, req.form['nodes'][0].split(" ")) | |
|
772 | resp = cStringIO.StringIO() | |
|
773 | for b in self.repo.branches(nodes): | |
|
774 | resp.write(" ".join(map(hex, b)) + "\n") | |
|
775 | resp = resp.getvalue() | |
|
776 | req.httphdr("application/mercurial-0.1", length=len(resp)) | |
|
777 | req.write(resp) | |
|
778 | ||
|
779 | elif cmd == 'between': | |
|
780 | nodes = [] | |
|
781 | if req.form.has_key('pairs'): | |
|
782 | pairs = [map(bin, p.split("-")) | |
|
783 | for p in req.form['pairs'][0].split(" ")] | |
|
784 | resp = cStringIO.StringIO() | |
|
785 | for b in self.repo.between(pairs): | |
|
786 | resp.write(" ".join(map(hex, b)) + "\n") | |
|
787 | resp = resp.getvalue() | |
|
788 | req.httphdr("application/mercurial-0.1", length=len(resp)) | |
|
789 | req.write(resp) | |
|
790 | ||
|
791 | elif cmd == 'changegroup': | |
|
792 | req.httphdr("application/mercurial-0.1") | |
|
793 | nodes = [] | |
|
794 | if not self.allowpull: | |
|
795 | return | |
|
796 | ||
|
797 | if req.form.has_key('roots'): | |
|
798 | nodes = map(bin, req.form['roots'][0].split(" ")) | |
|
799 | ||
|
800 | z = zlib.compressobj() | |
|
801 | f = self.repo.changegroup(nodes, 'serve') | |
|
802 | while 1: | |
|
803 | chunk = f.read(4096) | |
|
804 | if not chunk: | |
|
805 | break | |
|
806 | req.write(z.compress(chunk)) | |
|
807 | ||
|
808 | req.write(z.flush()) | |
|
809 | ||
|
810 | elif cmd == 'archive': | |
|
811 | changeset = self.repo.lookup(req.form['node'][0]) | |
|
812 | type_ = req.form['type'][0] | |
|
813 | allowed = self.repo.ui.config("web", "allow_archive", "").split() | |
|
814 | if (type_ in self.archives and (type_ in allowed or | |
|
815 | self.repo.ui.configbool("web", "allow" + type_, False))): | |
|
816 | self.archive(req, changeset, type_) | |
|
817 | return | |
|
818 | ||
|
819 | req.write(self.t("error")) | |
|
820 | ||
|
821 | elif cmd == 'static': | |
|
822 | fname = req.form['file'][0] | |
|
823 | req.write(staticfile(static, fname) | |
|
824 | or self.t("error", error="%r not found" % fname)) | |
|
825 | ||
|
723 | method = getattr(self, 'do_' + cmd, None) | |
|
724 | if method: | |
|
725 | method(req) | |
|
826 | 726 | else: |
|
827 | 727 | req.write(self.t("error")) |
|
828 | 728 | req.done() |
|
729 | ||
|
730 | def do_changelog(self, req): | |
|
731 | hi = self.repo.changelog.count() - 1 | |
|
732 | if req.form.has_key('rev'): | |
|
733 | hi = req.form['rev'][0] | |
|
734 | try: | |
|
735 | hi = self.repo.changelog.rev(self.repo.lookup(hi)) | |
|
736 | except hg.RepoError: | |
|
737 | req.write(self.search(hi)) # XXX redirect to 404 page? | |
|
738 | return | |
|
739 | ||
|
740 | req.write(self.changelog(hi)) | |
|
741 | ||
|
742 | def do_changeset(self, req): | |
|
743 | req.write(self.changeset(req.form['node'][0])) | |
|
744 | ||
|
745 | def do_manifest(self, req): | |
|
746 | req.write(self.manifest(req.form['manifest'][0], | |
|
747 | self.cleanpath(req.form['path'][0]))) | |
|
748 | ||
|
749 | def do_tags(self, req): | |
|
750 | req.write(self.tags()) | |
|
751 | ||
|
752 | def do_summary(self, req): | |
|
753 | req.write(self.summary()) | |
|
754 | ||
|
755 | def do_filediff(self, req): | |
|
756 | req.write(self.filediff(self.cleanpath(req.form['file'][0]), | |
|
757 | req.form['node'][0])) | |
|
758 | ||
|
759 | def do_file(self, req): | |
|
760 | req.write(self.filerevision(self.cleanpath(req.form['file'][0]), | |
|
761 | req.form['filenode'][0])) | |
|
762 | ||
|
763 | def do_annotate(self, req): | |
|
764 | req.write(self.fileannotate(self.cleanpath(req.form['file'][0]), | |
|
765 | req.form['filenode'][0])) | |
|
766 | ||
|
767 | def do_filelog(self, req): | |
|
768 | req.write(self.filelog(self.cleanpath(req.form['file'][0]), | |
|
769 | req.form['filenode'][0])) | |
|
770 | ||
|
771 | def do_heads(self, req): | |
|
772 | resp = " ".join(map(hex, self.repo.heads())) + "\n" | |
|
773 | req.httphdr("application/mercurial-0.1", length=len(resp)) | |
|
774 | req.write(resp) | |
|
775 | ||
|
776 | def do_branches(self, req): | |
|
777 | nodes = [] | |
|
778 | if req.form.has_key('nodes'): | |
|
779 | nodes = map(bin, req.form['nodes'][0].split(" ")) | |
|
780 | resp = cStringIO.StringIO() | |
|
781 | for b in self.repo.branches(nodes): | |
|
782 | resp.write(" ".join(map(hex, b)) + "\n") | |
|
783 | resp = resp.getvalue() | |
|
784 | req.httphdr("application/mercurial-0.1", length=len(resp)) | |
|
785 | req.write(resp) | |
|
786 | ||
|
787 | def do_between(self, req): | |
|
788 | nodes = [] | |
|
789 | if req.form.has_key('pairs'): | |
|
790 | pairs = [map(bin, p.split("-")) | |
|
791 | for p in req.form['pairs'][0].split(" ")] | |
|
792 | resp = cStringIO.StringIO() | |
|
793 | for b in self.repo.between(pairs): | |
|
794 | resp.write(" ".join(map(hex, b)) + "\n") | |
|
795 | resp = resp.getvalue() | |
|
796 | req.httphdr("application/mercurial-0.1", length=len(resp)) | |
|
797 | req.write(resp) | |
|
798 | ||
|
799 | def do_changegroup(self, req): | |
|
800 | req.httphdr("application/mercurial-0.1") | |
|
801 | nodes = [] | |
|
802 | if not self.allowpull: | |
|
803 | return | |
|
804 | ||
|
805 | if req.form.has_key('roots'): | |
|
806 | nodes = map(bin, req.form['roots'][0].split(" ")) | |
|
807 | ||
|
808 | z = zlib.compressobj() | |
|
809 | f = self.repo.changegroup(nodes, 'serve') | |
|
810 | while 1: | |
|
811 | chunk = f.read(4096) | |
|
812 | if not chunk: | |
|
813 | break | |
|
814 | req.write(z.compress(chunk)) | |
|
815 | ||
|
816 | req.write(z.flush()) | |
|
817 | ||
|
818 | def do_archive(self, req): | |
|
819 | changeset = self.repo.lookup(req.form['node'][0]) | |
|
820 | type_ = req.form['type'][0] | |
|
821 | allowed = self.repo.ui.config("web", "allow_archive", "").split() | |
|
822 | if (type_ in self.archives and (type_ in allowed or | |
|
823 | self.repo.ui.configbool("web", "allow" + type_, False))): | |
|
824 | self.archive(req, changeset, type_) | |
|
825 | return | |
|
826 | ||
|
827 | req.write(self.t("error")) | |
|
828 | ||
|
829 | def do_static(self, req): | |
|
830 | fname = req.form['file'][0] | |
|
831 | static = self.repo.ui.config("web", "static", | |
|
832 | os.path.join(self.templatepath, | |
|
833 | "static")) | |
|
834 | req.write(staticfile(static, fname) | |
|
835 | or self.t("error", error="%r not found" % fname)) |
General Comments 0
You need to be logged in to leave comments.
Login now