[PATCH] hgweb: teach archive how to handle file patterns

Angel Ezquerra angel.ezquerra at gmail.com
Wed Feb 6 11:24:02 CST 2013


# HG changeset patch
# User Angel Ezquerra <angel.ezquerra at gmail.com>
# 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:

1. http://mercurial.selenic.com/hg/tip.zip/mercurial/templates

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

2. http://mercurial.selenic.com/hg/tip.tar.gz/relglob:*.py

    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/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -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 []
 


More information about the Mercurial-devel mailing list