comparison mercurial/hgweb/webcommands.py @ 18771:bb38f4f78104

hgweb: teach archive how to download a specific directory or file The archive web command now takes into account the "file" request entry, if one is provided. The provided "file" is processed as a "path" corresponding to a directory or file that will be downloaded. With this change hgweb can to process requests such as: http://mercurial.selenic.com/hg/archive/tip.zip/mercurial/templates This will download all files on the mercurial/templates directory as a zip file. It is not possible to specify file patterns ('glob', 'relglob', 'path', 'relpath', 're', 'relre' nor 'set'). The server will reject those with a 403 HTTP error response. Note that this is a first step to add support for downloading directories from the web interface. A following patch will modify the archiveentry map entry on the different templates so that it adds the current folder path to the archive links.
author Angel Ezquerra <angel.ezquerra@gmail.com>
date Sun, 10 Feb 2013 11:52:05 +0100
parents f5db3092790f
children 7d2a7f8e9da4
comparison
equal deleted inserted replaced
18770:dcb6a99e82ff 18771:bb38f4f78104
814 cnode = web.repo.lookup(key) 814 cnode = web.repo.lookup(key)
815 arch_version = key 815 arch_version = key
816 if cnode == key or key == 'tip': 816 if cnode == key or key == 'tip':
817 arch_version = short(cnode) 817 arch_version = short(cnode)
818 name = "%s-%s" % (reponame, arch_version) 818 name = "%s-%s" % (reponame, arch_version)
819
820 ctx = webutil.changectx(web.repo, req)
821 pats = []
822 file = req.form.get('file', None)
823 if file:
824 file = file[0]
825 patandfile = file.split(':')
826 if len(patandfile) > 1 and patandfile[0].lower() in ('glob', 'relglob',
827 'path', 'relpath', 're', 'relre', 'set'):
828 msg = 'Archive pattern not allowed: %s' % file
829 raise ErrorResponse(HTTP_FORBIDDEN, msg)
830 pats = ['path:' + file]
831
819 mimetype, artype, extension, encoding = web.archive_specs[type_] 832 mimetype, artype, extension, encoding = web.archive_specs[type_]
820 headers = [ 833 headers = [
821 ('Content-Disposition', 'attachment; filename=%s%s' % (name, extension)) 834 ('Content-Disposition', 'attachment; filename=%s%s' % (name, extension))
822 ] 835 ]
823 if encoding: 836 if encoding:
824 headers.append(('Content-Encoding', encoding)) 837 headers.append(('Content-Encoding', encoding))
825 req.headers.extend(headers) 838 req.headers.extend(headers)
826 req.respond(HTTP_OK, mimetype) 839 req.respond(HTTP_OK, mimetype)
827 840
828 ctx = webutil.changectx(web.repo, req) 841 matchfn = scmutil.match(ctx, pats, default='path')
829 archival.archive(web.repo, req, cnode, artype, prefix=name, 842 archival.archive(web.repo, req, cnode, artype, prefix=name,
830 matchfn=scmutil.match(ctx, []), 843 matchfn=matchfn,
831 subrepos=web.configbool("web", "archivesubrepos")) 844 subrepos=web.configbool("web", "archivesubrepos"))
832 return [] 845 return []
833 846
834 847
835 def static(web, req, tmpl): 848 def static(web, req, tmpl):