mercurial/hgweb/hgweb_mod.py
author Dirkjan Ochtman <dirkjan@ochtman.nl>
Fri, 07 Sep 2007 17:38:52 +0200
changeset 5289 ed6df6b1c29a
parent 5064 ccdc8db02bdf
child 5290 05889b6b1468
child 5331 8ee5b8129e7b
permissions -rw-r--r--
Prevent WSGI apps from touching sys.stdin by setting ui.interactive to False.
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: 2361
diff changeset
     1
# hgweb/hgweb_mod.py - Web interface for a repository.
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>
4635
63b9d2deed48 Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4539
diff changeset
     4
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
     5
#
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
     6
# This software may be used and distributed according to the terms
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
     7
# of the GNU General Public License, incorporated herein by reference.
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
     8
3974
a3aa97171546 hgweb: fix unused import
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3973
diff changeset
     9
import os, mimetypes, re, zlib, mimetools, cStringIO, sys
3877
abaee83ce0a6 Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents: 3781
diff changeset
    10
import tempfile, urllib, bz2
2311
b832b6eb65ab Moving hgweb.py into it's own module in preparation for breaking it up.
Eric Hopper <hopper@omnifarious.org>
parents: 2275
diff changeset
    11
from mercurial.node import *
b832b6eb65ab Moving hgweb.py into it's own module in preparation for breaking it up.
Eric Hopper <hopper@omnifarious.org>
parents: 2275
diff changeset
    12
from mercurial.i18n import gettext as _
3877
abaee83ce0a6 Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents: 3781
diff changeset
    13
from mercurial import mdiff, ui, hg, util, archival, streamclone, patch
abaee83ce0a6 Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents: 3781
diff changeset
    14
from mercurial import revlog, templater
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
    15
from common import get_mtime, staticfile, style_map, paritygen
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    16
2356
2db831b33e8f Final stage of the hgweb split up.
Eric Hopper <hopper@omnifarious.org>
parents: 2355
diff changeset
    17
def _up(p):
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
    18
    if p[0] != "/":
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
    19
        p = "/" + p
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
    20
    if p[-1] == "/":
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
    21
        p = p[:-1]
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    22
    up = os.path.dirname(p)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    23
    if up == "/":
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    24
        return "/"
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    25
    return up + "/"
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    26
3422
0eba7e76cd02 Convert changenav bar from revisions to hashes (closes issue189)
Brendan Cully <brendan@kublai.com>
parents: 3409
diff changeset
    27
def revnavgen(pos, pagelen, limit, nodefunc):
3407
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    28
    def seq(factor, limit=None):
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    29
        if limit:
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    30
            yield limit
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    31
            if limit >= 20 and limit <= 40:
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    32
                yield 50
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    33
        else:
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    34
            yield 1 * factor
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    35
            yield 3 * factor
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    36
        for f in seq(factor * 10):
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    37
            yield f
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    38
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    39
    def nav(**map):
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    40
        l = []
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    41
        last = 0
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    42
        for f in seq(1, pagelen):
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    43
            if f < pagelen or f <= last:
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    44
                continue
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    45
            if f > limit:
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    46
                break
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    47
            last = f
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    48
            if pos + f < limit:
3422
0eba7e76cd02 Convert changenav bar from revisions to hashes (closes issue189)
Brendan Cully <brendan@kublai.com>
parents: 3409
diff changeset
    49
                l.append(("+%d" % f, hex(nodefunc(pos + f).node())))
3407
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    50
            if pos - f >= 0:
3422
0eba7e76cd02 Convert changenav bar from revisions to hashes (closes issue189)
Brendan Cully <brendan@kublai.com>
parents: 3409
diff changeset
    51
                l.insert(0, ("-%d" % f, hex(nodefunc(pos - f).node())))
3407
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    52
3424
9b1c126b74cd Fix test-oldcgi after navbar update
Brendan Cully <brendan@kublai.com>
parents: 3423
diff changeset
    53
        try:
9b1c126b74cd Fix test-oldcgi after navbar update
Brendan Cully <brendan@kublai.com>
parents: 3423
diff changeset
    54
            yield {"label": "(0)", "node": hex(nodefunc('0').node())}
3407
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    55
3424
9b1c126b74cd Fix test-oldcgi after navbar update
Brendan Cully <brendan@kublai.com>
parents: 3423
diff changeset
    56
            for label, node in l:
9b1c126b74cd Fix test-oldcgi after navbar update
Brendan Cully <brendan@kublai.com>
parents: 3423
diff changeset
    57
                yield {"label": label, "node": node}
3407
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    58
3427
6bd676ee8b99 Explicitly use "tip" in revision navigation.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3424
diff changeset
    59
            yield {"label": "tip", "node": "tip"}
3424
9b1c126b74cd Fix test-oldcgi after navbar update
Brendan Cully <brendan@kublai.com>
parents: 3423
diff changeset
    60
        except hg.RepoError:
9b1c126b74cd Fix test-oldcgi after navbar update
Brendan Cully <brendan@kublai.com>
parents: 3423
diff changeset
    61
            pass
3407
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    62
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    63
    return nav
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
    64
1559
59b3639df0a9 Convert all classes to new-style classes by deriving them from object.
Eric Hopper <hopper@omnifarious.org>
parents: 1554
diff changeset
    65
class hgweb(object):
987
bfe12654764d hgweb: change startup argument processing
mpm@selenic.com
parents: 986
diff changeset
    66
    def __init__(self, repo, name=None):
bfe12654764d hgweb: change startup argument processing
mpm@selenic.com
parents: 986
diff changeset
    67
        if type(repo) == type(""):
5289
ed6df6b1c29a Prevent WSGI apps from touching sys.stdin by setting ui.interactive to False.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5064
diff changeset
    68
            parentui = ui.ui(report_untrusted=False, interactive=False)
ed6df6b1c29a Prevent WSGI apps from touching sys.stdin by setting ui.interactive to False.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5064
diff changeset
    69
            self.repo = hg.repository(parentui, repo)
987
bfe12654764d hgweb: change startup argument processing
mpm@selenic.com
parents: 986
diff changeset
    70
        else:
bfe12654764d hgweb: change startup argument processing
mpm@selenic.com
parents: 986
diff changeset
    71
            self.repo = repo
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    72
258
268bcb5a072a hgweb: watch changelog for changes
mpm@selenic.com
parents: 241
diff changeset
    73
        self.mtime = -1
1172
3f30a5e7e15b Use path relative to document root as reponame if published via a web server.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1170
diff changeset
    74
        self.reponame = name
1078
33f40d0c6124 Various cleanups for tarball support
mpm@selenic.com
parents: 1077
diff changeset
    75
        self.archives = 'zip', 'gz', 'bz2'
2666
ebf033bc8eb2 hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 2622
diff changeset
    76
        self.stripecount = 1
3555
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
    77
        # a repo owner may set web.templates in .hg/hgrc to get any file
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
    78
        # readable by the user running the CGI script
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
    79
        self.templatepath = self.config("web", "templates",
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
    80
                                        templater.templatepath(),
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
    81
                                        untrusted=False)
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
    82
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
    83
    # The CGI scripts are often run by a user different from the repo owner.
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
    84
    # Trust the settings from the .hg/hgrc files by default.
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
    85
    def config(self, section, name, default=None, untrusted=True):
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
    86
        return self.repo.ui.config(section, name, default,
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
    87
                                   untrusted=untrusted)
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
    88
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
    89
    def configbool(self, section, name, default=False, untrusted=True):
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
    90
        return self.repo.ui.configbool(section, name, default,
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
    91
                                       untrusted=untrusted)
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
    92
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
    93
    def configlist(self, section, name, default=None, untrusted=True):
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
    94
        return self.repo.ui.configlist(section, name, default,
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
    95
                                       untrusted=untrusted)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    96
258
268bcb5a072a hgweb: watch changelog for changes
mpm@selenic.com
parents: 241
diff changeset
    97
    def refresh(self):
1418
68f81ba07b2a Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1416
diff changeset
    98
        mtime = get_mtime(self.repo.root)
68f81ba07b2a Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1416
diff changeset
    99
        if mtime != self.mtime:
68f81ba07b2a Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1416
diff changeset
   100
            self.mtime = mtime
1213
db9639b8594c Clean up hgweb imports
mpm@selenic.com
parents: 1210
diff changeset
   101
            self.repo = hg.repository(self.repo.ui, self.repo.root)
3555
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
   102
            self.maxchanges = int(self.config("web", "maxchanges", 10))
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
   103
            self.stripecount = int(self.config("web", "stripes", 1))
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
   104
            self.maxshortchanges = int(self.config("web", "maxshortchanges", 60))
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
   105
            self.maxfiles = int(self.config("web", "maxfiles", 10))
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
   106
            self.allowpull = self.configbool("web", "allowpull", True)
4690
ecea4de3104e Enable to select encoding in hgrc web section
OHASHI Hideya <ohachige at gmail.com>
parents: 4669
diff changeset
   107
            self.encoding = self.config("web", "encoding", util._encoding)
258
268bcb5a072a hgweb: watch changelog for changes
mpm@selenic.com
parents: 241
diff changeset
   108
1498
78590fb4a82b hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1473
diff changeset
   109
    def archivelist(self, nodeid):
3555
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
   110
        allowed = self.configlist("web", "allow_archive")
3260
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   111
        for i, spec in self.archive_specs.iteritems():
3555
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
   112
            if i in allowed or self.configbool("web", "allow" + i):
3260
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   113
                yield {"type" : i, "extension" : spec[2], "node" : nodeid}
1498
78590fb4a82b hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1473
diff changeset
   114
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   115
    def listfilediffs(self, files, changeset):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   116
        for f in files[:self.maxfiles]:
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   117
            yield self.t("filedifflink", node=hex(changeset), file=f)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   118
        if len(files) > self.maxfiles:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   119
            yield self.t("fileellipses")
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   120
3208
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   121
    def siblings(self, siblings=[], hiderev=None, **args):
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   122
        siblings = [s for s in siblings if s.node() != nullid]
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   123
        if len(siblings) == 1 and siblings[0].rev() == hiderev:
1416
19d2776f1725 hgweb: hide trivial parent (like in show_changeset)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1411
diff changeset
   124
            return
1606
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
   125
        for s in siblings:
3392
17894d1d9eea hgweb: fix parent/child links across renames
Brendan Cully <brendan@kublai.com>
parents: 3391
diff changeset
   126
            d = {'node': hex(s.node()), 'rev': s.rev()}
3394
be628f1cd3f4 hgweb: really fix parent/child rename links
Brendan Cully <brendan@kublai.com>
parents: 3392
diff changeset
   127
            if hasattr(s, 'path'):
be628f1cd3f4 hgweb: really fix parent/child rename links
Brendan Cully <brendan@kublai.com>
parents: 3392
diff changeset
   128
                d['file'] = s.path()
3392
17894d1d9eea hgweb: fix parent/child links across renames
Brendan Cully <brendan@kublai.com>
parents: 3391
diff changeset
   129
            d.update(args)
17894d1d9eea hgweb: fix parent/child links across renames
Brendan Cully <brendan@kublai.com>
parents: 3391
diff changeset
   130
            yield d
569
3e347929f5f9 [PATCH 1/5]: cleaning the template parent management in hgweb
mpm@selenic.com
parents: 568
diff changeset
   131
1653
e8a3df8b62b3 hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents: 1650
diff changeset
   132
    def renamelink(self, fl, node):
e8a3df8b62b3 hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents: 1650
diff changeset
   133
        r = fl.renamed(node)
e8a3df8b62b3 hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents: 1650
diff changeset
   134
        if r:
e8a3df8b62b3 hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents: 1650
diff changeset
   135
            return [dict(file=r[0], node=hex(r[1]))]
e8a3df8b62b3 hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents: 1650
diff changeset
   136
        return []
e8a3df8b62b3 hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents: 1650
diff changeset
   137
4539
e6c69a2491ed Small cleanups for the new tag code
Brendan Cully <brendan@kublai.com>
parents: 4538
diff changeset
   138
    def nodetagsdict(self, node):
e6c69a2491ed Small cleanups for the new tag code
Brendan Cully <brendan@kublai.com>
parents: 4538
diff changeset
   139
        return [{"name": i} for i in self.repo.nodetags(node)]
4538
4272ae760bb1 gitweb: Display branch and tag labels
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 4469
diff changeset
   140
4539
e6c69a2491ed Small cleanups for the new tag code
Brendan Cully <brendan@kublai.com>
parents: 4538
diff changeset
   141
    def nodebranchdict(self, ctx):
e6c69a2491ed Small cleanups for the new tag code
Brendan Cully <brendan@kublai.com>
parents: 4538
diff changeset
   142
        branches = []
e6c69a2491ed Small cleanups for the new tag code
Brendan Cully <brendan@kublai.com>
parents: 4538
diff changeset
   143
        branch = ctx.branch()
e6c69a2491ed Small cleanups for the new tag code
Brendan Cully <brendan@kublai.com>
parents: 4538
diff changeset
   144
        if self.repo.branchtags()[branch] == ctx.node():
e6c69a2491ed Small cleanups for the new tag code
Brendan Cully <brendan@kublai.com>
parents: 4538
diff changeset
   145
            branches.append({"name": branch})
e6c69a2491ed Small cleanups for the new tag code
Brendan Cully <brendan@kublai.com>
parents: 4538
diff changeset
   146
        return branches
4538
4272ae760bb1 gitweb: Display branch and tag labels
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 4469
diff changeset
   147
568
e8fd41110dce [PATCH] Add tags to hgweb
mpm@selenic.com
parents: 547
diff changeset
   148
    def showtag(self, t1, node=nullid, **args):
e8fd41110dce [PATCH] Add tags to hgweb
mpm@selenic.com
parents: 547
diff changeset
   149
        for t in self.repo.nodetags(node):
3673
eb0b4a2d70a9 white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3612
diff changeset
   150
            yield self.t(t1, tag=t, **args)
568
e8fd41110dce [PATCH] Add tags to hgweb
mpm@selenic.com
parents: 547
diff changeset
   151
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   152
    def diff(self, node1, node2, files):
1626
f2b1df3dbcbb make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1619
diff changeset
   153
        def filterfiles(filters, files):
1627
11cd38286fdb fix for hgweb.filterfiles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1626
diff changeset
   154
            l = [x for x in files if x in filters]
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 391
diff changeset
   155
1626
f2b1df3dbcbb make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1619
diff changeset
   156
            for t in filters:
1627
11cd38286fdb fix for hgweb.filterfiles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1626
diff changeset
   157
                if t and t[-1] != os.sep:
1626
f2b1df3dbcbb make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1619
diff changeset
   158
                    t += os.sep
f2b1df3dbcbb make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1619
diff changeset
   159
                l += [x for x in files if x.startswith(t)]
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   160
            return l
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   161
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   162
        parity = paritygen(self.stripecount)
172
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
   163
        def diffblock(diff, f, fn):
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
   164
            yield self.t("diffblock",
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   165
                         lines=prettyprintlines(diff),
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   166
                         parity=parity.next(),
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   167
                         file=f,
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   168
                         filenode=hex(fn or nullid))
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 391
diff changeset
   169
172
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
   170
        def prettyprintlines(diff):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   171
            for l in diff.splitlines(1):
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   172
                if l.startswith('+'):
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   173
                    yield self.t("difflineplus", line=l)
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   174
                elif l.startswith('-'):
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   175
                    yield self.t("difflineminus", line=l)
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   176
                elif l.startswith('@'):
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   177
                    yield self.t("difflineat", line=l)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   178
                else:
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   179
                    yield self.t("diffline", line=l)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   180
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   181
        r = self.repo
3973
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   182
        c1 = r.changectx(node1)
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   183
        c2 = r.changectx(node2)
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   184
        date1 = util.datestr(c1.date())
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   185
        date2 = util.datestr(c2.date())
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   186
2876
cf86bbb8ed68 hgweb: repo.changes() is now called repo.status()
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents: 2874
diff changeset
   187
        modified, added, removed, deleted, unknown = r.status(node1, node2)[:5]
645
a55048b2ae3a this patch permits hgweb to show the deleted files in the changeset diff
kreijack@inwind.REMOVEME.it
parents: 635
diff changeset
   188
        if files:
1626
f2b1df3dbcbb make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1619
diff changeset
   189
            modified, added, removed = map(lambda x: filterfiles(files, x),
1618
ff339dd21976 Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1606
diff changeset
   190
                                           (modified, added, removed))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   191
3555
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
   192
        diffopts = patch.diffopts(self.repo.ui, untrusted=True)
1618
ff339dd21976 Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1606
diff changeset
   193
        for f in modified:
3973
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   194
            to = c1.filectx(f).data()
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   195
            tn = c2.filectx(f).data()
1637
3b1b44b917f4 Add new bdiff based unidiff generation.
mason@suse.com
parents: 1627
diff changeset
   196
            yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2859
diff changeset
   197
                                          opts=diffopts), f, tn)
1618
ff339dd21976 Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1606
diff changeset
   198
        for f in added:
265
7ca05593bd30 hgweb: fix non-existent source or destination for diff
mpm@selenic.com
parents: 258
diff changeset
   199
            to = None
3973
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   200
            tn = c2.filectx(f).data()
1637
3b1b44b917f4 Add new bdiff based unidiff generation.
mason@suse.com
parents: 1627
diff changeset
   201
            yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2859
diff changeset
   202
                                          opts=diffopts), f, tn)
1618
ff339dd21976 Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1606
diff changeset
   203
        for f in removed:
3973
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   204
            to = c1.filectx(f).data()
265
7ca05593bd30 hgweb: fix non-existent source or destination for diff
mpm@selenic.com
parents: 258
diff changeset
   205
            tn = None
1637
3b1b44b917f4 Add new bdiff based unidiff generation.
mason@suse.com
parents: 1627
diff changeset
   206
            yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2859
diff changeset
   207
                                          opts=diffopts), f, tn)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   208
3220
325278542ea8 hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents: 3208
diff changeset
   209
    def changelog(self, ctx, shortlog=False):
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   210
        def changelist(**map):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   211
            cl = self.repo.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   212
            l = [] # build a list in forward order for efficiency
3473
0e68608bd11d use xrange instead of range
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3445
diff changeset
   213
            for i in xrange(start, end):
3208
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   214
                ctx = self.repo.changectx(i)
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   215
                n = ctx.node()
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   216
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   217
                l.insert(0, {"parity": parity.next(),
3208
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   218
                             "author": ctx.user(),
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   219
                             "parent": self.siblings(ctx.parents(), i - 1),
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   220
                             "child": self.siblings(ctx.children(), i + 1),
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   221
                             "changelogtag": self.showtag("changelogtag",n),
3208
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   222
                             "desc": ctx.description(),
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   223
                             "date": ctx.date(),
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   224
                             "files": self.listfilediffs(ctx.files(), n),
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   225
                             "rev": i,
4538
4272ae760bb1 gitweb: Display branch and tag labels
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 4469
diff changeset
   226
                             "node": hex(n),
4539
e6c69a2491ed Small cleanups for the new tag code
Brendan Cully <brendan@kublai.com>
parents: 4538
diff changeset
   227
                             "tags": self.nodetagsdict(n),
e6c69a2491ed Small cleanups for the new tag code
Brendan Cully <brendan@kublai.com>
parents: 4538
diff changeset
   228
                             "branches": self.nodebranchdict(ctx)})
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   229
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   230
            for e in l:
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   231
                yield e
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   232
2684
783220e5d2d1 [hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2683
diff changeset
   233
        maxchanges = shortlog and self.maxshortchanges or self.maxchanges
168
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   234
        cl = self.repo.changelog
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   235
        count = cl.count()
3407
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
   236
        pos = ctx.rev()
2684
783220e5d2d1 [hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2683
diff changeset
   237
        start = max(0, pos - maxchanges + 1)
783220e5d2d1 [hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2683
diff changeset
   238
        end = min(count, start + maxchanges)
351
9525208e1c1d hgweb: change number navigation tidy up
mpm@selenic.com
parents: 350
diff changeset
   239
        pos = end - 1
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   240
        parity = paritygen(self.stripecount, offset=start-end)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   241
3422
0eba7e76cd02 Convert changenav bar from revisions to hashes (closes issue189)
Brendan Cully <brendan@kublai.com>
parents: 3409
diff changeset
   242
        changenav = revnavgen(pos, maxchanges, count, self.repo.changectx)
3407
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
   243
2684
783220e5d2d1 [hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2683
diff changeset
   244
        yield self.t(shortlog and 'shortlog' or 'changelog',
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   245
                     changenav=changenav,
3205
48395d2692de hgweb: kill #manifest#
Brendan Cully <brendan@kublai.com>
parents: 3179
diff changeset
   246
                     node=hex(cl.tip()),
2170
29eeb2717915 Add archive download links to tip on main changeset list page
Colin McMillen <mcmillen@cs.cmu.edu>
parents: 2148
diff changeset
   247
                     rev=pos, changesets=count, entries=changelist,
29eeb2717915 Add archive download links to tip on main changeset list page
Colin McMillen <mcmillen@cs.cmu.edu>
parents: 2148
diff changeset
   248
                     archives=self.archivelist("tip"))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   249
538
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   250
    def search(self, query):
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   251
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   252
        def changelist(**map):
538
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   253
            cl = self.repo.changelog
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   254
            count = 0
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   255
            qw = query.lower().split()
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   256
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   257
            def revgen():
3473
0e68608bd11d use xrange instead of range
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3445
diff changeset
   258
                for i in xrange(cl.count() - 1, 0, -100):
538
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   259
                    l = []
3473
0e68608bd11d use xrange instead of range
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3445
diff changeset
   260
                    for j in xrange(max(0, i - 100), i):
3208
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   261
                        ctx = self.repo.changectx(j)
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   262
                        l.append(ctx)
1023
bc806ba72959 Minor tweak to the revgen algorithm
mpm@selenic.com
parents: 1022
diff changeset
   263
                    l.reverse()
538
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   264
                    for e in l:
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   265
                        yield e
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   266
3208
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   267
            for ctx in revgen():
538
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   268
                miss = 0
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   269
                for q in qw:
3208
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   270
                    if not (q in ctx.user().lower() or
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   271
                            q in ctx.description().lower() or
4323
7843528a7922 hgweb: expand keyword search to full list of files
TK Soh <teekaysoh@yahoo.com>
parents: 4243
diff changeset
   272
                            q in " ".join(ctx.files()).lower()):
538
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   273
                        miss = 1
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   274
                        break
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   275
                if miss:
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   276
                    continue
538
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   277
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   278
                count += 1
3208
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   279
                n = ctx.node()
538
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   280
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   281
                yield self.t('searchentry',
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   282
                             parity=parity.next(),
3208
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   283
                             author=ctx.user(),
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   284
                             parent=self.siblings(ctx.parents()),
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   285
                             child=self.siblings(ctx.children()),
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   286
                             changelogtag=self.showtag("changelogtag",n),
3208
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   287
                             desc=ctx.description(),
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   288
                             date=ctx.date(),
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   289
                             files=self.listfilediffs(ctx.files(), n),
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   290
                             rev=ctx.rev(),
4538
4272ae760bb1 gitweb: Display branch and tag labels
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 4469
diff changeset
   291
                             node=hex(n),
4539
e6c69a2491ed Small cleanups for the new tag code
Brendan Cully <brendan@kublai.com>
parents: 4538
diff changeset
   292
                             tags=self.nodetagsdict(n),
e6c69a2491ed Small cleanups for the new tag code
Brendan Cully <brendan@kublai.com>
parents: 4538
diff changeset
   293
                             branches=self.nodebranchdict(ctx))
538
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   294
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   295
                if count >= self.maxchanges:
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   296
                    break
538
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   297
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   298
        cl = self.repo.changelog
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   299
        parity = paritygen(self.stripecount)
538
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   300
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   301
        yield self.t('search',
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   302
                     query=query,
3205
48395d2692de hgweb: kill #manifest#
Brendan Cully <brendan@kublai.com>
parents: 3179
diff changeset
   303
                     node=hex(cl.tip()),
4469
8af65bc092b0 gitweb: Fixed-up search template
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 4462
diff changeset
   304
                     entries=changelist,
8af65bc092b0 gitweb: Fixed-up search template
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 4462
diff changeset
   305
                     archives=self.archivelist("tip"))
538
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   306
3220
325278542ea8 hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents: 3208
diff changeset
   307
    def changeset(self, ctx):
3208
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   308
        n = ctx.node()
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   309
        parents = ctx.parents()
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   310
        p1 = parents[0].node()
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 391
diff changeset
   311
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   312
        files = []
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   313
        parity = paritygen(self.stripecount)
3208
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   314
        for f in ctx.files():
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   315
            files.append(self.t("filenodelink",
3206
79fd7a92f3e2 hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents: 3205
diff changeset
   316
                                node=hex(n), file=f,
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   317
                                parity=parity.next()))
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   318
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   319
        def diff(**map):
645
a55048b2ae3a this patch permits hgweb to show the deleted files in the changeset diff
kreijack@inwind.REMOVEME.it
parents: 635
diff changeset
   320
            yield self.diff(p1, n, None)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   321
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   322
        yield self.t('changeset',
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   323
                     diff=diff,
3208
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   324
                     rev=ctx.rev(),
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   325
                     node=hex(n),
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   326
                     parent=self.siblings(parents),
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   327
                     child=self.siblings(ctx.children()),
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   328
                     changesettag=self.showtag("changesettag",n),
3208
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   329
                     author=ctx.user(),
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   330
                     desc=ctx.description(),
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   331
                     date=ctx.date(),
1076
01db658cc78a tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents: 1073
diff changeset
   332
                     files=files,
4538
4272ae760bb1 gitweb: Display branch and tag labels
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 4469
diff changeset
   333
                     archives=self.archivelist(hex(n)),
4539
e6c69a2491ed Small cleanups for the new tag code
Brendan Cully <brendan@kublai.com>
parents: 4538
diff changeset
   334
                     tags=self.nodetagsdict(n),
e6c69a2491ed Small cleanups for the new tag code
Brendan Cully <brendan@kublai.com>
parents: 4538
diff changeset
   335
                     branches=self.nodebranchdict(ctx))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   336
3206
79fd7a92f3e2 hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents: 3205
diff changeset
   337
    def filelog(self, fctx):
79fd7a92f3e2 hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents: 3205
diff changeset
   338
        f = fctx.path()
79fd7a92f3e2 hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents: 3205
diff changeset
   339
        fl = fctx.filelog()
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   340
        count = fl.count()
3407
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
   341
        pagelen = self.maxshortchanges
3409
1ae738bacf74 Fixed page overlap for file revision links in hgweb.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3407
diff changeset
   342
        pos = fctx.filerev()
3673
eb0b4a2d70a9 white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3612
diff changeset
   343
        start = max(0, pos - pagelen + 1)
3409
1ae738bacf74 Fixed page overlap for file revision links in hgweb.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3407
diff changeset
   344
        end = min(count, start + pagelen)
1ae738bacf74 Fixed page overlap for file revision links in hgweb.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3407
diff changeset
   345
        pos = end - 1
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   346
        parity = paritygen(self.stripecount, offset=start-end)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   347
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   348
        def entries(**map):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   349
            l = []
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 391
diff changeset
   350
3473
0e68608bd11d use xrange instead of range
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3445
diff changeset
   351
            for i in xrange(start, end):
3208
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   352
                ctx = fctx.filectx(i)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   353
                n = fl.node(i)
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   354
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   355
                l.insert(0, {"parity": parity.next(),
978
ea67e5b37043 hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 977
diff changeset
   356
                             "filerev": i,
ea67e5b37043 hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 977
diff changeset
   357
                             "file": f,
3206
79fd7a92f3e2 hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents: 3205
diff changeset
   358
                             "node": hex(ctx.node()),
79fd7a92f3e2 hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents: 3205
diff changeset
   359
                             "author": ctx.user(),
79fd7a92f3e2 hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents: 3205
diff changeset
   360
                             "date": ctx.date(),
1653
e8a3df8b62b3 hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents: 1650
diff changeset
   361
                             "rename": self.renamelink(fl, n),
3392
17894d1d9eea hgweb: fix parent/child links across renames
Brendan Cully <brendan@kublai.com>
parents: 3391
diff changeset
   362
                             "parent": self.siblings(fctx.parents()),
17894d1d9eea hgweb: fix parent/child links across renames
Brendan Cully <brendan@kublai.com>
parents: 3391
diff changeset
   363
                             "child": self.siblings(fctx.children()),
3206
79fd7a92f3e2 hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents: 3205
diff changeset
   364
                             "desc": ctx.description()})
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   365
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   366
            for e in l:
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   367
                yield e
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   368
3422
0eba7e76cd02 Convert changenav bar from revisions to hashes (closes issue189)
Brendan Cully <brendan@kublai.com>
parents: 3409
diff changeset
   369
        nodefunc = lambda x: fctx.filectx(fileid=x)
0eba7e76cd02 Convert changenav bar from revisions to hashes (closes issue189)
Brendan Cully <brendan@kublai.com>
parents: 3409
diff changeset
   370
        nav = revnavgen(pos, pagelen, count, nodefunc)
3407
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
   371
        yield self.t("filelog", file=f, node=hex(fctx.node()), nav=nav,
03e7e8958a27 hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents: 3406
diff changeset
   372
                     entries=entries)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   373
3206
79fd7a92f3e2 hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents: 3205
diff changeset
   374
    def filerevision(self, fctx):
79fd7a92f3e2 hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents: 3205
diff changeset
   375
        f = fctx.path()
79fd7a92f3e2 hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents: 3205
diff changeset
   376
        text = fctx.data()
79fd7a92f3e2 hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents: 3205
diff changeset
   377
        fl = fctx.filelog()
79fd7a92f3e2 hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents: 3205
diff changeset
   378
        n = fctx.filenode()
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   379
        parity = paritygen(self.stripecount)
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   380
1411
e2ba788545bf hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1409
diff changeset
   381
        mt = mimetypes.guess_type(f)[0]
e2ba788545bf hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1409
diff changeset
   382
        rawtext = text
e2ba788545bf hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1409
diff changeset
   383
        if util.binary(text):
2103
caccf539c9a4 Use application/octet-stream as the content-type of unknown binary files
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2095
diff changeset
   384
            mt = mt or 'application/octet-stream'
caccf539c9a4 Use application/octet-stream as the content-type of unknown binary files
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2095
diff changeset
   385
            text = "(binary:%s)" % mt
2095
0bf2a9e5eff1 Don't send "Content-Type: none"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 1964
diff changeset
   386
        mt = mt or 'text/plain'
1411
e2ba788545bf hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1409
diff changeset
   387
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   388
        def lines():
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   389
            for l, t in enumerate(text.splitlines(1)):
976
5d5ab159d197 hgweb: Changed file page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 975
diff changeset
   390
                yield {"line": t,
5d5ab159d197 hgweb: Changed file page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 975
diff changeset
   391
                       "linenumber": "% 6d" % (l + 1),
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   392
                       "parity": parity.next()}
359
0c4688e9ee5c hgweb: add file permissions
mpm@selenic.com
parents: 351
diff changeset
   393
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   394
        yield self.t("filerevision",
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   395
                     file=f,
2356
2db831b33e8f Final stage of the hgweb split up.
Eric Hopper <hopper@omnifarious.org>
parents: 2355
diff changeset
   396
                     path=_up(f),
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   397
                     text=lines(),
1411
e2ba788545bf hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1409
diff changeset
   398
                     raw=rawtext,
e2ba788545bf hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1409
diff changeset
   399
                     mimetype=mt,
3206
79fd7a92f3e2 hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents: 3205
diff changeset
   400
                     rev=fctx.rev(),
79fd7a92f3e2 hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents: 3205
diff changeset
   401
                     node=hex(fctx.node()),
79fd7a92f3e2 hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents: 3205
diff changeset
   402
                     author=fctx.user(),
79fd7a92f3e2 hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents: 3205
diff changeset
   403
                     date=fctx.date(),
3395
3c8f0dc9a6d3 hgweb: add changeset description to file revision page
Brendan Cully <brendan@kublai.com>
parents: 3394
diff changeset
   404
                     desc=fctx.description(),
3392
17894d1d9eea hgweb: fix parent/child links across renames
Brendan Cully <brendan@kublai.com>
parents: 3391
diff changeset
   405
                     parent=self.siblings(fctx.parents()),
17894d1d9eea hgweb: fix parent/child links across renames
Brendan Cully <brendan@kublai.com>
parents: 3391
diff changeset
   406
                     child=self.siblings(fctx.children()),
1653
e8a3df8b62b3 hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents: 1650
diff changeset
   407
                     rename=self.renamelink(fl, n),
4745
e21a0e12ff10 hgweb: use lrwxrwxrwx as the permissions of a symlink
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4690
diff changeset
   408
                     permissions=fctx.manifest().flags(f))
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   409
3206
79fd7a92f3e2 hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents: 3205
diff changeset
   410
    def fileannotate(self, fctx):
79fd7a92f3e2 hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents: 3205
diff changeset
   411
        f = fctx.path()
3173
3466bd7b9754 hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents: 3131
diff changeset
   412
        n = fctx.filenode()
3466bd7b9754 hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents: 3131
diff changeset
   413
        fl = fctx.filelog()
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   414
        parity = paritygen(self.stripecount)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   415
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   416
        def annotate(**map):
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   417
            last = None
3175
fc379b91f602 hgweb: make annotate line revisions point to annotation for that rev
Brendan Cully <brendan@kublai.com>
parents: 3173
diff changeset
   418
            for f, l in fctx.annotate(follow=True):
fc379b91f602 hgweb: make annotate line revisions point to annotation for that rev
Brendan Cully <brendan@kublai.com>
parents: 3173
diff changeset
   419
                fnode = f.filenode()
3173
3466bd7b9754 hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents: 3131
diff changeset
   420
                name = self.repo.ui.shortuser(f.user())
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   421
3175
fc379b91f602 hgweb: make annotate line revisions point to annotation for that rev
Brendan Cully <brendan@kublai.com>
parents: 3173
diff changeset
   422
                if last != fnode:
fc379b91f602 hgweb: make annotate line revisions point to annotation for that rev
Brendan Cully <brendan@kublai.com>
parents: 3173
diff changeset
   423
                    last = fnode
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   424
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   425
                yield {"parity": parity.next(),
3178
0d0d7317bbc8 hgweb: yield filenode as well as node in annotate, use filenode in annotateline
Brendan Cully <brendan@kublai.com>
parents: 3177
diff changeset
   426
                       "node": hex(f.node()),
3403
372999405787 Back out d8eba1c3ce9b and a004164dbeef
Brendan Cully <brendan@kublai.com>
parents: 3402
diff changeset
   427
                       "rev": f.rev(),
977
289975641886 hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 976
diff changeset
   428
                       "author": name,
3173
3466bd7b9754 hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents: 3131
diff changeset
   429
                       "file": f.path(),
977
289975641886 hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 976
diff changeset
   430
                       "line": l}
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   431
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   432
        yield self.t("fileannotate",
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   433
                     file=f,
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   434
                     annotate=annotate,
2356
2db831b33e8f Final stage of the hgweb split up.
Eric Hopper <hopper@omnifarious.org>
parents: 2355
diff changeset
   435
                     path=_up(f),
3173
3466bd7b9754 hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents: 3131
diff changeset
   436
                     rev=fctx.rev(),
3177
8683c7a637ad hgweb: fix changeset link in annotate view.
Brendan Cully <brendan@kublai.com>
parents: 3175
diff changeset
   437
                     node=hex(fctx.node()),
3173
3466bd7b9754 hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents: 3131
diff changeset
   438
                     author=fctx.user(),
3466bd7b9754 hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents: 3131
diff changeset
   439
                     date=fctx.date(),
3391
defadc26e674 hgweb: add changeset description to annotate page
Brendan Cully <brendan@kublai.com>
parents: 3382
diff changeset
   440
                     desc=fctx.description(),
1653
e8a3df8b62b3 hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents: 1650
diff changeset
   441
                     rename=self.renamelink(fl, n),
3392
17894d1d9eea hgweb: fix parent/child links across renames
Brendan Cully <brendan@kublai.com>
parents: 3391
diff changeset
   442
                     parent=self.siblings(fctx.parents()),
17894d1d9eea hgweb: fix parent/child links across renames
Brendan Cully <brendan@kublai.com>
parents: 3391
diff changeset
   443
                     child=self.siblings(fctx.children()),
4745
e21a0e12ff10 hgweb: use lrwxrwxrwx as the permissions of a symlink
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4690
diff changeset
   444
                     permissions=fctx.manifest().flags(f))
136
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   445
3205
48395d2692de hgweb: kill #manifest#
Brendan Cully <brendan@kublai.com>
parents: 3179
diff changeset
   446
    def manifest(self, ctx, path):
48395d2692de hgweb: kill #manifest#
Brendan Cully <brendan@kublai.com>
parents: 3179
diff changeset
   447
        mf = ctx.manifest()
48395d2692de hgweb: kill #manifest#
Brendan Cully <brendan@kublai.com>
parents: 3179
diff changeset
   448
        node = ctx.node()
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   449
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   450
        files = {}
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   451
        parity = paritygen(self.stripecount)
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 391
diff changeset
   452
3595
fc34fd58ae7b hgweb: fix handling of path for old style template
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3557
diff changeset
   453
        if path and path[-1] != "/":
fc34fd58ae7b hgweb: fix handling of path for old style template
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3557
diff changeset
   454
            path += "/"
fc34fd58ae7b hgweb: fix handling of path for old style template
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3557
diff changeset
   455
        l = len(path)
fc34fd58ae7b hgweb: fix handling of path for old style template
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3557
diff changeset
   456
        abspath = "/" + path
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   457
3673
eb0b4a2d70a9 white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3612
diff changeset
   458
        for f, n in mf.items():
3595
fc34fd58ae7b hgweb: fix handling of path for old style template
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3557
diff changeset
   459
            if f[:l] != path:
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   460
                continue
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   461
            remain = f[l:]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   462
            if "/" in remain:
2579
0875cda033fd use __contains__, index or split instead of str.find
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2558
diff changeset
   463
                short = remain[:remain.index("/") + 1] # bleah
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   464
                files[short] = (f, None)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   465
            else:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   466
                short = os.path.basename(remain)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   467
                files[short] = (f, n)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   468
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   469
        def filelist(**map):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   470
            fl = files.keys()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   471
            fl.sort()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   472
            for f in fl:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   473
                full, fnode = files[f]
979
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   474
                if not fnode:
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   475
                    continue
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   476
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   477
                yield {"file": full,
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   478
                       "parity": parity.next(),
979
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   479
                       "basename": f,
3305
0708bdb4987a hgweb: add file sizes to manifest browsing
Matt Mackall <mpm@selenic.com>
parents: 3304
diff changeset
   480
                       "size": ctx.filectx(full).size(),
4745
e21a0e12ff10 hgweb: use lrwxrwxrwx as the permissions of a symlink
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4690
diff changeset
   481
                       "permissions": mf.flags(full)}
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   482
979
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   483
        def dirlist(**map):
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   484
            fl = files.keys()
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   485
            fl.sort()
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   486
            for f in fl:
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   487
                full, fnode = files[f]
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   488
                if fnode:
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   489
                    continue
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   490
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   491
                yield {"parity": parity.next(),
5064
ccdc8db02bdf hgweb: don't use os.path.join to build URL parts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4834
diff changeset
   492
                       "path": "%s%s" % (abspath, f),
980
5197fb9d65d5 Merge with MPM
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 979 939
diff changeset
   493
                       "basename": f[:-1]}
982
8d2e24bae760 hgweb: convert index entries to list expansion style
mpm@selenic.com
parents: 981
diff changeset
   494
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   495
        yield self.t("manifest",
3205
48395d2692de hgweb: kill #manifest#
Brendan Cully <brendan@kublai.com>
parents: 3179
diff changeset
   496
                     rev=ctx.rev(),
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   497
                     node=hex(node),
3595
fc34fd58ae7b hgweb: fix handling of path for old style template
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3557
diff changeset
   498
                     path=abspath,
fc34fd58ae7b hgweb: fix handling of path for old style template
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3557
diff changeset
   499
                     up=_up(abspath),
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   500
                     upparity=parity.next(),
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   501
                     fentries=filelist,
1498
78590fb4a82b hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1473
diff changeset
   502
                     dentries=dirlist,
4538
4272ae760bb1 gitweb: Display branch and tag labels
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 4469
diff changeset
   503
                     archives=self.archivelist(hex(node)),
4539
e6c69a2491ed Small cleanups for the new tag code
Brendan Cully <brendan@kublai.com>
parents: 4538
diff changeset
   504
                     tags=self.nodetagsdict(node),
e6c69a2491ed Small cleanups for the new tag code
Brendan Cully <brendan@kublai.com>
parents: 4538
diff changeset
   505
                     branches=self.nodebranchdict(ctx))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   506
168
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   507
    def tags(self):
343
d7df759d0e97 rework all code using tags
mpm@selenic.com
parents: 330
diff changeset
   508
        i = self.repo.tagslist()
d7df759d0e97 rework all code using tags
mpm@selenic.com
parents: 330
diff changeset
   509
        i.reverse()
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   510
        parity = paritygen(self.stripecount)
168
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   511
1767
adbc392dfd9e implement entriesnotip for tags in hgweb.py ; change entries to entriesnotip in templates/tags-rss.tmpl
Peter van Dijk <peter@dataloss.nl>
parents: 1653
diff changeset
   512
        def entries(notip=False, **map):
3673
eb0b4a2d70a9 white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3612
diff changeset
   513
            for k, n in i:
eb0b4a2d70a9 white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3612
diff changeset
   514
                if notip and k == "tip":
eb0b4a2d70a9 white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3612
diff changeset
   515
                    continue
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   516
                yield {"parity": parity.next(),
974
aedb47764f29 Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 938
diff changeset
   517
                       "tag": k,
3973
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   518
                       "date": self.repo.changectx(n).date(),
974
aedb47764f29 Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 938
diff changeset
   519
                       "node": hex(n)}
168
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   520
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   521
        yield self.t("tags",
3205
48395d2692de hgweb: kill #manifest#
Brendan Cully <brendan@kublai.com>
parents: 3179
diff changeset
   522
                     node=hex(self.repo.changelog.tip()),
1767
adbc392dfd9e implement entriesnotip for tags in hgweb.py ; change entries to entriesnotip in templates/tags-rss.tmpl
Peter van Dijk <peter@dataloss.nl>
parents: 1653
diff changeset
   523
                     entries=lambda **x: entries(False, **x),
adbc392dfd9e implement entriesnotip for tags in hgweb.py ; change entries to entriesnotip in templates/tags-rss.tmpl
Peter van Dijk <peter@dataloss.nl>
parents: 1653
diff changeset
   524
                     entriesnotip=lambda **x: entries(True, **x))
168
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   525
1572
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   526
    def summary(self):
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   527
        i = self.repo.tagslist()
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   528
        i.reverse()
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   529
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   530
        def tagentries(**map):
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   531
            parity = paritygen(self.stripecount)
1579
85803ec2daab Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1575
diff changeset
   532
            count = 0
3673
eb0b4a2d70a9 white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3612
diff changeset
   533
            for k, n in i:
1579
85803ec2daab Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1575
diff changeset
   534
                if k == "tip": # skip tip
1572
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   535
                    continue;
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   536
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   537
                count += 1
1579
85803ec2daab Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1575
diff changeset
   538
                if count > 10: # limit to 10 tags
1572
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   539
                    break;
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   540
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   541
                yield self.t("tagentry",
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   542
                             parity=parity.next(),
3973
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   543
                             tag=k,
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   544
                             node=hex(n),
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   545
                             date=self.repo.changectx(n).date())
1579
85803ec2daab Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1575
diff changeset
   546
4300
05d15c456fb2 hgweb: display named branches in gitweb-style summary page
greg@maptuit.com
parents: 4282
diff changeset
   547
05d15c456fb2 hgweb: display named branches in gitweb-style summary page
greg@maptuit.com
parents: 4282
diff changeset
   548
        def branches(**map):
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   549
            parity = paritygen(self.stripecount)
3499
e0db0b7934f2 hgweb: add heads to gitweb summary
Brendan Cully <brendan@kublai.com>
parents: 3488
diff changeset
   550
4300
05d15c456fb2 hgweb: display named branches in gitweb-style summary page
greg@maptuit.com
parents: 4282
diff changeset
   551
            b = self.repo.branchtags()
05d15c456fb2 hgweb: display named branches in gitweb-style summary page
greg@maptuit.com
parents: 4282
diff changeset
   552
            l = [(-self.repo.changelog.rev(n), n, t) for t, n in b.items()]
05d15c456fb2 hgweb: display named branches in gitweb-style summary page
greg@maptuit.com
parents: 4282
diff changeset
   553
            l.sort()
3499
e0db0b7934f2 hgweb: add heads to gitweb summary
Brendan Cully <brendan@kublai.com>
parents: 3488
diff changeset
   554
4300
05d15c456fb2 hgweb: display named branches in gitweb-style summary page
greg@maptuit.com
parents: 4282
diff changeset
   555
            for r,n,t in l:
05d15c456fb2 hgweb: display named branches in gitweb-style summary page
greg@maptuit.com
parents: 4282
diff changeset
   556
                ctx = self.repo.changectx(n)
3499
e0db0b7934f2 hgweb: add heads to gitweb summary
Brendan Cully <brendan@kublai.com>
parents: 3488
diff changeset
   557
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   558
                yield {'parity': parity.next(),
4300
05d15c456fb2 hgweb: display named branches in gitweb-style summary page
greg@maptuit.com
parents: 4282
diff changeset
   559
                       'branch': t,
05d15c456fb2 hgweb: display named branches in gitweb-style summary page
greg@maptuit.com
parents: 4282
diff changeset
   560
                       'node': hex(n),
3499
e0db0b7934f2 hgweb: add heads to gitweb summary
Brendan Cully <brendan@kublai.com>
parents: 3488
diff changeset
   561
                       'date': ctx.date()}
e0db0b7934f2 hgweb: add heads to gitweb summary
Brendan Cully <brendan@kublai.com>
parents: 3488
diff changeset
   562
1572
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   563
        def changelist(**map):
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   564
            parity = paritygen(self.stripecount, offset=start-end)
1572
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   565
            l = [] # build a list in forward order for efficiency
3473
0e68608bd11d use xrange instead of range
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3445
diff changeset
   566
            for i in xrange(start, end):
3973
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   567
                ctx = self.repo.changectx(i)
4538
4272ae760bb1 gitweb: Display branch and tag labels
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 4469
diff changeset
   568
                n = ctx.node()
4272ae760bb1 gitweb: Display branch and tag labels
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 4469
diff changeset
   569
                hn = hex(n)
1572
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   570
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   571
                l.insert(0, self.t(
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   572
                    'shortlogentry',
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4458
diff changeset
   573
                    parity=parity.next(),
3973
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   574
                    author=ctx.user(),
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   575
                    desc=ctx.description(),
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   576
                    date=ctx.date(),
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   577
                    rev=i,
4538
4272ae760bb1 gitweb: Display branch and tag labels
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 4469
diff changeset
   578
                    node=hn,
4539
e6c69a2491ed Small cleanups for the new tag code
Brendan Cully <brendan@kublai.com>
parents: 4538
diff changeset
   579
                    tags=self.nodetagsdict(n),
e6c69a2491ed Small cleanups for the new tag code
Brendan Cully <brendan@kublai.com>
parents: 4538
diff changeset
   580
                    branches=self.nodebranchdict(ctx)))
1572
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   581
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   582
            yield l
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   583
3973
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   584
        cl = self.repo.changelog
1572
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   585
        count = cl.count()
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   586
        start = max(0, count - self.maxchanges)
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   587
        end = min(count, start + self.maxchanges)
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   588
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   589
        yield self.t("summary",
3973
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   590
                 desc=self.config("web", "description", "unknown"),
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   591
                 owner=(self.config("ui", "username") or # preferred
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   592
                        self.config("web", "contact") or # deprecated
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   593
                        self.config("web", "author", "unknown")), # also
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   594
                 lastchange=cl.read(cl.tip())[2],
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   595
                 tags=tagentries,
4300
05d15c456fb2 hgweb: display named branches in gitweb-style summary page
greg@maptuit.com
parents: 4282
diff changeset
   596
                 branches=branches,
3973
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   597
                 shortlog=changelist,
b485a4459d96 hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3936
diff changeset
   598
                 node=hex(cl.tip()),
2683
8a798185809d [hgweb] Fixed up gitweb templates
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2622
diff changeset
   599
                 archives=self.archivelist("tip"))
1579
85803ec2daab Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1575
diff changeset
   600
3220
325278542ea8 hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents: 3208
diff changeset
   601
    def filediff(self, fctx):
325278542ea8 hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents: 3208
diff changeset
   602
        n = fctx.node()
325278542ea8 hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents: 3208
diff changeset
   603
        path = fctx.path()
3406
970b2d6de3b3 hgweb: link to file parents in filediff, rather than changeset parents
Brendan Cully <brendan@kublai.com>
parents: 3403
diff changeset
   604
        parents = fctx.parents()
970b2d6de3b3 hgweb: link to file parents in filediff, rather than changeset parents
Brendan Cully <brendan@kublai.com>
parents: 3403
diff changeset
   605
        p1 = parents and parents[0].node() or nullid
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 391
diff changeset
   606
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   607
        def diff(**map):
3220
325278542ea8 hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents: 3208
diff changeset
   608
            yield self.diff(p1, n, [path])
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   609
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   610
        yield self.t("filediff",
3220
325278542ea8 hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents: 3208
diff changeset
   611
                     file=path,
3208
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   612
                     node=hex(n),
3220
325278542ea8 hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents: 3208
diff changeset
   613
                     rev=fctx.rev(),
3208
e7b7906cc47e hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents: 3206
diff changeset
   614
                     parent=self.siblings(parents),
3220
325278542ea8 hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents: 3208
diff changeset
   615
                     child=self.siblings(fctx.children()),
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   616
                     diff=diff)
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 391
diff changeset
   617
2113
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   618
    archive_specs = {
2361
d3adb454c5a9 Fix automatic decompression of tarballs with Firefox.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2359
diff changeset
   619
        'bz2': ('application/x-tar', 'tbz2', '.tar.bz2', None),
d3adb454c5a9 Fix automatic decompression of tarballs with Firefox.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2359
diff changeset
   620
        'gz': ('application/x-tar', 'tgz', '.tar.gz', None),
2113
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   621
        'zip': ('application/zip', 'zip', '.zip', None),
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   622
        }
1076
01db658cc78a tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents: 1073
diff changeset
   623
4669
96e096fe9e86 hgweb_mod.archive(): Use 'key' instead of builtin 'id'.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4635
diff changeset
   624
    def archive(self, req, key, type_):
2113
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   625
        reponame = re.sub(r"\W+", "-", os.path.basename(self.reponame))
4669
96e096fe9e86 hgweb_mod.archive(): Use 'key' instead of builtin 'id'.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4635
diff changeset
   626
        cnode = self.repo.lookup(key)
96e096fe9e86 hgweb_mod.archive(): Use 'key' instead of builtin 'id'.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4635
diff changeset
   627
        arch_version = key
96e096fe9e86 hgweb_mod.archive(): Use 'key' instead of builtin 'id'.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4635
diff changeset
   628
        if cnode == key or key == 'tip':
4164
5c1e18bb804c hgweb: use the given revision in the name of the archive
Michael Gebetsroither <michael.geb@gmx.at>
parents: 4096
diff changeset
   629
            arch_version = short(cnode)
5c1e18bb804c hgweb: use the given revision in the name of the archive
Michael Gebetsroither <michael.geb@gmx.at>
parents: 4096
diff changeset
   630
        name = "%s-%s" % (reponame, arch_version)
2394
a8f1049d1d2d hgweb: fix errors and warnings found by pychecker
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2391
diff changeset
   631
        mimetype, artype, extension, encoding = self.archive_specs[type_]
2113
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   632
        headers = [('Content-type', mimetype),
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   633
                   ('Content-disposition', 'attachment; filename=%s%s' %
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   634
                    (name, extension))]
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   635
        if encoding:
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   636
            headers.append(('Content-encoding', encoding))
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   637
        req.header(headers)
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   638
        archival.archive(self.repo, req.out, cnode, artype, prefix=name)
1076
01db658cc78a tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents: 1073
diff changeset
   639
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   640
    # add tags to things
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   641
    # tags -> list of changesets corresponding to tags
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   642
    # find tag, changeset, file
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   643
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   644
    def cleanpath(self, path):
3595
fc34fd58ae7b hgweb: fix handling of path for old style template
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3557
diff changeset
   645
        path = path.lstrip('/')
3382
80721b86a448 hgweb: fix path cleaning
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3363
diff changeset
   646
        return util.canonpath(self.repo.root, '', path)
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   647
2535
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2534
diff changeset
   648
    def run(self):
2538
f4b7d71c1c60 Cleanup hgweb and hgwebdir's run method a bit.
Eric Hopper <hopper@omnifarious.org>
parents: 2535
diff changeset
   649
        if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."):
2535
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2534
diff changeset
   650
            raise RuntimeError("This function is only intended to be called while running as a CGI script.")
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2534
diff changeset
   651
        import mercurial.hgweb.wsgicgi as wsgicgi
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2534
diff changeset
   652
        from request import wsgiapplication
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2534
diff changeset
   653
        def make_web_app():
2538
f4b7d71c1c60 Cleanup hgweb and hgwebdir's run method a bit.
Eric Hopper <hopper@omnifarious.org>
parents: 2535
diff changeset
   654
            return self
2535
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2534
diff changeset
   655
        wsgicgi.launch(wsgiapplication(make_web_app))
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2534
diff changeset
   656
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2534
diff changeset
   657
    def run_wsgi(self, req):
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   658
        def header(**map):
3781
713e35dcc321 hgweb: report detected character set
Matt Mackall <mpm@selenic.com>
parents: 3673
diff changeset
   659
            header_file = cStringIO.StringIO(
4690
ecea4de3104e Enable to select encoding in hgrc web section
OHASHI Hideya <ohachige at gmail.com>
parents: 4669
diff changeset
   660
                ''.join(self.t("header", encoding=self.encoding, **map)))
2514
419c42223bee Really fix http headers for web UI and issue 254.
Eric Hopper <hopper@omnifarious.org>
parents: 2509
diff changeset
   661
            msg = mimetools.Message(header_file, 0)
419c42223bee Really fix http headers for web UI and issue 254.
Eric Hopper <hopper@omnifarious.org>
parents: 2509
diff changeset
   662
            req.header(msg.items())
419c42223bee Really fix http headers for web UI and issue 254.
Eric Hopper <hopper@omnifarious.org>
parents: 2509
diff changeset
   663
            yield header_file.read()
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   664
2534
d5a3cc6520d5 Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
   665
        def rawfileheader(**map):
d5a3cc6520d5 Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
   666
            req.header([('Content-type', map['mimetype']),
d5a3cc6520d5 Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
   667
                        ('Content-disposition', 'filename=%s' % map['file']),
d5a3cc6520d5 Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
   668
                        ('Content-length', str(len(map['raw'])))])
d5a3cc6520d5 Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
   669
            yield ''
d5a3cc6520d5 Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
   670
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   671
        def footer(**map):
3488
8f02223662c8 hgweb: make #motd# available for all templates
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3473
diff changeset
   672
            yield self.t("footer", **map)
8f02223662c8 hgweb: make #motd# available for all templates
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3473
diff changeset
   673
8f02223662c8 hgweb: make #motd# available for all templates
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3473
diff changeset
   674
        def motd(**map):
3555
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
   675
            yield self.config("web", "motd", "")
1409
964baa35faf8 hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents: 1407
diff changeset
   676
1406
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   677
        def expand_form(form):
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   678
            shortcuts = {
1409
964baa35faf8 hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents: 1407
diff changeset
   679
                'cl': [('cmd', ['changelog']), ('rev', None)],
2684
783220e5d2d1 [hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2683
diff changeset
   680
                'sl': [('cmd', ['shortlog']), ('rev', None)],
1406
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   681
                'cs': [('cmd', ['changeset']), ('node', None)],
1409
964baa35faf8 hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents: 1407
diff changeset
   682
                'f': [('cmd', ['file']), ('filenode', None)],
964baa35faf8 hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents: 1407
diff changeset
   683
                'fl': [('cmd', ['filelog']), ('filenode', None)],
964baa35faf8 hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents: 1407
diff changeset
   684
                'fd': [('cmd', ['filediff']), ('node', None)],
964baa35faf8 hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents: 1407
diff changeset
   685
                'fa': [('cmd', ['annotate']), ('filenode', None)],
964baa35faf8 hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents: 1407
diff changeset
   686
                'mf': [('cmd', ['manifest']), ('manifest', None)],
964baa35faf8 hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents: 1407
diff changeset
   687
                'ca': [('cmd', ['archive']), ('node', None)],
964baa35faf8 hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents: 1407
diff changeset
   688
                'tags': [('cmd', ['tags'])],
964baa35faf8 hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents: 1407
diff changeset
   689
                'tip': [('cmd', ['changeset']), ('node', ['tip'])],
1777
a2316878f19d [hgweb] Static content serving
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1703
diff changeset
   690
                'static': [('cmd', ['static']), ('file', None)]
1406
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   691
            }
1409
964baa35faf8 hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents: 1407
diff changeset
   692
1406
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   693
            for k in shortcuts.iterkeys():
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   694
                if form.has_key(k):
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   695
                    for name, value in shortcuts[k]:
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   696
                        if value is None:
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   697
                            value = form[k]
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   698
                        form[name] = value
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   699
                    del form[k]
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   700
3260
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   701
        def rewrite_request(req):
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   702
            '''translate new web interface to traditional format'''
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   703
3263
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   704
            def spliturl(req):
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   705
                def firstitem(query):
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   706
                    return query.split('&', 1)[0].split(';', 1)[0]
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   707
3327
e6353b7b102a NWI base URL detection fixes
Brendan Cully <brendan@kublai.com>
parents: 3305
diff changeset
   708
                def normurl(url):
e6353b7b102a NWI base URL detection fixes
Brendan Cully <brendan@kublai.com>
parents: 3305
diff changeset
   709
                    inner = '/'.join([x for x in url.split('/') if x])
e6353b7b102a NWI base URL detection fixes
Brendan Cully <brendan@kublai.com>
parents: 3305
diff changeset
   710
                    tl = len(url) > 1 and url.endswith('/') and '/' or ''
3263
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   711
3327
e6353b7b102a NWI base URL detection fixes
Brendan Cully <brendan@kublai.com>
parents: 3305
diff changeset
   712
                    return '%s%s%s' % (url.startswith('/') and '/' or '',
e6353b7b102a NWI base URL detection fixes
Brendan Cully <brendan@kublai.com>
parents: 3305
diff changeset
   713
                                       inner, tl)
e6353b7b102a NWI base URL detection fixes
Brendan Cully <brendan@kublai.com>
parents: 3305
diff changeset
   714
3606
f8589028a7fa hgweb: split URLs containing spaces or other escaped characters correctly
Brendan Cully <brendan@kublai.com>
parents: 3595
diff changeset
   715
                root = normurl(urllib.unquote(req.env.get('REQUEST_URI', '').split('?', 1)[0]))
3327
e6353b7b102a NWI base URL detection fixes
Brendan Cully <brendan@kublai.com>
parents: 3305
diff changeset
   716
                pi = normurl(req.env.get('PATH_INFO', ''))
3263
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   717
                if pi:
3327
e6353b7b102a NWI base URL detection fixes
Brendan Cully <brendan@kublai.com>
parents: 3305
diff changeset
   718
                    # strip leading /
e6353b7b102a NWI base URL detection fixes
Brendan Cully <brendan@kublai.com>
parents: 3305
diff changeset
   719
                    pi = pi[1:]
e6353b7b102a NWI base URL detection fixes
Brendan Cully <brendan@kublai.com>
parents: 3305
diff changeset
   720
                    if pi:
4348
b633f470944e hgweb: fix rfind bug in PATH_INFO handling
Matt Mackall <mpm@selenic.com>
parents: 4339
diff changeset
   721
                        root = root[:root.rfind(pi)]
3327
e6353b7b102a NWI base URL detection fixes
Brendan Cully <brendan@kublai.com>
parents: 3305
diff changeset
   722
                    if req.env.has_key('REPO_NAME'):
e6353b7b102a NWI base URL detection fixes
Brendan Cully <brendan@kublai.com>
parents: 3305
diff changeset
   723
                        rn = req.env['REPO_NAME'] + '/'
e6353b7b102a NWI base URL detection fixes
Brendan Cully <brendan@kublai.com>
parents: 3305
diff changeset
   724
                        root += rn
e6353b7b102a NWI base URL detection fixes
Brendan Cully <brendan@kublai.com>
parents: 3305
diff changeset
   725
                        query = pi[len(rn):]
3263
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   726
                    else:
3327
e6353b7b102a NWI base URL detection fixes
Brendan Cully <brendan@kublai.com>
parents: 3305
diff changeset
   727
                        query = pi
3263
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   728
                else:
3327
e6353b7b102a NWI base URL detection fixes
Brendan Cully <brendan@kublai.com>
parents: 3305
diff changeset
   729
                    root += '?'
3263
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   730
                    query = firstitem(req.env['QUERY_STRING'])
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   731
3327
e6353b7b102a NWI base URL detection fixes
Brendan Cully <brendan@kublai.com>
parents: 3305
diff changeset
   732
                return (root, query)
3263
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   733
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   734
            req.url, query = spliturl(req)
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   735
3260
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   736
            if req.form.has_key('cmd'):
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   737
                # old style
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   738
                return
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   739
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   740
            args = query.split('/', 2)
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   741
            if not args or not args[0]:
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   742
                return
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   743
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   744
            cmd = args.pop(0)
3261
329ac0c0c0e8 hgweb: extract raw prefix from NWI commands
Brendan Cully <brendan@kublai.com>
parents: 3260
diff changeset
   745
            style = cmd.rfind('-')
329ac0c0c0e8 hgweb: extract raw prefix from NWI commands
Brendan Cully <brendan@kublai.com>
parents: 3260
diff changeset
   746
            if style != -1:
329ac0c0c0e8 hgweb: extract raw prefix from NWI commands
Brendan Cully <brendan@kublai.com>
parents: 3260
diff changeset
   747
                req.form['style'] = [cmd[:style]]
329ac0c0c0e8 hgweb: extract raw prefix from NWI commands
Brendan Cully <brendan@kublai.com>
parents: 3260
diff changeset
   748
                cmd = cmd[style+1:]
3263
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   749
            # avoid accepting e.g. style parameter as command
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   750
            if hasattr(self, 'do_' + cmd):
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   751
                req.form['cmd'] = [cmd]
3260
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   752
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   753
            if args and args[0]:
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   754
                node = args.pop(0)
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   755
                req.form['node'] = [node]
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   756
            if args:
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   757
                req.form['file'] = args
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   758
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   759
            if cmd == 'static':
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   760
                req.form['file'] = req.form['node']
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   761
            elif cmd == 'archive':
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   762
                fn = req.form['node'][0]
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   763
                for type_, spec in self.archive_specs.iteritems():
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   764
                    ext = spec[2]
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   765
                    if fn.endswith(ext):
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   766
                        req.form['node'] = [fn[:-len(ext)]]
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   767
                        req.form['type'] = [type_]
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   768
3362
887da2247b57 hgweb: Keep session variables (currently only style) in HTML forms, too.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3359
diff changeset
   769
        def sessionvars(**map):
887da2247b57 hgweb: Keep session variables (currently only style) in HTML forms, too.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3359
diff changeset
   770
            fields = []
887da2247b57 hgweb: Keep session variables (currently only style) in HTML forms, too.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3359
diff changeset
   771
            if req.form.has_key('style'):
887da2247b57 hgweb: Keep session variables (currently only style) in HTML forms, too.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3359
diff changeset
   772
                style = req.form['style'][0]
3555
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
   773
                if style != self.config('web', 'style', ''):
3362
887da2247b57 hgweb: Keep session variables (currently only style) in HTML forms, too.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3359
diff changeset
   774
                    fields.append(('style', style))
887da2247b57 hgweb: Keep session variables (currently only style) in HTML forms, too.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3359
diff changeset
   775
3363
ce8f31e0b3b8 hgweb: Apply the new method of passing session variables to links.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3362
diff changeset
   776
            separator = req.url[-1] == '?' and ';' or '?'
3362
887da2247b57 hgweb: Keep session variables (currently only style) in HTML forms, too.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3359
diff changeset
   777
            for name, value in fields:
3363
ce8f31e0b3b8 hgweb: Apply the new method of passing session variables to links.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3362
diff changeset
   778
                yield dict(name=name, value=value, separator=separator)
ce8f31e0b3b8 hgweb: Apply the new method of passing session variables to links.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3362
diff changeset
   779
                separator = ';'
3270
a7370503d800 hgweb: provide means for handling query parameters
Brendan Cully <brendan@kublai.com>
parents: 3267
diff changeset
   780
258
268bcb5a072a hgweb: watch changelog for changes
mpm@selenic.com
parents: 241
diff changeset
   781
        self.refresh()
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   782
1406
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   783
        expand_form(req.form)
3260
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   784
        rewrite_request(req)
1406
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   785
3555
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
   786
        style = self.config("web", "style", "")
1159
b6f5a947e62e Change use of global sys.stdout, sys.stdin os.environ to a hgrequest object.
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents: 1143
diff changeset
   787
        if req.form.has_key('style'):
b6f5a947e62e Change use of global sys.stdout, sys.stdin os.environ to a hgrequest object.
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents: 1143
diff changeset
   788
            style = req.form['style'][0]
3276
db9d2a624521 hgweb: Search templates in templatepath/style/map, too, using a common function.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3274
diff changeset
   789
        mapfile = style_map(self.templatepath, style)
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 391
diff changeset
   790
3423
a2179e78d18b Fix RSS URLs (closes issue396)
Brendan Cully <brendan@kublai.com>
parents: 3422
diff changeset
   791
        port = req.env["SERVER_PORT"]
a2179e78d18b Fix RSS URLs (closes issue396)
Brendan Cully <brendan@kublai.com>
parents: 3422
diff changeset
   792
        port = port != "80" and (":" + port) or ""
a2179e78d18b Fix RSS URLs (closes issue396)
Brendan Cully <brendan@kublai.com>
parents: 3422
diff changeset
   793
        urlbase = 'http://%s%s' % (req.env['SERVER_NAME'], port)
4084
51e52db6b40d hgweb: allow static files to be served directly by the HTTP server
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3974
diff changeset
   794
        staticurl = self.config("web", "staticurl") or req.url + 'static/'
51e52db6b40d hgweb: allow static files to be served directly by the HTTP server
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3974
diff changeset
   795
        if not staticurl.endswith('/'):
51e52db6b40d hgweb: allow static files to be served directly by the HTTP server
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3974
diff changeset
   796
            staticurl += '/'
3263
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   797
1172
3f30a5e7e15b Use path relative to document root as reponame if published via a web server.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1170
diff changeset
   798
        if not self.reponame:
3555
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
   799
            self.reponame = (self.config("web", "name")
3263
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   800
                             or req.env.get('REPO_NAME')
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   801
                             or req.url.strip('/') or self.repo.root)
601
8865eb8ade99 Add globals to templater/fixup RSS
mpm@selenic.com
parents: 600
diff changeset
   802
3276
db9d2a624521 hgweb: Search templates in templatepath/style/map, too, using a common function.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3274
diff changeset
   803
        self.t = templater.templater(mapfile, templater.common_filters,
3263
3207e30bf468 hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents: 3261
diff changeset
   804
                                     defaults={"url": req.url,
4084
51e52db6b40d hgweb: allow static files to be served directly by the HTTP server
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3974
diff changeset
   805
                                               "staticurl": staticurl,
3423
a2179e78d18b Fix RSS URLs (closes issue396)
Brendan Cully <brendan@kublai.com>
parents: 3422
diff changeset
   806
                                               "urlbase": urlbase,
1964
778281d46bb2 fix template bug that made hgweb break.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1920
diff changeset
   807
                                               "repo": self.reponame,
778281d46bb2 fix template bug that made hgweb break.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1920
diff changeset
   808
                                               "header": header,
778281d46bb2 fix template bug that made hgweb break.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1920
diff changeset
   809
                                               "footer": footer,
3488
8f02223662c8 hgweb: make #motd# available for all templates
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3473
diff changeset
   810
                                               "motd": motd,
2534
d5a3cc6520d5 Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
   811
                                               "rawfileheader": rawfileheader,
3363
ce8f31e0b3b8 hgweb: Apply the new method of passing session variables to links.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3362
diff changeset
   812
                                               "sessionvars": sessionvars
1964
778281d46bb2 fix template bug that made hgweb break.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1920
diff changeset
   813
                                               })
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   814
4243
3f2e334937ce hgweb: break templater -> templater circular reference
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4228
diff changeset
   815
        try:
3f2e334937ce hgweb: break templater -> templater circular reference
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4228
diff changeset
   816
            if not req.form.has_key('cmd'):
3f2e334937ce hgweb: break templater -> templater circular reference
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4228
diff changeset
   817
                req.form['cmd'] = [self.t.cache['default']]
937
e4f1b76831b2 Whitespace
mpm@selenic.com
parents: 896
diff changeset
   818
4243
3f2e334937ce hgweb: break templater -> templater circular reference
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4228
diff changeset
   819
            cmd = req.form['cmd'][0]
575
7f5ce4bbdd7b More whitespace cleanups
mpm@selenic.com
parents: 572
diff changeset
   820
4243
3f2e334937ce hgweb: break templater -> templater circular reference
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4228
diff changeset
   821
            method = getattr(self, 'do_' + cmd, None)
3f2e334937ce hgweb: break templater -> templater circular reference
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4228
diff changeset
   822
            if method:
3f2e334937ce hgweb: break templater -> templater circular reference
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4228
diff changeset
   823
                try:
3f2e334937ce hgweb: break templater -> templater circular reference
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4228
diff changeset
   824
                    method(req)
3f2e334937ce hgweb: break templater -> templater circular reference
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4228
diff changeset
   825
                except (hg.RepoError, revlog.RevlogError), inst:
3f2e334937ce hgweb: break templater -> templater circular reference
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4228
diff changeset
   826
                    req.write(self.t("error", error=str(inst)))
3f2e334937ce hgweb: break templater -> templater circular reference
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4228
diff changeset
   827
            else:
3f2e334937ce hgweb: break templater -> templater circular reference
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4228
diff changeset
   828
                req.write(self.t("error", error='No such method: ' + cmd))
3f2e334937ce hgweb: break templater -> templater circular reference
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4228
diff changeset
   829
        finally:
3f2e334937ce hgweb: break templater -> templater circular reference
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4228
diff changeset
   830
            self.t = None
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   831
3226
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   832
    def changectx(self, req):
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   833
        if req.form.has_key('node'):
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   834
            changeid = req.form['node'][0]
3333
8ec80c1b8f0b hgweb: globally default to tip if no revision is specified
Brendan Cully <brendan@kublai.com>
parents: 3327
diff changeset
   835
        elif req.form.has_key('manifest'):
8ec80c1b8f0b hgweb: globally default to tip if no revision is specified
Brendan Cully <brendan@kublai.com>
parents: 3327
diff changeset
   836
            changeid = req.form['manifest'][0]
3226
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   837
        else:
3333
8ec80c1b8f0b hgweb: globally default to tip if no revision is specified
Brendan Cully <brendan@kublai.com>
parents: 3327
diff changeset
   838
            changeid = self.repo.changelog.count() - 1
8ec80c1b8f0b hgweb: globally default to tip if no revision is specified
Brendan Cully <brendan@kublai.com>
parents: 3327
diff changeset
   839
3226
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   840
        try:
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   841
            ctx = self.repo.changectx(changeid)
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   842
        except hg.RepoError:
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   843
            man = self.repo.manifest
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   844
            mn = man.lookup(changeid)
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   845
            ctx = self.repo.changectx(man.linkrev(mn))
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   846
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   847
        return ctx
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   848
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   849
    def filectx(self, req):
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   850
        path = self.cleanpath(req.form['file'][0])
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   851
        if req.form.has_key('node'):
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   852
            changeid = req.form['node'][0]
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   853
        else:
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   854
            changeid = req.form['filenode'][0]
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   855
        try:
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   856
            ctx = self.repo.changectx(changeid)
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   857
            fctx = ctx.filectx(path)
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   858
        except hg.RepoError:
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   859
            fctx = self.repo.filectx(path, fileid=changeid)
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   860
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   861
        return fctx
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   862
3260
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   863
    def do_log(self, req):
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   864
        if req.form.has_key('file') and req.form['file'][0]:
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   865
            self.do_filelog(req)
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   866
        else:
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   867
            self.do_changelog(req)
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   868
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   869
    def do_rev(self, req):
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   870
        self.do_changeset(req)
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   871
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   872
    def do_file(self, req):
3595
fc34fd58ae7b hgweb: fix handling of path for old style template
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3557
diff changeset
   873
        path = self.cleanpath(req.form.get('file', [''])[0])
3260
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   874
        if path:
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   875
            try:
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   876
                req.write(self.filerevision(self.filectx(req)))
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   877
                return
3936
ea238a4e9e8b Teach hgweb about revlog.LookupError
Brendan Cully <brendan@kublai.com>
parents: 3887
diff changeset
   878
            except revlog.LookupError:
3260
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   879
                pass
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   880
3595
fc34fd58ae7b hgweb: fix handling of path for old style template
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3557
diff changeset
   881
        req.write(self.manifest(self.changectx(req), path))
3260
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   882
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   883
    def do_diff(self, req):
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   884
        self.do_filediff(req)
1f1af9b273e8 hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents: 3231
diff changeset
   885
3226
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   886
    def do_changelog(self, req, shortlog = False):
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   887
        if req.form.has_key('node'):
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   888
            ctx = self.changectx(req)
3220
325278542ea8 hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents: 3208
diff changeset
   889
        else:
3226
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   890
            if req.form.has_key('rev'):
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   891
                hi = req.form['rev'][0]
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   892
            else:
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   893
                hi = self.repo.changelog.count() - 1
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   894
            try:
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   895
                ctx = self.repo.changectx(hi)
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   896
            except hg.RepoError:
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   897
                req.write(self.search(hi)) # XXX redirect to 404 page?
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   898
                return
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   899
3226
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   900
        req.write(self.changelog(ctx, shortlog = shortlog))
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   901
2684
783220e5d2d1 [hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2683
diff changeset
   902
    def do_shortlog(self, req):
3226
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   903
        self.do_changelog(req, shortlog = True)
2684
783220e5d2d1 [hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 2683
diff changeset
   904
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   905
    def do_changeset(self, req):
3333
8ec80c1b8f0b hgweb: globally default to tip if no revision is specified
Brendan Cully <brendan@kublai.com>
parents: 3327
diff changeset
   906
        req.write(self.changeset(self.changectx(req)))
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   907
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   908
    def do_manifest(self, req):
3226
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   909
        req.write(self.manifest(self.changectx(req),
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   910
                                self.cleanpath(req.form['path'][0])))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   911
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   912
    def do_tags(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   913
        req.write(self.tags())
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   914
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   915
    def do_summary(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   916
        req.write(self.summary())
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   917
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   918
    def do_filediff(self, req):
3226
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   919
        req.write(self.filediff(self.filectx(req)))
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   920
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   921
    def do_annotate(self, req):
3226
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   922
        req.write(self.fileannotate(self.filectx(req)))
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   923
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   924
    def do_filelog(self, req):
3226
5c6028778c5a hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents: 3220
diff changeset
   925
        req.write(self.filelog(self.filectx(req)))
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   926
3444
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   927
    def do_lookup(self, req):
3445
233c733e4af5 httprepo: add support for passing lookup exception data
Matt Mackall <mpm@selenic.com>
parents: 3444
diff changeset
   928
        try:
233c733e4af5 httprepo: add support for passing lookup exception data
Matt Mackall <mpm@selenic.com>
parents: 3444
diff changeset
   929
            r = hex(self.repo.lookup(req.form['key'][0]))
233c733e4af5 httprepo: add support for passing lookup exception data
Matt Mackall <mpm@selenic.com>
parents: 3444
diff changeset
   930
            success = 1
233c733e4af5 httprepo: add support for passing lookup exception data
Matt Mackall <mpm@selenic.com>
parents: 3444
diff changeset
   931
        except Exception,inst:
233c733e4af5 httprepo: add support for passing lookup exception data
Matt Mackall <mpm@selenic.com>
parents: 3444
diff changeset
   932
            r = str(inst)
233c733e4af5 httprepo: add support for passing lookup exception data
Matt Mackall <mpm@selenic.com>
parents: 3444
diff changeset
   933
            success = 0
233c733e4af5 httprepo: add support for passing lookup exception data
Matt Mackall <mpm@selenic.com>
parents: 3444
diff changeset
   934
        resp = "%s %s\n" % (success, r)
3444
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   935
        req.httphdr("application/mercurial-0.1", length=len(resp))
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   936
        req.write(resp)
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   937
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   938
    def do_heads(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   939
        resp = " ".join(map(hex, self.repo.heads())) + "\n"
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   940
        req.httphdr("application/mercurial-0.1", length=len(resp))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   941
        req.write(resp)
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   942
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   943
    def do_branches(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   944
        nodes = []
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   945
        if req.form.has_key('nodes'):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   946
            nodes = map(bin, req.form['nodes'][0].split(" "))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   947
        resp = cStringIO.StringIO()
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   948
        for b in self.repo.branches(nodes):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   949
            resp.write(" ".join(map(hex, b)) + "\n")
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   950
        resp = resp.getvalue()
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   951
        req.httphdr("application/mercurial-0.1", length=len(resp))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   952
        req.write(resp)
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   953
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   954
    def do_between(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   955
        if req.form.has_key('pairs'):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   956
            pairs = [map(bin, p.split("-"))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   957
                     for p in req.form['pairs'][0].split(" ")]
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   958
        resp = cStringIO.StringIO()
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   959
        for b in self.repo.between(pairs):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   960
            resp.write(" ".join(map(hex, b)) + "\n")
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   961
        resp = resp.getvalue()
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   962
        req.httphdr("application/mercurial-0.1", length=len(resp))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   963
        req.write(resp)
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   964
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   965
    def do_changegroup(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   966
        req.httphdr("application/mercurial-0.1")
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   967
        nodes = []
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   968
        if not self.allowpull:
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   969
            return
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   970
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   971
        if req.form.has_key('roots'):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   972
            nodes = map(bin, req.form['roots'][0].split(" "))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   973
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   974
        z = zlib.compressobj()
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   975
        f = self.repo.changegroup(nodes, 'serve')
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   976
        while 1:
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   977
            chunk = f.read(4096)
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   978
            if not chunk:
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   979
                break
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   980
            req.write(z.compress(chunk))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   981
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   982
        req.write(z.flush())
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   983
3444
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   984
    def do_changegroupsubset(self, req):
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   985
        req.httphdr("application/mercurial-0.1")
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   986
        bases = []
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   987
        heads = []
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   988
        if not self.allowpull:
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   989
            return
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   990
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   991
        if req.form.has_key('bases'):
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   992
            bases = [bin(x) for x in req.form['bases'][0].split(' ')]
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   993
        if req.form.has_key('heads'):
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   994
            heads = [bin(x) for x in req.form['heads'][0].split(' ')]
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   995
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   996
        z = zlib.compressobj()
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   997
        f = self.repo.changegroupsubset(bases, heads, 'serve')
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   998
        while 1:
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
   999
            chunk = f.read(4096)
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
  1000
            if not chunk:
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
  1001
                break
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
  1002
            req.write(z.compress(chunk))
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
  1003
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
  1004
        req.write(z.flush())
3505fcd5a231 Adding changegroupsubset and lookup to web protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents: 3427
diff changeset
  1005
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
  1006
    def do_archive(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
  1007
        type_ = req.form['type'][0]
3555
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
  1008
        allowed = self.configlist("web", "allow_archive")
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
  1009
        if (type_ in self.archives and (type_ in allowed or
3555
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
  1010
            self.configbool("web", "allow" + type_, False))):
4164
5c1e18bb804c hgweb: use the given revision in the name of the archive
Michael Gebetsroither <michael.geb@gmx.at>
parents: 4096
diff changeset
  1011
            self.archive(req, req.form['node'][0], type_)
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
  1012
            return
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
  1013
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
  1014
        req.write(self.t("error"))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
  1015
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
  1016
    def do_static(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
  1017
        fname = req.form['file'][0]
3555
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
  1018
        # a repo owner may set web.static in .hg/hgrc to get any file
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
  1019
        # readable by the user running the CGI script
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
  1020
        static = self.config("web", "static",
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
  1021
                             os.path.join(self.templatepath, "static"),
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
  1022
                             untrusted=False)
2514
419c42223bee Really fix http headers for web UI and issue 254.
Eric Hopper <hopper@omnifarious.org>
parents: 2509
diff changeset
  1023
        req.write(staticfile(static, fname, req)
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
  1024
                  or self.t("error", error="%r not found" % fname))
2442
c660691fb45d http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2436
diff changeset
  1025
c660691fb45d http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2436
diff changeset
  1026
    def do_capabilities(self, req):
3612
d1b16a746db6 Add allowed bundle types as argument to hgweb unbundle capability.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3611
diff changeset
  1027
        caps = ['lookup', 'changegroupsubset']
3555
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
  1028
        if self.configbool('server', 'uncompressed'):
4258
b11a2fb59cf5 revlog: simplify revlog version handling
Matt Mackall <mpm@selenic.com>
parents: 4250
diff changeset
  1029
            caps.append('stream=%d' % self.repo.changelog.version)
3612
d1b16a746db6 Add allowed bundle types as argument to hgweb unbundle capability.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3611
diff changeset
  1030
        # XXX: make configurable and/or share code with do_unbundle:
d1b16a746db6 Add allowed bundle types as argument to hgweb unbundle capability.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3611
diff changeset
  1031
        unbundleversions = ['HG10GZ', 'HG10BZ', 'HG10UN']
d1b16a746db6 Add allowed bundle types as argument to hgweb unbundle capability.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3611
diff changeset
  1032
        if unbundleversions:
d1b16a746db6 Add allowed bundle types as argument to hgweb unbundle capability.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3611
diff changeset
  1033
            caps.append('unbundle=%s' % ','.join(unbundleversions))
2621
5a5852a417b1 clone: disable stream support on server side by default.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2612
diff changeset
  1034
        resp = ' '.join(caps)
2442
c660691fb45d http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2436
diff changeset
  1035
        req.httphdr("application/mercurial-0.1", length=len(resp))
c660691fb45d http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2436
diff changeset
  1036
        req.write(resp)
c660691fb45d http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2436
diff changeset
  1037
2466
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1038
    def check_perm(self, req, op, default):
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1039
        '''check permission for operation based on user auth.
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1040
        return true if op allowed, else false.
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1041
        default is policy to use if no config given.'''
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1042
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1043
        user = req.env.get('REMOTE_USER')
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1044
3555
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
  1045
        deny = self.configlist('web', 'deny_' + op)
2466
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1046
        if deny and (not user or deny == ['*'] or user in deny):
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1047
            return False
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1048
3555
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
  1049
        allow = self.configlist('web', 'allow_' + op)
2466
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1050
        return (allow and (allow == ['*'] or user in allow)) or default
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1051
2464
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1052
    def do_unbundle(self, req):
2466
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1053
        def bail(response, headers={}):
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1054
            length = int(req.env['CONTENT_LENGTH'])
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1055
            for s in util.filechunkiter(req, limit=length):
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1056
                # drain incoming bundle, else client will not see
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1057
                # response when run outside cgi script
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1058
                pass
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1059
            req.httphdr("application/mercurial-0.1", headers=headers)
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1060
            req.write('0\n')
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1061
            req.write(response)
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1062
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1063
        # require ssl by default, auth info cannot be sniffed and
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1064
        # replayed
3555
881064004fd0 use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3499
diff changeset
  1065
        ssl_req = self.configbool('web', 'push_ssl', True)
2673
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2666
diff changeset
  1066
        if ssl_req:
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2666
diff changeset
  1067
            if not req.env.get('HTTPS'):
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2666
diff changeset
  1068
                bail(_('ssl required\n'))
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2666
diff changeset
  1069
                return
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2666
diff changeset
  1070
            proto = 'https'
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2666
diff changeset
  1071
        else:
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2666
diff changeset
  1072
            proto = 'http'
2466
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1073
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1074
        # do not allow push unless explicitly allowed
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1075
        if not self.check_perm(req, 'push', False):
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1076
            bail(_('push not authorized\n'),
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1077
                 headers={'status': '401 Unauthorized'})
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1078
            return
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1079
2464
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1080
        their_heads = req.form['heads'][0].split(' ')
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1081
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1082
        def check_heads():
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1083
            heads = map(hex, self.repo.heads())
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1084
            return their_heads == [hex('force')] or their_heads == heads
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1085
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1086
        # fail early if possible
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1087
        if not check_heads():
2466
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
  1088
            bail(_('unsynced changes\n'))
2464
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1089
            return
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1090
4227
f5b9edf3390b hgweb.unbundle: call req.httphdr only after the last possible call to bail
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4095
diff changeset
  1091
        req.httphdr("application/mercurial-0.1")
f5b9edf3390b hgweb.unbundle: call req.httphdr only after the last possible call to bail
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4095
diff changeset
  1092
2464
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1093
        # do not lock repo until all changegroup data is
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1094
        # streamed. save to temporary file.
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1095
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1096
        fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-')
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1097
        fp = os.fdopen(fd, 'wb+')
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1098
        try:
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1099
            length = int(req.env['CONTENT_LENGTH'])
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1100
            for s in util.filechunkiter(req, limit=length):
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1101
                fp.write(s)
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1102
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1103
            try:
4228
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1104
                lock = self.repo.lock()
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1105
                try:
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1106
                    if not check_heads():
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1107
                        req.write('0\n')
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1108
                        req.write(_('unsynced changes\n'))
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1109
                        return
2464
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1110
4228
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1111
                    fp.seek(0)
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1112
                    header = fp.read(6)
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1113
                    if not header.startswith("HG"):
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1114
                        # old client with uncompressed bundle
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1115
                        def generator(f):
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1116
                            yield header
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1117
                            for chunk in f:
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1118
                                yield chunk
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1119
                    elif not header.startswith("HG10"):
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1120
                        req.write("0\n")
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1121
                        req.write(_("unknown bundle version\n"))
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1122
                        return
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1123
                    elif header == "HG10GZ":
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1124
                        def generator(f):
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1125
                            zd = zlib.decompressobj()
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1126
                            for chunk in f:
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1127
                                yield zd.decompress(chunk)
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1128
                    elif header == "HG10BZ":
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1129
                        def generator(f):
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1130
                            zd = bz2.BZ2Decompressor()
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1131
                            zd.decompress("BZ")
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1132
                            for chunk in f:
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1133
                                yield zd.decompress(chunk)
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1134
                    elif header == "HG10UN":
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1135
                        def generator(f):
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1136
                            for chunk in f:
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1137
                                yield chunk
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1138
                    else:
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1139
                        req.write("0\n")
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1140
                        req.write(_("unknown bundle compression type\n"))
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1141
                        return
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1142
                    gen = generator(util.filechunkiter(fp, 4096))
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1143
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1144
                    # send addchangegroup output to client
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1145
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1146
                    old_stdout = sys.stdout
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1147
                    sys.stdout = cStringIO.StringIO()
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1148
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1149
                    try:
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1150
                        url = 'remote:%s:%s' % (proto,
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1151
                                                req.env.get('REMOTE_HOST', ''))
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1152
                        try:
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1153
                            ret = self.repo.addchangegroup(
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1154
                                        util.chunkbuffer(gen), 'serve', url)
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1155
                        except util.Abort, inst:
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1156
                            sys.stdout.write("abort: %s\n" % inst)
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1157
                            ret = 0
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1158
                    finally:
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1159
                        val = sys.stdout.getvalue()
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1160
                        sys.stdout = old_stdout
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1161
                    req.write('%d\n' % ret)
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1162
                    req.write(val)
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1163
                finally:
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1164
                    lock.release()
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1165
            except (OSError, IOError), inst:
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1166
                req.write('0\n')
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1167
                filename = getattr(inst, 'filename', '')
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1168
                # Don't send our filesystem layout to the client
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1169
                if filename.startswith(self.repo.root):
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1170
                    filename = filename[len(self.repo.root)+1:]
3610
44cd1eb72fd7 hgweb: introduce a new capability for sending a compressed bundle
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3606
diff changeset
  1171
                else:
4228
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1172
                    filename = ''
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1173
                error = getattr(inst, 'strerror', 'Unknown error')
c52b7176af94 hgweb: handle IOErrors and OSErrors during unbundle
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4227
diff changeset
  1174
                req.write('%s: %s\n' % (error, filename))
2464
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1175
        finally:
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1176
            fp.close()
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
  1177
            os.unlink(tempname)
2612
ffb895f16925 add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2580
diff changeset
  1178
ffb895f16925 add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2580
diff changeset
  1179
    def do_stream_out(self, req):
ffb895f16925 add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2580
diff changeset
  1180
        req.httphdr("application/mercurial-0.1")
4834
439e2f2fde42 Fix inconsistency for the stream_out capability in hgweb
Edouard Gomez <ed.gomez@free.fr>
parents: 4745
diff changeset
  1181
        streamclone.stream_out(self.repo, req, untrusted=True)