mercurial/hgweb/hgwebdir_mod.py
author Mads Kiilerich <mads@kiilerich.com>
Thu, 21 Jun 2012 12:50:15 +0200
changeset 17104 5a9acb0b2086
parent 16754 d94c470c3deb
child 17838 d51364b318ea
permissions -rw-r--r--
help: improve hgweb help The existing help only walked through an example. Now we first explain the basic rules and then show an example. The 'collections' example and description only cause confusion and is removed. Bikeshedded by Patrick Mezard <patrick@mezard.eu>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2391
d351a3be3371 Fixing up comment headers for split up code.
Eric Hopper <hopper@omnifarious.org>
parents: 2360
diff changeset
     1
# hgweb/hgwebdir_mod.py - Web interface for a directory of repositories.
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
     2
#
238
3b92f8fe47ae hgweb.py: kill #! line, clean up copyright notice
mpm@selenic.com
parents: 222
diff changeset
     3
# Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net>
2859
345bac2bc4ec update copyrights.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2538
diff changeset
     4
# Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
     5
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8216
diff changeset
     6
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9903
diff changeset
     7
# GNU General Public License version 2 or any later version.
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
     8
13821
a35aff48d577 hgweb: use url.url when setting CGI environment variables
Brodie Rao <brodie@bitheap.org>
parents: 13796
diff changeset
     9
import os, re, time
7225
59b4ae211584 i18n: import _ instead of gettext
Martin Geisler <mg@daimi.au.dk>
parents: 7107
diff changeset
    10
from mercurial.i18n import _
13975
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13964
diff changeset
    11
from mercurial import ui, hg, scmutil, util, templater
14076
924c82157d46 url: move URL parsing functions into util to improve startup time
Brodie Rao <brodie@bitheap.org>
parents: 13975
diff changeset
    12
from mercurial import error, encoding
10394
4612cded5176 fix coding style (reported by pylint)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10282
diff changeset
    13
from common import ErrorResponse, get_mtime, staticfile, paritygen, \
5993
948a41e77902 hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5976
diff changeset
    14
                   get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
3877
abaee83ce0a6 Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents: 3557
diff changeset
    15
from hgweb_mod import hgweb
5566
d74fc8dec2b4 Less indirection in the WSGI web interface. This simplifies some code, and makes it more compliant with WSGI.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5561
diff changeset
    16
from request import wsgirequest
8216
25266fe996b0 hgweb: use new sessionvars code in hgwebdir, too
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8215
diff changeset
    17
import webutil
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    18
8215
227707c90548 hgweb: some cleanups in hgwebdir, remove double defaults
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8209
diff changeset
    19
def cleannames(items):
227707c90548 hgweb: some cleanups in hgwebdir, remove double defaults
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8209
diff changeset
    20
    return [(util.pconvert(name).strip('/'), path) for name, path in items]
1181
4f5001f5b4c3 Make sure the repository names don't have slashes at the at or else in some
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents: 1180
diff changeset
    21
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents: 8389
diff changeset
    22
def findrepos(paths):
9723
a235644a0b93 hgweb: use a tuple-list instead of dictionary for append-only store
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9363
diff changeset
    23
    repos = []
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents: 8389
diff changeset
    24
    for prefix, root in cleannames(paths):
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents: 8389
diff changeset
    25
        roothead, roottail = os.path.split(root)
17104
5a9acb0b2086 help: improve hgweb help
Mads Kiilerich <mads@kiilerich.com>
parents: 16754
diff changeset
    26
        # "foo = /bar/*" or "foo = /bar/**" lets every repo /bar/N in or below
5a9acb0b2086 help: improve hgweb help
Mads Kiilerich <mads@kiilerich.com>
parents: 16754
diff changeset
    27
        # /bar/ be served as as foo/N .
5a9acb0b2086 help: improve hgweb help
Mads Kiilerich <mads@kiilerich.com>
parents: 16754
diff changeset
    28
        # '*' will not search inside dirs with .hg (except .hg/patches),
5a9acb0b2086 help: improve hgweb help
Mads Kiilerich <mads@kiilerich.com>
parents: 16754
diff changeset
    29
        # '**' will search inside dirs with .hg (and thus also find subrepos).
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents: 8389
diff changeset
    30
        try:
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents: 8389
diff changeset
    31
            recurse = {'*': False, '**': True}[roottail]
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents: 8389
diff changeset
    32
        except KeyError:
9723
a235644a0b93 hgweb: use a tuple-list instead of dictionary for append-only store
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9363
diff changeset
    33
            repos.append((prefix, root))
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents: 8389
diff changeset
    34
            continue
11677
8f8a7976f4bc hgwebdir: allow pure relative globs in paths
Mads Kiilerich <mads@kiilerich.com>
parents: 11649
diff changeset
    35
        roothead = os.path.normpath(os.path.abspath(roothead))
13975
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13964
diff changeset
    36
        paths = scmutil.walkrepos(roothead, followsym=True, recurse=recurse)
13402
f947d9a4c45c hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents: 13214
diff changeset
    37
        repos.extend(urlrepos(prefix, roothead, paths))
9723
a235644a0b93 hgweb: use a tuple-list instead of dictionary for append-only store
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9363
diff changeset
    38
    return repos
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents: 8389
diff changeset
    39
13402
f947d9a4c45c hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents: 13214
diff changeset
    40
def urlrepos(prefix, roothead, paths):
f947d9a4c45c hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents: 13214
diff changeset
    41
    """yield url paths and filesystem paths from a list of repo paths
f947d9a4c45c hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents: 13214
diff changeset
    42
13538
d24e97fd52a9 test-doctest: handle unix/windows path discrepancies
Patrick Mezard <pmezard@gmail.com>
parents: 13436
diff changeset
    43
    >>> conv = lambda seq: [(v, util.pconvert(p)) for v,p in seq]
d24e97fd52a9 test-doctest: handle unix/windows path discrepancies
Patrick Mezard <pmezard@gmail.com>
parents: 13436
diff changeset
    44
    >>> conv(urlrepos('hg', '/opt', ['/opt/r', '/opt/r/r', '/opt']))
13403
8ed91088acbb hgweb: make paths wildcards expanding in a repo root match repo correctly
Mads Kiilerich <mads@kiilerich.com>
parents: 13402
diff changeset
    45
    [('hg/r', '/opt/r'), ('hg/r/r', '/opt/r/r'), ('hg', '/opt')]
13538
d24e97fd52a9 test-doctest: handle unix/windows path discrepancies
Patrick Mezard <pmezard@gmail.com>
parents: 13436
diff changeset
    46
    >>> conv(urlrepos('', '/opt', ['/opt/r', '/opt/r/r', '/opt']))
13402
f947d9a4c45c hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents: 13214
diff changeset
    47
    [('r', '/opt/r'), ('r/r', '/opt/r/r'), ('', '/opt')]
f947d9a4c45c hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents: 13214
diff changeset
    48
    """
f947d9a4c45c hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents: 13214
diff changeset
    49
    for path in paths:
f947d9a4c45c hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents: 13214
diff changeset
    50
        path = os.path.normpath(path)
13403
8ed91088acbb hgweb: make paths wildcards expanding in a repo root match repo correctly
Mads Kiilerich <mads@kiilerich.com>
parents: 13402
diff changeset
    51
        yield (prefix + '/' +
8ed91088acbb hgweb: make paths wildcards expanding in a repo root match repo correctly
Mads Kiilerich <mads@kiilerich.com>
parents: 13402
diff changeset
    52
               util.pconvert(path[len(roothead):]).lstrip('/')).strip('/'), path
13402
f947d9a4c45c hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents: 13214
diff changeset
    53
15003
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    54
def geturlcgivars(baseurl, port):
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    55
    """
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    56
    Extract CGI variables from baseurl
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    57
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    58
    >>> geturlcgivars("http://host.org/base", "80")
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    59
    ('host.org', '80', '/base')
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    60
    >>> geturlcgivars("http://host.org:8000/base", "80")
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    61
    ('host.org', '8000', '/base')
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    62
    >>> geturlcgivars('/base', 8000)
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    63
    ('', '8000', '/base')
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    64
    >>> geturlcgivars("base", '8000')
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    65
    ('', '8000', '/base')
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    66
    >>> geturlcgivars("http://host", '8000')
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    67
    ('host', '8000', '/')
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    68
    >>> geturlcgivars("http://host/", '8000')
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    69
    ('host', '8000', '/')
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    70
    """
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    71
    u = util.url(baseurl)
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    72
    name = u.host or ''
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    73
    if u.port:
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    74
        port = u.port
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    75
    path = u.path or ""
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    76
    if not path.startswith('/'):
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    77
        path = '/' + path
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    78
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    79
    return name, str(port), path
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
    80
1559
59b3639df0a9 Convert all classes to new-style classes by deriving them from object.
Eric Hopper <hopper@omnifarious.org>
parents: 1554
diff changeset
    81
class hgwebdir(object):
8371
1bd0fdf4c1ec hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 8360
diff changeset
    82
    refreshinterval = 20
8215
227707c90548 hgweb: some cleanups in hgwebdir, remove double defaults
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8209
diff changeset
    83
8191
35604226d712 hgweb: kill parentui references
Matt Mackall <mpm@selenic.com>
parents: 8190
diff changeset
    84
    def __init__(self, conf, baseui=None):
8371
1bd0fdf4c1ec hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 8360
diff changeset
    85
        self.conf = conf
1bd0fdf4c1ec hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 8360
diff changeset
    86
        self.baseui = baseui
1bd0fdf4c1ec hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 8360
diff changeset
    87
        self.lastrefresh = 0
9903
5d748045c2ae Do not overwrite motd attribute of hgwebdir instances on refresh.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 9842
diff changeset
    88
        self.motd = None
8371
1bd0fdf4c1ec hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 8360
diff changeset
    89
        self.refresh()
1181
4f5001f5b4c3 Make sure the repository names don't have slashes at the at or else in some
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents: 1180
diff changeset
    90
8371
1bd0fdf4c1ec hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 8360
diff changeset
    91
    def refresh(self):
1bd0fdf4c1ec hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 8360
diff changeset
    92
        if self.lastrefresh + self.refreshinterval > time.time():
1bd0fdf4c1ec hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 8360
diff changeset
    93
            return
1bd0fdf4c1ec hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 8360
diff changeset
    94
1bd0fdf4c1ec hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 8360
diff changeset
    95
        if self.baseui:
11239
99bc18d1ab0f hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents: 10675
diff changeset
    96
            u = self.baseui.copy()
1143
4fffb3d84b7c Allow list of (virtual, real) or dictionary to be passed to hgwebdir.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1142
diff changeset
    97
        else:
12696
ef969e58a394 hgweb: another fix for the help termwidth bug
Matt Mackall <mpm@selenic.com>
parents: 12691
diff changeset
    98
            u = ui.ui()
11239
99bc18d1ab0f hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents: 10675
diff changeset
    99
            u.setconfig('ui', 'report_untrusted', 'off')
16754
d94c470c3deb hgweb: use ui.nontty to disable all cooked I/O
Matt Mackall <mpm@selenic.com>
parents: 16239
diff changeset
   100
            u.setconfig('ui', 'nontty', 'true')
8136
6b5522cb2ad2 ui: refactor option setting
Matt Mackall <mpm@selenic.com>
parents: 7966
diff changeset
   101
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents: 8389
diff changeset
   102
        if not isinstance(self.conf, (dict, list, tuple)):
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents: 8389
diff changeset
   103
            map = {'paths': 'hgweb-paths'}
13214
5bcb6c9d16db hgweb: abort if config file isn't found
Matt Mackall <mpm@selenic.com>
parents: 13066
diff changeset
   104
            if not os.path.exists(self.conf):
5bcb6c9d16db hgweb: abort if config file isn't found
Matt Mackall <mpm@selenic.com>
parents: 13066
diff changeset
   105
                raise util.Abort(_('config file %s not found!') % self.conf)
11239
99bc18d1ab0f hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents: 10675
diff changeset
   106
            u.readconfig(self.conf, remap=map, trust=True)
13667
8cbb59124e67 hgweb: support multiple directories for the same path
timeless <timeless@gmail.com>
parents: 13538
diff changeset
   107
            paths = []
8cbb59124e67 hgweb: support multiple directories for the same path
timeless <timeless@gmail.com>
parents: 13538
diff changeset
   108
            for name, ignored in u.configitems('hgweb-paths'):
8cbb59124e67 hgweb: support multiple directories for the same path
timeless <timeless@gmail.com>
parents: 13538
diff changeset
   109
                for path in u.configlist('hgweb-paths', name):
8cbb59124e67 hgweb: support multiple directories for the same path
timeless <timeless@gmail.com>
parents: 13538
diff changeset
   110
                    paths.append((name, path))
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents: 8389
diff changeset
   111
        elif isinstance(self.conf, (list, tuple)):
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents: 8389
diff changeset
   112
            paths = self.conf
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents: 8389
diff changeset
   113
        elif isinstance(self.conf, dict):
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents: 8389
diff changeset
   114
            paths = self.conf.items()
8345
dcebff8a25dd hgwebdir: read --webdir-conf as actual configuration to ui (issue1586)
Alexander Solovyov <piranha@piranha.org.ua>
parents: 8225
diff changeset
   115
11239
99bc18d1ab0f hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents: 10675
diff changeset
   116
        repos = findrepos(paths)
99bc18d1ab0f hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents: 10675
diff changeset
   117
        for prefix, root in u.configitems('collections'):
99bc18d1ab0f hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents: 10675
diff changeset
   118
            prefix = util.pconvert(prefix)
13975
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13964
diff changeset
   119
            for path in scmutil.walkrepos(root, followsym=True):
11239
99bc18d1ab0f hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents: 10675
diff changeset
   120
                repo = os.path.normpath(path)
99bc18d1ab0f hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents: 10675
diff changeset
   121
                name = util.pconvert(repo)
99bc18d1ab0f hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents: 10675
diff changeset
   122
                if name.startswith(prefix):
99bc18d1ab0f hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents: 10675
diff changeset
   123
                    name = name[len(prefix):]
99bc18d1ab0f hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents: 10675
diff changeset
   124
                repos.append((name.lstrip('/'), repo))
99bc18d1ab0f hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents: 10675
diff changeset
   125
99bc18d1ab0f hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents: 10675
diff changeset
   126
        self.repos = repos
99bc18d1ab0f hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents: 10675
diff changeset
   127
        self.ui = u
8859
580a79dde2a3 hgweb: web.encoding should override encoding.encoding (issue1183)
Matt Mackall <mpm@selenic.com>
parents: 8663
diff changeset
   128
        encoding.encoding = self.ui.config('web', 'encoding',
580a79dde2a3 hgweb: web.encoding should override encoding.encoding (issue1183)
Matt Mackall <mpm@selenic.com>
parents: 8663
diff changeset
   129
                                           encoding.encoding)
8621
13613221caf1 hgweb: extract config values after reading webdir-config
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8537
diff changeset
   130
        self.style = self.ui.config('web', 'style', 'paper')
11649
48163c39e1f1 hgwebdir: use template paths configured in the hgrc (issue2281)
Christian Fischer <christian@fi12.de>
parents: 11241
diff changeset
   131
        self.templatepath = self.ui.config('web', 'templates', None)
8621
13613221caf1 hgweb: extract config values after reading webdir-config
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8537
diff changeset
   132
        self.stripecount = self.ui.config('web', 'stripes', 1)
13613221caf1 hgweb: extract config values after reading webdir-config
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8537
diff changeset
   133
        if self.stripecount:
13613221caf1 hgweb: extract config values after reading webdir-config
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8537
diff changeset
   134
            self.stripecount = int(self.stripecount)
13613221caf1 hgweb: extract config values after reading webdir-config
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8537
diff changeset
   135
        self._baseurl = self.ui.config('web', 'baseurl')
8371
1bd0fdf4c1ec hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 8360
diff changeset
   136
        self.lastrefresh = time.time()
941
4cf418c2a013 Add a multi-repository server
mpm@selenic.com
parents: 939
diff changeset
   137
2535
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
   138
    def run(self):
2538
f4b7d71c1c60 Cleanup hgweb and hgwebdir's run method a bit.
Eric Hopper <hopper@omnifarious.org>
parents: 2537
diff changeset
   139
        if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."):
8663
45f626a39def wrap string literals in error messages
Martin Geisler <mg@lazybytes.net>
parents: 8621
diff changeset
   140
            raise RuntimeError("This function is only intended to be "
45f626a39def wrap string literals in error messages
Martin Geisler <mg@lazybytes.net>
parents: 8621
diff changeset
   141
                               "called while running as a CGI script.")
2535
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
   142
        import mercurial.hgweb.wsgicgi as wsgicgi
5566
d74fc8dec2b4 Less indirection in the WSGI web interface. This simplifies some code, and makes it more compliant with WSGI.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5561
diff changeset
   143
        wsgicgi.launch(self)
d74fc8dec2b4 Less indirection in the WSGI web interface. This simplifies some code, and makes it more compliant with WSGI.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5561
diff changeset
   144
d74fc8dec2b4 Less indirection in the WSGI web interface. This simplifies some code, and makes it more compliant with WSGI.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5561
diff changeset
   145
    def __call__(self, env, respond):
d74fc8dec2b4 Less indirection in the WSGI web interface. This simplifies some code, and makes it more compliant with WSGI.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5561
diff changeset
   146
        req = wsgirequest(env, respond)
6797
8909070fd05e merge another backout
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6796
diff changeset
   147
        return self.run_wsgi(req)
2535
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
   148
7336
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   149
    def read_allowed(self, ui, req):
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   150
        """Check allow_read and deny_read config options of a repo's ui object
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   151
        to determine user permissions.  By default, with neither option set (or
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   152
        both empty), allow all users to read the repo.  There are two ways a
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   153
        user can be denied read access:  (1) deny_read is not empty, and the
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   154
        user is unauthenticated or deny_read contains user (or *), and (2)
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   155
        allow_read is not empty and the user is not in allow_read.  Return True
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   156
        if user is allowed to read the repo, else return False."""
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   157
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   158
        user = req.env.get('REMOTE_USER')
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   159
7575
3ccaefc84f45 hgweb: fix long line lengths introduced in 2dc868712dcc
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7560
diff changeset
   160
        deny_read = ui.configlist('web', 'deny_read', untrusted=True)
7336
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   161
        if deny_read and (not user or deny_read == ['*'] or user in deny_read):
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   162
            return False
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   163
7575
3ccaefc84f45 hgweb: fix long line lengths introduced in 2dc868712dcc
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7560
diff changeset
   164
        allow_read = ui.configlist('web', 'allow_read', untrusted=True)
7336
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   165
        # by default, allow reading if no allow_read option has been set
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   166
        if (not allow_read) or (allow_read == ['*']) or (user in allow_read):
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   167
            return True
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   168
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   169
        return False
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   170
2535
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
   171
    def run_wsgi(self, req):
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   172
        try:
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   173
            try:
8371
1bd0fdf4c1ec hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 8360
diff changeset
   174
                self.refresh()
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   175
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   176
                virtual = req.env.get("PATH_INFO", "").strip('/')
5993
948a41e77902 hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5976
diff changeset
   177
                tmpl = self.templater(req)
7948
de377b1a9a84 move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents: 7740
diff changeset
   178
                ctype = tmpl('mimetype', encoding=encoding.encoding)
6391
a1007f7b9b7b Backed out changeset d2bb66a8a435 (temporary template compatibility)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6379
diff changeset
   179
                ctype = templater.stringify(ctype)
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5603
diff changeset
   180
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   181
                # a static file
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   182
                if virtual.startswith('static/') or 'static' in req.form:
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   183
                    if virtual.startswith('static/'):
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   184
                        fname = virtual[7:]
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   185
                    else:
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   186
                        fname = req.form['static'][0]
7107
125c8fedcbe0 Allow hgweb to search for templates in more than one path.
Brendan Cully <brendan@kublai.com>
parents: 6945
diff changeset
   187
                    static = templater.templatepath('static')
7560
305efd897a63 hgwebdir_mod: fix a performance issue with static files
Patrick Mezard <pmezard@gmail.com>
parents: 7523
diff changeset
   188
                    return (staticfile(static, fname, req),)
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   189
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   190
                # top-level index
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   191
                elif not virtual:
5993
948a41e77902 hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5976
diff changeset
   192
                    req.respond(HTTP_OK, ctype)
7396
526c40a74bd0 templater: return data in increasing chunk sizes
Brendan Cully <brendan@kublai.com>
parents: 7337
diff changeset
   193
                    return self.makeindex(req, tmpl)
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   194
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   195
                # nested indexes and hgwebs
6210
942287cb1f57 Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6046
diff changeset
   196
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   197
                repos = dict(self.repos)
13066
86888ae9ce90 hgwebdir: fix incorrect index generation for invalid paths (issue2023)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 12696
diff changeset
   198
                virtualrepo = virtual
86888ae9ce90 hgwebdir: fix incorrect index generation for invalid paths (issue2023)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 12696
diff changeset
   199
                while virtualrepo:
86888ae9ce90 hgwebdir: fix incorrect index generation for invalid paths (issue2023)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 12696
diff changeset
   200
                    real = repos.get(virtualrepo)
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   201
                    if real:
13066
86888ae9ce90 hgwebdir: fix incorrect index generation for invalid paths (issue2023)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 12696
diff changeset
   202
                        req.env['REPO_NAME'] = virtualrepo
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   203
                        try:
8191
35604226d712 hgweb: kill parentui references
Matt Mackall <mpm@selenic.com>
parents: 8190
diff changeset
   204
                            repo = hg.repository(self.ui, real)
6797
8909070fd05e merge another backout
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6796
diff changeset
   205
                            return hgweb(repo).run_wsgi(req)
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   206
                        except IOError, inst:
5993
948a41e77902 hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5976
diff changeset
   207
                            msg = inst.strerror
948a41e77902 hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5976
diff changeset
   208
                            raise ErrorResponse(HTTP_SERVER_ERROR, msg)
7637
1d54e2f6c0b7 error: move repo errors
Matt Mackall <mpm@selenic.com>
parents: 7575
diff changeset
   209
                        except error.RepoError, inst:
5993
948a41e77902 hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5976
diff changeset
   210
                            raise ErrorResponse(HTTP_SERVER_ERROR, str(inst))
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   211
13066
86888ae9ce90 hgwebdir: fix incorrect index generation for invalid paths (issue2023)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 12696
diff changeset
   212
                    up = virtualrepo.rfind('/')
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   213
                    if up < 0:
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   214
                        break
13066
86888ae9ce90 hgwebdir: fix incorrect index generation for invalid paths (issue2023)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 12696
diff changeset
   215
                    virtualrepo = virtualrepo[:up]
86888ae9ce90 hgwebdir: fix incorrect index generation for invalid paths (issue2023)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 12696
diff changeset
   216
86888ae9ce90 hgwebdir: fix incorrect index generation for invalid paths (issue2023)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 12696
diff changeset
   217
                # browse subdirectories
86888ae9ce90 hgwebdir: fix incorrect index generation for invalid paths (issue2023)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 12696
diff changeset
   218
                subdir = virtual + '/'
86888ae9ce90 hgwebdir: fix incorrect index generation for invalid paths (issue2023)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 12696
diff changeset
   219
                if [r for r in repos if r.startswith(subdir)]:
86888ae9ce90 hgwebdir: fix incorrect index generation for invalid paths (issue2023)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 12696
diff changeset
   220
                    req.respond(HTTP_OK, ctype)
86888ae9ce90 hgwebdir: fix incorrect index generation for invalid paths (issue2023)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 12696
diff changeset
   221
                    return self.makeindex(req, tmpl, subdir)
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   222
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   223
                # prefixes not found
5993
948a41e77902 hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5976
diff changeset
   224
                req.respond(HTTP_NOT_FOUND, ctype)
7396
526c40a74bd0 templater: return data in increasing chunk sizes
Brendan Cully <brendan@kublai.com>
parents: 7337
diff changeset
   225
                return tmpl("notfound", repo=virtual)
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5603
diff changeset
   226
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   227
            except ErrorResponse, err:
7740
176d3d681702 hgweb: pass ErrorResponses directly into req.respond()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7637
diff changeset
   228
                req.respond(err, ctype)
7396
526c40a74bd0 templater: return data in increasing chunk sizes
Brendan Cully <brendan@kublai.com>
parents: 7337
diff changeset
   229
                return tmpl('error', error=err.message or '')
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   230
        finally:
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   231
            tmpl = None
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   232
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   233
    def makeindex(self, req, tmpl, subdir=""):
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   234
2171
290534ee163c Add download links to hgwebdir index page for allowed archive types.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2170
diff changeset
   235
        def archivelist(ui, nodeid, url):
3556
c3043ebe40a0 use untrusted settings in hgwebdir
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3488
diff changeset
   236
            allowed = ui.configlist("web", "allow_archive", untrusted=True)
13436
b391c0c9be61 hgwebdir: reduce memory usage for index generation
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 13403
diff changeset
   237
            archives = []
3262
1e322b44b366 Teach hgwebdir about new interface
Brendan Cully <brendan@kublai.com>
parents: 3223
diff changeset
   238
            for i in [('zip', '.zip'), ('gz', '.tar.gz'), ('bz2', '.tar.bz2')]:
3556
c3043ebe40a0 use untrusted settings in hgwebdir
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3488
diff changeset
   239
                if i[0] in allowed or ui.configbool("web", "allow" + i[0],
c3043ebe40a0 use untrusted settings in hgwebdir
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3488
diff changeset
   240
                                                    untrusted=True):
13436
b391c0c9be61 hgwebdir: reduce memory usage for index generation
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 13403
diff changeset
   241
                    archives.append({"type" : i[0], "extension": i[1],
b391c0c9be61 hgwebdir: reduce memory usage for index generation
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 13403
diff changeset
   242
                                     "node": nodeid, "url": url})
b391c0c9be61 hgwebdir: reduce memory usage for index generation
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 13403
diff changeset
   243
            return archives
2171
290534ee163c Add download links to hgwebdir index page for allowed archive types.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2170
diff changeset
   244
10600
033d2fdc3b9d hgweb: separate generation of entries and sorting (cleanup)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10394
diff changeset
   245
        def rawentries(subdir="", **map):
9363
8635b33eaade hgweb: add web.descend configuration variable
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9184
diff changeset
   246
8635b33eaade hgweb: add web.descend configuration variable
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9184
diff changeset
   247
            descend = self.ui.configbool('web', 'descend', True)
16239
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   248
            collapse = self.ui.configbool('web', 'collapse', False)
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   249
            seenrepos = set()
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   250
            seendirs = set()
1141
033c968d7c66 Use ConfigParser only in hgwebdir.__init__()
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1140
diff changeset
   251
            for name, path in self.repos:
9363
8635b33eaade hgweb: add web.descend configuration variable
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9184
diff changeset
   252
4841
9b0ebb5e0f94 hgweb: let hgwebdir browse subdirectories
Brendan Cully <brendan@kublai.com>
parents: 4709
diff changeset
   253
                if not name.startswith(subdir):
9b0ebb5e0f94 hgweb: let hgwebdir browse subdirectories
Brendan Cully <brendan@kublai.com>
parents: 4709
diff changeset
   254
                    continue
4843
496ac05c6a31 hgwebdir: show only trailing part of path when browsing subdirectories
Brendan Cully <brendan@kublai.com>
parents: 4841
diff changeset
   255
                name = name[len(subdir):]
16239
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   256
                directory = False
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   257
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   258
                if '/' in name:
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   259
                    if not descend:
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   260
                        continue
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   261
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   262
                    nameparts = name.split('/')
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   263
                    rootname = nameparts[0]
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   264
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   265
                    if not collapse:
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   266
                        pass
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   267
                    elif rootname in seendirs:
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   268
                        continue
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   269
                    elif rootname in seenrepos:
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   270
                        pass
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   271
                    else:
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   272
                        directory = True
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   273
                        name = rootname
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   274
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   275
                        # redefine the path to refer to the directory
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   276
                        discarded = '/'.join(nameparts[1:])
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   277
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   278
                        # remove name parts plus accompanying slash
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   279
                        path = path[:-len(discarded) - 1]
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   280
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   281
                parts = [name]
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   282
                if 'PATH_INFO' in req.env:
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   283
                    parts.insert(0, req.env['PATH_INFO'].rstrip('/'))
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   284
                if req.env['SCRIPT_NAME']:
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   285
                    parts.insert(0, req.env['SCRIPT_NAME'])
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   286
                url = re.sub(r'/+', '/', '/'.join(parts) + '/')
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   287
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   288
                # show either a directory entry or a repository
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   289
                if directory:
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   290
                    # get the directory's time information
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   291
                    try:
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   292
                        d = (get_mtime(path), util.makedate()[1])
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   293
                    except OSError:
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   294
                        continue
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   295
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   296
                    row = dict(contact="",
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   297
                               contact_sort="",
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   298
                               name=name,
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   299
                               name_sort=name,
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   300
                               url=url,
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   301
                               description="",
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   302
                               description_sort="",
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   303
                               lastchange=d,
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   304
                               lastchange_sort=d[1]-d[0],
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   305
                               archives=[])
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   306
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   307
                    seendirs.add(name)
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   308
                    yield row
9363
8635b33eaade hgweb: add web.descend configuration variable
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9184
diff changeset
   309
                    continue
4841
9b0ebb5e0f94 hgweb: let hgwebdir browse subdirectories
Brendan Cully <brendan@kublai.com>
parents: 4709
diff changeset
   310
8191
35604226d712 hgweb: kill parentui references
Matt Mackall <mpm@selenic.com>
parents: 8190
diff changeset
   311
                u = self.ui.copy()
1170
85555540a4e2 Make .hg/hgrc optional for repositories published by hgwebdir.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1165
diff changeset
   312
                try:
1473
7d66ce9895fa make readconfig take a filename instead of a file pointer as argument
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1445
diff changeset
   313
                    u.readconfig(os.path.join(path, '.hg', 'hgrc'))
5332
b0bfe087ad8a hgwebdir: ignore hgrc parse errors while building the index page
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5289
diff changeset
   314
                except Exception, e:
6913
580d5e6bfc1f move % out of translatable strings
Martin Geisler <mg@daimi.au.dk>
parents: 6908
diff changeset
   315
                    u.warn(_('error reading %s/.hg/hgrc: %s\n') % (path, e))
5332
b0bfe087ad8a hgwebdir: ignore hgrc parse errors while building the index page
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5289
diff changeset
   316
                    continue
3556
c3043ebe40a0 use untrusted settings in hgwebdir
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3488
diff changeset
   317
                def get(section, name, default=None):
c3043ebe40a0 use untrusted settings in hgwebdir
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3488
diff changeset
   318
                    return u.config(section, name, default, untrusted=True)
941
4cf418c2a013 Add a multi-repository server
mpm@selenic.com
parents: 939
diff changeset
   319
4709
53eca35c3aeb Add option "hidden" to hgwebdir.
Markus F.X.J. Oberhumer <markus@oberhumer.com>
parents: 4462
diff changeset
   320
                if u.configbool("web", "hidden", untrusted=True):
53eca35c3aeb Add option "hidden" to hgwebdir.
Markus F.X.J. Oberhumer <markus@oberhumer.com>
parents: 4462
diff changeset
   321
                    continue
53eca35c3aeb Add option "hidden" to hgwebdir.
Markus F.X.J. Oberhumer <markus@oberhumer.com>
parents: 4462
diff changeset
   322
7336
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   323
                if not self.read_allowed(u, req):
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   324
                    continue
2dc868712dcc hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents: 7225
diff changeset
   325
1348
b8c82bf3da21 hgwebdir: Fix date display
mpm@selenic.com
parents: 1333
diff changeset
   326
                # update time with local timezone
1524
0d47bb884330 hgweb: fix traceback by skipping invalid repo paths
TK Soh <teekaysoh@yahoo.com>
parents: 1511
diff changeset
   327
                try:
10078
97c75ad3b1a0 hgweb: Make get_mtime use repository to find store path.
Brendan Cully <brendan@kublai.com>
parents: 9903
diff changeset
   328
                    r = hg.repository(self.ui, path)
13796
6337149fc07c hgwebdir: handle IOErrors from localrepo while enumerating
timeless@gmail.com
parents: 13667
diff changeset
   329
                except IOError:
6337149fc07c hgwebdir: handle IOErrors from localrepo while enumerating
timeless@gmail.com
parents: 13667
diff changeset
   330
                    u.warn(_('error accessing repository at %s\n') % path)
6337149fc07c hgwebdir: handle IOErrors from localrepo while enumerating
timeless@gmail.com
parents: 13667
diff changeset
   331
                    continue
12038
9617803b1acb hgweb: handle exception of misconfigured path on index page
Yuya Nishihara <yuya@tcha.org>
parents: 11677
diff changeset
   332
                except error.RepoError:
9617803b1acb hgweb: handle exception of misconfigured path on index page
Yuya Nishihara <yuya@tcha.org>
parents: 11677
diff changeset
   333
                    u.warn(_('error accessing repository at %s\n') % path)
9617803b1acb hgweb: handle exception of misconfigured path on index page
Yuya Nishihara <yuya@tcha.org>
parents: 11677
diff changeset
   334
                    continue
9617803b1acb hgweb: handle exception of misconfigured path on index page
Yuya Nishihara <yuya@tcha.org>
parents: 11677
diff changeset
   335
                try:
10078
97c75ad3b1a0 hgweb: Make get_mtime use repository to find store path.
Brendan Cully <brendan@kublai.com>
parents: 9903
diff changeset
   336
                    d = (get_mtime(r.spath), util.makedate()[1])
1524
0d47bb884330 hgweb: fix traceback by skipping invalid repo paths
TK Soh <teekaysoh@yahoo.com>
parents: 1511
diff changeset
   337
                except OSError:
0d47bb884330 hgweb: fix traceback by skipping invalid repo paths
TK Soh <teekaysoh@yahoo.com>
parents: 1511
diff changeset
   338
                    continue
1348
b8c82bf3da21 hgwebdir: Fix date display
mpm@selenic.com
parents: 1333
diff changeset
   339
5779
e9f68860d5ed Don't let ui.username override web.contact (issue900)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5760
diff changeset
   340
                contact = get_contact(get)
2173
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   341
                description = get("web", "description", "")
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   342
                name = get("web", "name", name)
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   343
                row = dict(contact=contact or "unknown",
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   344
                           contact_sort=contact.upper() or "unknown",
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   345
                           name=name,
2174
3044a3fdae76 If default sorting is name, offer name-descending with one click.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2173
diff changeset
   346
                           name_sort=name,
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   347
                           url=url,
2173
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   348
                           description=description or "unknown",
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   349
                           description_sort=description.upper() or "unknown",
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   350
                           lastchange=d,
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   351
                           lastchange_sort=d[1]-d[0],
2171
290534ee163c Add download links to hgwebdir index page for allowed archive types.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2170
diff changeset
   352
                           archives=archivelist(u, "tip", url))
16239
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   353
287f76b3f502 hgweb: support multi-level repository indexes by enabling descend and collapse
Paul Boddie <paul@boddie.org.uk>
parents: 15003
diff changeset
   354
                seenrepos.add(name)
10600
033d2fdc3b9d hgweb: separate generation of entries and sorting (cleanup)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10394
diff changeset
   355
                yield row
033d2fdc3b9d hgweb: separate generation of entries and sorting (cleanup)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10394
diff changeset
   356
033d2fdc3b9d hgweb: separate generation of entries and sorting (cleanup)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10394
diff changeset
   357
        sortdefault = None, False
033d2fdc3b9d hgweb: separate generation of entries and sorting (cleanup)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10394
diff changeset
   358
        def entries(sortcolumn="", descending=False, subdir="", **map):
033d2fdc3b9d hgweb: separate generation of entries and sorting (cleanup)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10394
diff changeset
   359
            rows = rawentries(subdir=subdir, **map)
033d2fdc3b9d hgweb: separate generation of entries and sorting (cleanup)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10394
diff changeset
   360
033d2fdc3b9d hgweb: separate generation of entries and sorting (cleanup)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10394
diff changeset
   361
            if sortcolumn and sortdefault != (sortcolumn, descending):
033d2fdc3b9d hgweb: separate generation of entries and sorting (cleanup)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10394
diff changeset
   362
                sortkey = '%s_sort' % sortcolumn
033d2fdc3b9d hgweb: separate generation of entries and sorting (cleanup)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10394
diff changeset
   363
                rows = sorted(rows, key=lambda x: x[sortkey],
033d2fdc3b9d hgweb: separate generation of entries and sorting (cleanup)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10394
diff changeset
   364
                              reverse=descending)
033d2fdc3b9d hgweb: separate generation of entries and sorting (cleanup)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10394
diff changeset
   365
            for row, parity in zip(rows, paritygen(self.stripecount)):
033d2fdc3b9d hgweb: separate generation of entries and sorting (cleanup)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10394
diff changeset
   366
                row['parity'] = parity
033d2fdc3b9d hgweb: separate generation of entries and sorting (cleanup)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10394
diff changeset
   367
                yield row
941
4cf418c2a013 Add a multi-repository server
mpm@selenic.com
parents: 939
diff changeset
   368
8371
1bd0fdf4c1ec hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 8360
diff changeset
   369
        self.refresh()
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   370
        sortable = ["name", "description", "contact", "lastchange"]
8346
b579823cc546 hgweb: get rid of inaccurate hgwebdir.repos_sorted, localize machinery
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8345
diff changeset
   371
        sortcolumn, descending = sortdefault
5915
d0576d065993 Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents: 5779
diff changeset
   372
        if 'sort' in req.form:
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   373
            sortcolumn = req.form['sort'][0]
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   374
            descending = sortcolumn.startswith('-')
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   375
            if descending:
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   376
                sortcolumn = sortcolumn[1:]
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   377
            if sortcolumn not in sortable:
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   378
                sortcolumn = ""
4841
9b0ebb5e0f94 hgweb: let hgwebdir browse subdirectories
Brendan Cully <brendan@kublai.com>
parents: 4709
diff changeset
   379
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   380
        sort = [("sort_%s" % column,
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   381
                 "%s%s" % ((not descending and column == sortcolumn)
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   382
                            and "-" or "", column))
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   383
                for column in sortable]
5928
3340aa5a64f7 hgweb: move HTTP content types out of header templates
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5915
diff changeset
   384
8371
1bd0fdf4c1ec hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 8360
diff changeset
   385
        self.refresh()
10673
9848b39a1472 hgweb: introduce helper method to update req.env
Yuya Nishihara <yuya@tcha.org>
parents: 10394
diff changeset
   386
        self.updatereqenv(req.env)
6221
2eb18c780287 Support web.baseurl in hgwebdir, overriding SCRIPT_NAME
Brendan Cully <brendan@kublai.com>
parents: 6217
diff changeset
   387
5965
abe373e16fe6 hgweb: forgot to centralize the req.write() calls in hgwebdir
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5928
diff changeset
   388
        return tmpl("index", entries=entries, subdir=subdir,
abe373e16fe6 hgweb: forgot to centralize the req.write() calls in hgwebdir
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5928
diff changeset
   389
                    sortcolumn=sortcolumn, descending=descending,
abe373e16fe6 hgweb: forgot to centralize the req.write() calls in hgwebdir
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5928
diff changeset
   390
                    **dict(sort))
5602
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   391
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   392
    def templater(self, req):
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   393
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   394
        def header(**map):
7948
de377b1a9a84 move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents: 7740
diff changeset
   395
            yield tmpl('header', encoding=encoding.encoding, **map)
5602
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   396
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   397
        def footer(**map):
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   398
            yield tmpl("footer", **map)
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   399
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   400
        def motd(**map):
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   401
            if self.motd is not None:
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   402
                yield self.motd
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   403
            else:
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   404
                yield config('web', 'motd', '')
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   405
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   406
        def config(section, name, default=None, untrusted=True):
8191
35604226d712 hgweb: kill parentui references
Matt Mackall <mpm@selenic.com>
parents: 8190
diff changeset
   407
            return self.ui.config(section, name, default, untrusted)
5602
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   408
10673
9848b39a1472 hgweb: introduce helper method to update req.env
Yuya Nishihara <yuya@tcha.org>
parents: 10394
diff changeset
   409
        self.updatereqenv(req.env)
6221
2eb18c780287 Support web.baseurl in hgwebdir, overriding SCRIPT_NAME
Brendan Cully <brendan@kublai.com>
parents: 6217
diff changeset
   410
5602
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   411
        url = req.env.get('SCRIPT_NAME', '')
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   412
        if not url.endswith('/'):
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   413
            url += '/'
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   414
8216
25266fe996b0 hgweb: use new sessionvars code in hgwebdir, too
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8215
diff changeset
   415
        vars = {}
9842
d3dbdca92458 hgweb: don't choke when an inexistent style is requested (issue1901)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9724
diff changeset
   416
        styles = (
d3dbdca92458 hgweb: don't choke when an inexistent style is requested (issue1901)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9724
diff changeset
   417
            req.form.get('style', [None])[0],
d3dbdca92458 hgweb: don't choke when an inexistent style is requested (issue1901)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9724
diff changeset
   418
            config('web', 'style'),
d3dbdca92458 hgweb: don't choke when an inexistent style is requested (issue1901)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9724
diff changeset
   419
            'paper'
d3dbdca92458 hgweb: don't choke when an inexistent style is requested (issue1901)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9724
diff changeset
   420
        )
11649
48163c39e1f1 hgwebdir: use template paths configured in the hgrc (issue2281)
Christian Fischer <christian@fi12.de>
parents: 11241
diff changeset
   421
        style, mapfile = templater.stylemap(styles, self.templatepath)
9842
d3dbdca92458 hgweb: don't choke when an inexistent style is requested (issue1901)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9724
diff changeset
   422
        if style == styles[0]:
d3dbdca92458 hgweb: don't choke when an inexistent style is requested (issue1901)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9724
diff changeset
   423
            vars['style'] = style
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   424
8216
25266fe996b0 hgweb: use new sessionvars code in hgwebdir, too
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8215
diff changeset
   425
        start = url[-1] == '?' and '&' or '?'
25266fe996b0 hgweb: use new sessionvars code in hgwebdir, too
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8215
diff changeset
   426
        sessionvars = webutil.sessionvars(vars, start)
13964
616ad3f6fd33 hgweb: support alternate logo url
Steven Stallion <sstallion@gmail.com>
parents: 13821
diff changeset
   427
        logourl = config('web', 'logourl', 'http://mercurial.selenic.com/')
14913
44382887d012 hgweb: add a "web/logoimg" setting to customize the web logo image
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 14076
diff changeset
   428
        logoimg = config('web', 'logoimg', 'hglogo.png')
5602
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   429
        staticurl = config('web', 'staticurl') or url + 'static/'
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   430
        if not staticurl.endswith('/'):
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   431
            staticurl += '/'
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   432
8360
acc202b71619 templater: provide the standard template filters by default
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8359
diff changeset
   433
        tmpl = templater.templater(mapfile,
5602
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   434
                                   defaults={"header": header,
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   435
                                             "footer": footer,
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   436
                                             "motd": motd,
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   437
                                             "url": url,
13964
616ad3f6fd33 hgweb: support alternate logo url
Steven Stallion <sstallion@gmail.com>
parents: 13821
diff changeset
   438
                                             "logourl": logourl,
14913
44382887d012 hgweb: add a "web/logoimg" setting to customize the web logo image
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 14076
diff changeset
   439
                                             "logoimg": logoimg,
8216
25266fe996b0 hgweb: use new sessionvars code in hgwebdir, too
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8215
diff changeset
   440
                                             "staticurl": staticurl,
25266fe996b0 hgweb: use new sessionvars code in hgwebdir, too
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8215
diff changeset
   441
                                             "sessionvars": sessionvars})
5602
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   442
        return tmpl
10673
9848b39a1472 hgweb: introduce helper method to update req.env
Yuya Nishihara <yuya@tcha.org>
parents: 10394
diff changeset
   443
9848b39a1472 hgweb: introduce helper method to update req.env
Yuya Nishihara <yuya@tcha.org>
parents: 10394
diff changeset
   444
    def updatereqenv(self, env):
9848b39a1472 hgweb: introduce helper method to update req.env
Yuya Nishihara <yuya@tcha.org>
parents: 10394
diff changeset
   445
        if self._baseurl is not None:
15003
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
   446
            name, port, path = geturlcgivars(self._baseurl, env['SERVER_PORT'])
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
   447
            env['SERVER_NAME'] = name
a31b8e03af28 hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents: 15002
diff changeset
   448
            env['SERVER_PORT'] = port
15001
dd74cd1e5d49 hgweb: handle 'baseurl' configurations with leading slash (issue2934)
wujek
parents: 14076
diff changeset
   449
            env['SCRIPT_NAME'] = path