# HG changeset patch # User Alexis S. L. Carvalho # Date 1174342595 10800 # Node ID ca639faa38a263f4cbcf89a3b6b85a4a9d634114 # Parent 7663780b55a7115885540c8d5c337c5aa6407a62# Parent 89075f10641408fad1249103e5c30e8949039f14 Merge with crew-stable. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -765,7 +765,11 @@ def debugsetparents(ui, repo, rev1, rev2 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""" 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 @@ -797,19 +797,22 @@ class hgweb(object): "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'): diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py --- a/mercurial/hgweb/hgwebdir_mod.py +++ b/mercurial/hgweb/hgwebdir_mod.py @@ -179,53 +179,56 @@ class hgwebdir(object): 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 diff --git a/mercurial/hgweb/request.py b/mercurial/hgweb/request.py --- a/mercurial/hgweb/request.py +++ b/mercurial/hgweb/request.py @@ -16,20 +16,6 @@ class wsgiapplication(object): 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 @@ class _wsgirequest(object): 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 @@ class _wsgirequest(object): self.headers = [] destination.run_wsgi(self) + out = property(lambda self: self) + def __iter__(self): return iter([]) @@ -75,6 +62,16 @@ class _wsgirequest(object): 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) diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py --- a/mercurial/hgweb/server.py +++ b/mercurial/hgweb/server.py @@ -206,12 +206,17 @@ def create_server(ui, repo): 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 @@ def create_server(ui, repo): 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)