Show More
@@ -158,6 +158,7 b' class hgweb:' | |||
|
158 | 158 | self.mtime = -1 |
|
159 | 159 | self.reponame = name or self.repo.ui.config("web", "name", |
|
160 | 160 | self.repo.root) |
|
161 | self.supportedtarballs = 'zip', 'gz', 'bz2' | |
|
161 | 162 | |
|
162 | 163 | def refresh(self): |
|
163 | 164 | s = os.stat(os.path.join(self.repo.root, ".hg", "00changelog.i")) |
@@ -167,9 +168,10 b' class hgweb:' | |||
|
167 | 168 | self.maxchanges = self.repo.ui.config("web", "maxchanges", 10) |
|
168 | 169 | self.maxfiles = self.repo.ui.config("web", "maxchanges", 10) |
|
169 | 170 | self.allowpull = self.repo.ui.configbool("web", "allowpull", True) |
|
170 | self.allowzip = self.repo.ui.configbool("web", "zip", True) | |
|
171 | self.allowgz = self.repo.ui.configbool("web", "gz", True) | |
|
172 |
|
|
|
171 | self.allowedtarballs = [] | |
|
172 | for i in self.supportedtarballs: | |
|
173 | if self.repo.ui.configbool("web", i, True): | |
|
174 | self.allowedtarballs.append(i) | |
|
173 | 175 | |
|
174 | 176 | def date(self, cs): |
|
175 | 177 | return time.asctime(time.gmtime(float(cs[2].split(' ')[0]))) |
@@ -197,16 +199,6 b' class hgweb:' | |||
|
197 | 199 | for t in self.repo.nodetags(node): |
|
198 | 200 | yield self.t(t1, tag=t, **args) |
|
199 | 201 | |
|
200 | def tarballbuttons(self, m): | |
|
201 | s = '' | |
|
202 | if self.allowzip: | |
|
203 | s += '<a href="?cmd=tarball;manifest=%s;type=zip">zip</a>\n' % m | |
|
204 | if self.allowgz: | |
|
205 | s += '<a href="?cmd=tarball;manifest=%s;type=gz">gz</a>\n' % m | |
|
206 | if self.allowbz2: | |
|
207 | s += '<a href="?cmd=tarball;manifest=%s;type=bz2">bz2</a>\n' % m | |
|
208 | return s | |
|
209 | ||
|
210 | 202 | def diff(self, node1, node2, files): |
|
211 | 203 | def filterfiles(list, files): |
|
212 | 204 | l = [x for x in list if x in files] |
@@ -403,6 +395,11 b' class hgweb:' | |||
|
403 | 395 | def diff(**map): |
|
404 | 396 | yield self.diff(p1, n, None) |
|
405 | 397 | |
|
398 | def tarballs(): | |
|
399 | for i in self.allowedtarballs: | |
|
400 | yield {"type" : i, | |
|
401 | "manifest" : hex(changes[0])} | |
|
402 | ||
|
406 | 403 | yield self.t('changeset', |
|
407 | 404 | diff=diff, |
|
408 | 405 | rev=cl.rev(n), |
@@ -415,7 +412,7 b' class hgweb:' | |||
|
415 | 412 | desc=changes[4], |
|
416 | 413 | date=t, |
|
417 | 414 | files=files, |
|
418 |
tarballb |
|
|
415 | tarballbs = tarballs()) | |
|
419 | 416 | |
|
420 | 417 | def filelog(self, f, filenode): |
|
421 | 418 | cl = self.repo.changelog |
@@ -643,57 +640,58 b' class hgweb:' | |||
|
643 | 640 | cl.parents(n), cl.rev), |
|
644 | 641 | diff=diff) |
|
645 | 642 | |
|
646 |
def |
|
|
647 | import zipfile | |
|
648 | ||
|
649 | tmp = tempfile.mkstemp()[1] | |
|
650 | zf = zipfile.ZipFile(tmp, "w", zipfile.ZIP_DEFLATED) | |
|
651 | mf = self.repo.manifest.read(bin(mnode)) | |
|
652 | rev = self.repo.manifest.rev(bin(mnode)) | |
|
653 | cnode = short(self.repo.changelog.node(rev)) | |
|
654 | name = os.path.basename(self.repo.path[:-4]) # without '/.hg' suffix | |
|
655 | name += '-' + str(rev) + '-' + cnode + '/' | |
|
643 | def tarball(self, mnode, type): | |
|
644 | if type == 'zip': | |
|
645 | import zipfile | |
|
656 | 646 | |
|
657 | for fname in mf.keys(): | |
|
658 | r = self.repo.file(fname) | |
|
659 | zf.writestr(name + fname, r.read(mf[fname])) | |
|
660 | zf.close() | |
|
647 | tmp = tempfile.mkstemp()[1] | |
|
648 | zf = zipfile.ZipFile(tmp, "w", zipfile.ZIP_DEFLATED) | |
|
649 | mf = self.repo.manifest.read(bin(mnode)) | |
|
650 | rev = self.repo.manifest.rev(bin(mnode)) | |
|
651 | cnode = short(self.repo.changelog.node(rev)) | |
|
652 | name = os.path.basename(self.repo.path[:-4]) # without '/.hg' suffix | |
|
653 | name += '-' + str(rev) + '-' + cnode + '/' | |
|
661 | 654 | |
|
662 | f = open(tmp, 'r') | |
|
663 | httphdr('application/zip', name[:-1] + '.zip', os.path.getsize(tmp)) | |
|
664 | sys.stdout.write(f.read()) | |
|
665 | f.close() | |
|
666 | os.unlink(tmp) | |
|
655 | for fname in mf.keys(): | |
|
656 | r = self.repo.file(fname) | |
|
657 | zf.writestr(name + fname, r.read(mf[fname])) | |
|
658 | zf.close() | |
|
659 | ||
|
660 | f = open(tmp, 'r') | |
|
661 | httphdr('application/zip', name[:-1] + '.zip', os.path.getsize(tmp)) | |
|
662 | sys.stdout.write(f.read()) | |
|
663 | f.close() | |
|
664 | os.unlink(tmp) | |
|
667 | 665 | |
|
668 | def tararchive(self, mnode, type): | |
|
669 | import StringIO | |
|
670 | import time | |
|
671 | import tarfile | |
|
666 | else: | |
|
667 | import StringIO | |
|
668 | import time | |
|
669 | import tarfile | |
|
672 | 670 | |
|
673 | #if type == "gz": | |
|
674 | # tf = tarfile.TarFile.gzopen('', 'w', sys.stdout, compressionlevel) | |
|
675 | #else: | |
|
676 | # tf = tarfile.TarFile.bz2open('', 'w', sys.stdout, compressionlevel) | |
|
677 | tf = tarfile.TarFile.open(mode='w|' + type, fileobj=sys.stdout) | |
|
671 | #if type == "gz": | |
|
672 | # tf = tarfile.TarFile.gzopen('', 'w', sys.stdout, compressionlevel) | |
|
673 | #else: | |
|
674 | # tf = tarfile.TarFile.bz2open('', 'w', sys.stdout, compressionlevel) | |
|
675 | tf = tarfile.TarFile.open(mode='w|' + type, fileobj=sys.stdout) | |
|
678 | 676 | |
|
679 | mf = self.repo.manifest.read(bin(mnode)) | |
|
680 | rev = self.repo.manifest.rev(bin(mnode)) | |
|
681 | cnode = short(self.repo.changelog.node(rev)) | |
|
682 | mff = self.repo.manifest.readflags(bin(mnode)) | |
|
683 | mtime = int(time.time()) | |
|
684 | name = os.path.basename(self.repo.path[:-4]) # without '/.hg' suffix | |
|
685 | name += '-' + str(rev) + '-' + cnode + '/' | |
|
677 | mf = self.repo.manifest.read(bin(mnode)) | |
|
678 | rev = self.repo.manifest.rev(bin(mnode)) | |
|
679 | cnode = short(self.repo.changelog.node(rev)) | |
|
680 | mff = self.repo.manifest.readflags(bin(mnode)) | |
|
681 | mtime = int(time.time()) | |
|
682 | name = os.path.basename(self.repo.path[:-4]) # without '/.hg' suffix | |
|
683 | name += '-' + str(rev) + '-' + cnode + '/' | |
|
686 | 684 | |
|
687 | httphdr('application/octet-stream', name[:-1] + '.tar.' + type) | |
|
688 | for fname in mf.keys(): | |
|
689 | r = self.repo.file(fname) | |
|
690 | rcont = r.read(mf[fname]) | |
|
691 | finfo = tarfile.TarInfo(name + fname) | |
|
692 | finfo.mtime = mtime | |
|
693 | finfo.size = len(rcont) | |
|
694 | finfo.mode = mff[fname] and 0755 or 0644 | |
|
695 | tf.addfile(finfo, StringIO.StringIO(rcont)) | |
|
696 | tf.close() | |
|
685 | httphdr('application/octet-stream', name[:-1] + '.tar.' + type) | |
|
686 | for fname in mf.keys(): | |
|
687 | r = self.repo.file(fname) | |
|
688 | rcont = r.read(mf[fname]) | |
|
689 | finfo = tarfile.TarInfo(name + fname) | |
|
690 | finfo.mtime = mtime | |
|
691 | finfo.size = len(rcont) | |
|
692 | finfo.mode = mff[fname] and 0755 or 0644 | |
|
693 | tf.addfile(finfo, StringIO.StringIO(rcont)) | |
|
694 | tf.close() | |
|
697 | 695 | |
|
698 | 696 | # add tags to things |
|
699 | 697 | # tags -> list of changesets corresponding to tags |
@@ -815,14 +813,12 b' class hgweb:' | |||
|
815 | 813 | elif args['cmd'][0] == 'tarball': |
|
816 | 814 | manifest = args['manifest'][0] |
|
817 | 815 | type = args['type'][0] |
|
818 | if type == 'zip' and self.allowzip: | |
|
819 | self.ziparchive(manifest) | |
|
820 | elif type == 'gz' and self.allowgz: | |
|
821 | self.tararchive(manifest, 'gz') | |
|
822 | elif type == 'bz2' and self.allowbz2: | |
|
823 | self.tararchive(manifest, 'bz2') | |
|
824 | else: | |
|
825 | write(self.t("error")) | |
|
816 | for i in self.supportedtarballs: | |
|
817 | if type == i and i in self.allowedtarballs: | |
|
818 | self.tarball(manifest, type) | |
|
819 | return | |
|
820 | ||
|
821 | write(self.t("error")) | |
|
826 | 822 | |
|
827 | 823 | else: |
|
828 | 824 | write(self.t("error")) |
@@ -8,7 +8,7 b'' | |||
|
8 | 8 | <a href="?cmd=tags">tags</a> |
|
9 | 9 | <a href="?cmd=manifest;manifest=#manifest#;path=/">manifest</a> |
|
10 | 10 | <a href="?cmd=changeset;node=#node#;style=raw">raw</a> |
|
11 | #tarballbuttons# | |
|
11 | #tarballs%tarballentry# | |
|
12 | 12 | </div> |
|
13 | 13 | |
|
14 | 14 | <h2>changeset: #desc|escape|firstline#</h2> |
@@ -37,3 +37,4 b' filediffparent = "<tr><th class="parent"' | |||
|
37 | 37 | filelogparent = "<tr><td align="right">parent #rev#: </td><td><a href="?cmd=file;file=#file#;filenode=#node#">#node|short#</a></td></tr>" |
|
38 | 38 | indexentry = "<tr class="parity#parity#"><td><a href="#url#">#name#</a></td><td>#shortdesc#</td><td>#author# <i>#email|obfuscate#</i></td><td>#lastupdate|age# ago</td></tr>" |
|
39 | 39 | index = index.tmpl |
|
40 | archiveentry = "<a href="?cmd=archive;node=#node#;type=#type#">#type#</a> " No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now