[PATCH] hgweb/localrepo: pass the request object to hooks

Sune Foldager cryo at cyanite.org
Fri Nov 6 13:31:50 CST 2009


# HG changeset patch
# User Sune Foldager <cryo at cyanite.org>
# Date 1257535374 -3600
# Node ID 08d5b56a38837bcdcca28fdf783d686891f19c48
# Parent  732fc0e9d411e0b94e56779d4ac053ceac0349e4
hgweb/localrepo: pass the request object to hooks

The pretxnchangegroup hook is main place to do authorization based on the
contents of the commit, such as named branches, committer etc. In order to
receive authorization headers you need access to the environment. With CGI
you can always use os.environ, but not so with WSGI.

localrepo gets a property, request, which is normally None, but can be set
to an object which is then passed on to hooks. hgweb sets it when processing
requests.

diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -118,6 +118,7 @@
                             req.drain()
                         raise
                 method = getattr(protocol, cmd)
+                self.repo.request = req
                 return method(self.repo, req)
             except ErrorResponse, inst:
                 req.respond(inst, protocol.HGTYPE)
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -31,6 +31,7 @@
         self.wopener = util.opener(self.root)
         self.baseui = baseui
         self.ui = baseui.copy()
+        self.request = None
 
         try:
             self.ui.readconfig(self.join("hgrc"), self.root)
@@ -142,7 +143,7 @@
         return 'file:' + self.root
 
     def hook(self, name, throw=False, **args):
-        return hook.hook(self.ui, self, name, throw, **args)
+        return hook.hook(self.ui, self, name, throw, request=self.request, **args)
 
     tag_disallowed = ':\r\n'
 


More information about the Mercurial-devel mailing list