changeset 4250:ca639faa38a2

Merge with crew-stable.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Mon, 19 Mar 2007 19:16:35 -0300
parents 7663780b55a7 (current diff) 89075f106414 (diff)
children e76e52145c3d
files mercurial/commands.py mercurial/hgweb/hgweb_mod.py mercurial/hgweb/hgwebdir_mod.py mercurial/hgweb/request.py mercurial/hgweb/server.py
diffstat 5 files changed, 91 insertions(+), 90 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Mon Mar 19 09:36:06 2007 -0700
+++ b/mercurial/commands.py	Mon Mar 19 19:16:35 2007 -0300
@@ -765,7 +765,11 @@
     if not rev2:
         rev2 = hex(nullid)
 
-    repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2))
+    wlock = repo.wlock()
+    try:
+        repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2))
+    finally:
+        wlock.release()
 
 def debugstate(ui, repo):
     """show the contents of the current dirstate"""
--- a/mercurial/hgweb/hgweb_mod.py	Mon Mar 19 09:36:06 2007 -0700
+++ b/mercurial/hgweb/hgweb_mod.py	Mon Mar 19 19:16:35 2007 -0300
@@ -797,19 +797,22 @@
                                                "sessionvars": sessionvars
                                                })
 
-        if not req.form.has_key('cmd'):
-            req.form['cmd'] = [self.t.cache['default']]
+        try:
+            if not req.form.has_key('cmd'):
+                req.form['cmd'] = [self.t.cache['default']]
 
-        cmd = req.form['cmd'][0]
+            cmd = req.form['cmd'][0]
 
-        method = getattr(self, 'do_' + cmd, None)
-        if method:
-            try:
-                method(req)
-            except (hg.RepoError, revlog.RevlogError), inst:
-                req.write(self.t("error", error=str(inst)))
-        else:
-            req.write(self.t("error", error='No such method: ' + cmd))
+            method = getattr(self, 'do_' + cmd, None)
+            if method:
+                try:
+                    method(req)
+                except (hg.RepoError, revlog.RevlogError), inst:
+                    req.write(self.t("error", error=str(inst)))
+            else:
+                req.write(self.t("error", error='No such method: ' + cmd))
+        finally:
+            self.t = None
 
     def changectx(self, req):
         if req.form.has_key('node'):
--- a/mercurial/hgweb/hgwebdir_mod.py	Mon Mar 19 09:36:06 2007 -0700
+++ b/mercurial/hgweb/hgwebdir_mod.py	Mon Mar 19 19:16:35 2007 -0300
@@ -179,53 +179,56 @@
                     parity = 1 - parity
                     yield row
 
-        virtual = req.env.get("PATH_INFO", "").strip('/')
-        if virtual.startswith('static/'):
-            static = os.path.join(templater.templatepath(), 'static')
-            fname = virtual[7:]
-            req.write(staticfile(static, fname, req) or
-                      tmpl('error', error='%r not found' % fname))
-        elif virtual:
-            while virtual:
-                real = dict(self.repos).get(virtual)
+        try:
+            virtual = req.env.get("PATH_INFO", "").strip('/')
+            if virtual.startswith('static/'):
+                static = os.path.join(templater.templatepath(), 'static')
+                fname = virtual[7:]
+                req.write(staticfile(static, fname, req) or
+                          tmpl('error', error='%r not found' % fname))
+            elif virtual:
+                while virtual:
+                    real = dict(self.repos).get(virtual)
+                    if real:
+                        break
+                    up = virtual.rfind('/')
+                    if up < 0:
+                        break
+                    virtual = virtual[:up]
                 if real:
-                    break
-                up = virtual.rfind('/')
-                if up < 0:
-                    break
-                virtual = virtual[:up]
-            if real:
-                req.env['REPO_NAME'] = virtual
-                try:
-                    repo = hg.repository(parentui, real)
-                    hgweb(repo).run_wsgi(req)
-                except IOError, inst:
-                    req.write(tmpl("error", error=inst.strerror))
-                except hg.RepoError, inst:
-                    req.write(tmpl("error", error=str(inst)))
+                    req.env['REPO_NAME'] = virtual
+                    try:
+                        repo = hg.repository(parentui, real)
+                        hgweb(repo).run_wsgi(req)
+                    except IOError, inst:
+                        req.write(tmpl("error", error=inst.strerror))
+                    except hg.RepoError, inst:
+                        req.write(tmpl("error", error=str(inst)))
+                else:
+                    req.write(tmpl("notfound", repo=virtual))
             else:
-                req.write(tmpl("notfound", repo=virtual))
-        else:
-            if req.form.has_key('static'):
-                static = os.path.join(templater.templatepath(), "static")
-                fname = req.form['static'][0]
-                req.write(staticfile(static, fname, req)
-                          or tmpl("error", error="%r not found" % fname))
-            else:
-                sortable = ["name", "description", "contact", "lastchange"]
-                sortcolumn, descending = self.repos_sorted
-                if req.form.has_key('sort'):
-                    sortcolumn = req.form['sort'][0]
-                    descending = sortcolumn.startswith('-')
-                    if descending:
-                        sortcolumn = sortcolumn[1:]
-                    if sortcolumn not in sortable:
-                        sortcolumn = ""
+                if req.form.has_key('static'):
+                    static = os.path.join(templater.templatepath(), "static")
+                    fname = req.form['static'][0]
+                    req.write(staticfile(static, fname, req)
+                              or tmpl("error", error="%r not found" % fname))
+                else:
+                    sortable = ["name", "description", "contact", "lastchange"]
+                    sortcolumn, descending = self.repos_sorted
+                    if req.form.has_key('sort'):
+                        sortcolumn = req.form['sort'][0]
+                        descending = sortcolumn.startswith('-')
+                        if descending:
+                            sortcolumn = sortcolumn[1:]
+                        if sortcolumn not in sortable:
+                            sortcolumn = ""
 
-                sort = [("sort_%s" % column,
-                         "%s%s" % ((not descending and column == sortcolumn)
-                                   and "-" or "", column))
-                        for column in sortable]
-                req.write(tmpl("index", entries=entries,
-                               sortcolumn=sortcolumn, descending=descending,
-                               **dict(sort)))
+                    sort = [("sort_%s" % column,
+                             "%s%s" % ((not descending and column == sortcolumn)
+                                       and "-" or "", column))
+                            for column in sortable]
+                    req.write(tmpl("index", entries=entries,
+                                   sortcolumn=sortcolumn, descending=descending,
+                                   **dict(sort)))
+        finally:
+            tmpl = None
--- a/mercurial/hgweb/request.py	Mon Mar 19 09:36:06 2007 -0700
+++ b/mercurial/hgweb/request.py	Mon Mar 19 19:16:35 2007 -0300
@@ -16,20 +16,6 @@
     def __call__(self, wsgienv, start_response):
         return _wsgirequest(self.destmaker(), wsgienv, start_response)
 
-class _wsgioutputfile(object):
-    def __init__(self, request):
-        self.request = request
-
-    def write(self, data):
-        self.request.write(data)
-    def writelines(self, lines):
-        for line in lines:
-            self.write(line)
-    def flush(self):
-        return None
-    def close(self):
-        return None
-
 class _wsgirequest(object):
     def __init__(self, destination, wsgienv, start_response):
         version = wsgienv['wsgi.version']
@@ -37,7 +23,6 @@
             raise RuntimeError("Unknown and unsupported WSGI version %d.%d" \
                                % version)
         self.inp = wsgienv['wsgi.input']
-        self.out = _wsgioutputfile(self)
         self.server_write = None
         self.err = wsgienv['wsgi.errors']
         self.threaded = wsgienv['wsgi.multithread']
@@ -49,6 +34,8 @@
         self.headers = []
         destination.run_wsgi(self)
 
+    out = property(lambda self: self)
+
     def __iter__(self):
         return iter([])
 
@@ -75,6 +62,16 @@
                     if inst[0] != errno.ECONNRESET:
                         raise
 
+    def writelines(self, lines):
+        for line in lines:
+            self.write(line)
+
+    def flush(self):
+        return None
+
+    def close(self):
+        return None
+
     def header(self, headers=[('Content-type','text/html')]):
         self.headers.extend(headers)
 
--- a/mercurial/hgweb/server.py	Mon Mar 19 09:36:06 2007 -0700
+++ b/mercurial/hgweb/server.py	Mon Mar 19 19:16:35 2007 -0300
@@ -206,12 +206,17 @@
             BaseHTTPServer.HTTPServer.__init__(self, *args, **kargs)
             self.accesslog = accesslog
             self.errorlog = errorlog
-            self.repo = repo
-            self.webdir_conf = webdir_conf
-            self.webdirmaker = hgwebdir
-            self.repoviewmaker = hgweb
-            self.reqmaker = wsgiapplication(self.make_handler)
             self.daemon_threads = True
+            def make_handler():
+                if webdir_conf:
+                    hgwebobj = hgwebdir(webdir_conf, ui)
+                elif repo is not None:
+                    hgwebobj = hgweb(hg.repository(repo.ui, repo.root))
+                else:
+                    raise hg.RepoError(_("There is no Mercurial repository here"
+                                         " (.hg not found)"))
+                return hgwebobj
+            self.reqmaker = wsgiapplication(make_handler)
 
             addr, port = self.socket.getsockname()[:2]
             if addr in ('0.0.0.0', '::'):
@@ -223,17 +228,6 @@
                     pass
             self.addr, self.port = addr, port
 
-        def make_handler(self):
-            if self.webdir_conf:
-                hgwebobj = self.webdirmaker(self.webdir_conf, ui)
-            elif self.repo is not None:
-                hgwebobj = self.repoviewmaker(hg.repository(repo.ui,
-                                                            repo.root))
-            else:
-                raise hg.RepoError(_("There is no Mercurial repository here"
-                                     " (.hg not found)"))
-            return hgwebobj
-
     class IPv6HTTPServer(MercurialHTTPServer):
         address_family = getattr(socket, 'AF_INET6', None)