Patchwork hgweb: teach archive how to handle file patterns

mail settings
Submitter Angel Ezquerra
Date Feb. 6, 2013, 5:24 p.m.
Message ID <afcc0c47345e45fbf785.1360171442@Angel-PC.localdomain>
Download mbox | patch
Permalink /patch/819/
State Superseded
Headers show


Angel Ezquerra - Feb. 6, 2013, 5:24 p.m.
# HG changeset patch
# User Angel Ezquerra <>
# Date 1360141605 -3600
# Node ID afcc0c47345e45fbf785891fb010ead888851569
# Parent  1516d5624a2911fcb90ee051c6dc0679b49aef55
hgweb: teach archive how to handle file patterns

The archive web command now takes into account the "file" request entry, if one
is provided.

The provided "file" is processed as a "path" pattern by default, which makes it
easy to only archive a certain file or directory. However, it is possible to
specify a different type of pattern, such as relglob by specifying it
explicitly on the query URL.

With this change hgweb can to process requests such as:


    This will download all files on the mercurial/templates directory as a zip


    This will download all *.py files in the repository into a tar.gz file.

An so forth.

Note that this is a first step to add support for downloading directories from
the web interface. Currently the only way to use this feature is by manually
constructing the URL that you want to download. We will have to modify the
archiveentry map entry on the different templates so that it adds the current
folder path to the archive links.


diff --git a/mercurial/hgweb/ b/mercurial/hgweb/
--- a/mercurial/hgweb/
+++ b/mercurial/hgweb/
@@ -813,8 +813,13 @@ 
     req.respond(HTTP_OK, mimetype)
     ctx = webutil.changectx(web.repo, req)
+    pats = []
+    file = req.form.get('file', None)
+    if file:
+        pats = [req.form['file'][0]]
+    matchfn = scmutil.match(ctx, pats, default='path')
     archival.archive(web.repo, req, cnode, artype, prefix=name,
-                     matchfn=scmutil.match(ctx, []),
+                     matchfn=matchfn,
                      subrepos=web.configbool("web", "archivesubrepos"))
     return []