Show More
@@ -10,8 +10,8 b' import os, cgi, sys' | |||
|
10 | 10 | import mimetypes |
|
11 | 11 | from demandload import demandload |
|
12 | 12 | demandload(globals(), "mdiff time re socket zlib errno ui hg ConfigParser") |
|
13 |
demandload(globals(), " |
|
|
14 | demandload(globals(), "mimetypes templater") | |
|
13 | demandload(globals(), "tempfile StringIO BaseHTTPServer util") | |
|
14 | demandload(globals(), "archival mimetypes templater") | |
|
15 | 15 | from node import * |
|
16 | 16 | from i18n import gettext as _ |
|
17 | 17 | |
@@ -682,55 +682,23 b' class hgweb(object):' | |||
|
682 | 682 | child=self.siblings(cl.children(n), cl.rev), |
|
683 | 683 | diff=diff) |
|
684 | 684 | |
|
685 | def archive(self, req, cnode, type): | |
|
686 | cs = self.repo.changelog.read(cnode) | |
|
687 | mnode = cs[0] | |
|
688 | mf = self.repo.manifest.read(mnode) | |
|
689 | rev = self.repo.manifest.rev(mnode) | |
|
690 | reponame = re.sub(r"\W+", "-", self.reponame) | |
|
691 | name = "%s-%s/" % (reponame, short(cnode)) | |
|
692 | ||
|
693 | files = mf.keys() | |
|
694 | files.sort() | |
|
695 | ||
|
696 | if type == 'zip': | |
|
697 | tmp = tempfile.mkstemp()[1] | |
|
698 | try: | |
|
699 | zf = zipfile.ZipFile(tmp, "w", zipfile.ZIP_DEFLATED) | |
|
700 | ||
|
701 | for f in files: | |
|
702 | zf.writestr(name + f, self.repo.file(f).read(mf[f])) | |
|
703 | zf.close() | |
|
685 | archive_specs = { | |
|
686 | 'bz2': ('application/x-tar', 'tbz2', '.tar.bz2', 'x-bzip2'), | |
|
687 | 'gz': ('application/x-tar', 'tgz', '.tar.gz', 'x-gzip'), | |
|
688 | 'zip': ('application/zip', 'zip', '.zip', None), | |
|
689 | } | |
|
704 | 690 | |
|
705 | f = open(tmp, 'r') | |
|
706 | req.httphdr('application/zip', name[:-1] + '.zip', | |
|
707 | os.path.getsize(tmp)) | |
|
708 | req.write(f.read()) | |
|
709 | f.close() | |
|
710 | finally: | |
|
711 | os.unlink(tmp) | |
|
712 | ||
|
713 | else: | |
|
714 | tf = tarfile.TarFile.open(mode='w|' + type, fileobj=req.out) | |
|
715 | mff = self.repo.manifest.readflags(mnode) | |
|
716 | mtime = int(time.time()) | |
|
717 | ||
|
718 | if type == "gz": | |
|
719 | encoding = "gzip" | |
|
720 | else: | |
|
721 | encoding = "x-bzip2" | |
|
722 | req.header([('Content-type', 'application/x-tar'), | |
|
723 | ('Content-disposition', 'attachment; filename=%s%s%s' % | |
|
724 | (name[:-1], '.tar.', type)), | |
|
725 | ('Content-encoding', encoding)]) | |
|
726 | for fname in files: | |
|
727 | rcont = self.repo.file(fname).read(mf[fname]) | |
|
728 | finfo = tarfile.TarInfo(name + fname) | |
|
729 | finfo.mtime = mtime | |
|
730 | finfo.size = len(rcont) | |
|
731 | finfo.mode = mff[fname] and 0755 or 0644 | |
|
732 | tf.addfile(finfo, StringIO.StringIO(rcont)) | |
|
733 | tf.close() | |
|
691 | def archive(self, req, cnode, type): | |
|
692 | reponame = re.sub(r"\W+", "-", os.path.basename(self.reponame)) | |
|
693 | name = "%s-%s" % (reponame, short(cnode)) | |
|
694 | mimetype, artype, extension, encoding = self.archive_specs[type] | |
|
695 | headers = [('Content-type', mimetype), | |
|
696 | ('Content-disposition', 'attachment; filename=%s%s' % | |
|
697 | (name, extension))] | |
|
698 | if encoding: | |
|
699 | headers.append(('Content-encoding', encoding)) | |
|
700 | req.header(headers) | |
|
701 | archival.archive(self.repo, req.out, cnode, artype, prefix=name) | |
|
734 | 702 | |
|
735 | 703 | # add tags to things |
|
736 | 704 | # tags -> list of changesets corresponding to tags |
General Comments 0
You need to be logged in to leave comments.
Login now