mercurial/hgweb/hgweb_mod.py
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
Mon, 03 Jul 2006 00:33:19 -0300
changeset 2558 1120302009d7
parent 2538 f4b7d71c1c60
child 2579 0875cda033fd
permissions -rw-r--r--
hgweb: fix unbundle. After the WSGI changes, even if a push over HTTP succeeds, apache complains about "Premature end of script headers: hgwebdir.cgi" and returns a "HTTP Error 500: Internal Server Error", making the local hg abort. The change to either of the files touched by this patch is enough to fix this, but I think changing both is a more robust solution.
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>
575
7f5ce4bbdd7b More whitespace cleanups
mpm@selenic.com
parents: 572
diff changeset
     4
# Copyright 2005 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
2356
2db831b33e8f Final stage of the hgweb split up.
Eric Hopper <hopper@omnifarious.org>
parents: 2355
diff changeset
     9
import os
2db831b33e8f Final stage of the hgweb split up.
Eric Hopper <hopper@omnifarious.org>
parents: 2355
diff changeset
    10
import os.path
1777
a2316878f19d [hgweb] Static content serving
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1703
diff changeset
    11
import mimetypes
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
    12
from mercurial.demandload import demandload
2514
419c42223bee Really fix http headers for web UI and issue 254.
Eric Hopper <hopper@omnifarious.org>
parents: 2509
diff changeset
    13
demandload(globals(), "re zlib ConfigParser mimetools cStringIO sys tempfile")
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
    14
demandload(globals(), "mercurial:mdiff,ui,hg,util,archival,templater")
2356
2db831b33e8f Final stage of the hgweb split up.
Eric Hopper <hopper@omnifarious.org>
parents: 2355
diff changeset
    15
demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile")
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
    16
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
    17
from mercurial.i18n import gettext as _
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    18
2356
2db831b33e8f Final stage of the hgweb split up.
Eric Hopper <hopper@omnifarious.org>
parents: 2355
diff changeset
    19
def _up(p):
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
    20
    if p[0] != "/":
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
    21
        p = "/" + p
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
    22
    if p[-1] == "/":
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
    23
        p = p[:-1]
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    24
    up = os.path.dirname(p)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    25
    if up == "/":
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    26
        return "/"
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    27
    return up + "/"
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    28
1559
59b3639df0a9 Convert all classes to new-style classes by deriving them from object.
Eric Hopper <hopper@omnifarious.org>
parents: 1554
diff changeset
    29
class hgweb(object):
987
bfe12654764d hgweb: change startup argument processing
mpm@selenic.com
parents: 986
diff changeset
    30
    def __init__(self, repo, name=None):
bfe12654764d hgweb: change startup argument processing
mpm@selenic.com
parents: 986
diff changeset
    31
        if type(repo) == type(""):
1213
db9639b8594c Clean up hgweb imports
mpm@selenic.com
parents: 1210
diff changeset
    32
            self.repo = hg.repository(ui.ui(), repo)
987
bfe12654764d hgweb: change startup argument processing
mpm@selenic.com
parents: 986
diff changeset
    33
        else:
bfe12654764d hgweb: change startup argument processing
mpm@selenic.com
parents: 986
diff changeset
    34
            self.repo = repo
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    35
258
268bcb5a072a hgweb: watch changelog for changes
mpm@selenic.com
parents: 241
diff changeset
    36
        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
    37
        self.reponame = name
1078
33f40d0c6124 Various cleanups for tarball support
mpm@selenic.com
parents: 1077
diff changeset
    38
        self.archives = 'zip', 'gz', 'bz2'
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
    39
        self.templatepath = self.repo.ui.config("web", "templates",
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
    40
                                                templater.templatepath())
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    41
258
268bcb5a072a hgweb: watch changelog for changes
mpm@selenic.com
parents: 241
diff changeset
    42
    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
    43
        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
    44
        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
    45
            self.mtime = mtime
1213
db9639b8594c Clean up hgweb imports
mpm@selenic.com
parents: 1210
diff changeset
    46
            self.repo = hg.repository(self.repo.ui, self.repo.root)
1275
a1a84dd489ff Fix cut and paste error in hgweb.py
Florian La Roche <laroche@redhat.com>
parents: 1260
diff changeset
    47
            self.maxchanges = int(self.repo.ui.config("web", "maxchanges", 10))
a1a84dd489ff Fix cut and paste error in hgweb.py
Florian La Roche <laroche@redhat.com>
parents: 1260
diff changeset
    48
            self.maxfiles = int(self.repo.ui.config("web", "maxfiles", 10))
964
3f37720e7dc7 hgweb: Make maxfiles, maxchanges, and allowpull proper config options
mpm@selenic.com
parents: 957
diff changeset
    49
            self.allowpull = self.repo.ui.configbool("web", "allowpull", True)
258
268bcb5a072a hgweb: watch changelog for changes
mpm@selenic.com
parents: 241
diff changeset
    50
1498
78590fb4a82b hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1473
diff changeset
    51
    def archivelist(self, nodeid):
2500
76ff5efe8181 Fixed [web] allow_archive for comma separated parameters by using ui.configlist.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2466
diff changeset
    52
        allowed = self.repo.ui.configlist("web", "allow_archive")
1498
78590fb4a82b hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1473
diff changeset
    53
        for i in self.archives:
2359
a392eaa81f29 Allow comma to separate types in allow_archive, too. Use longer variable name.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2358
diff changeset
    54
            if i in allowed or self.repo.ui.configbool("web", "allow" + i):
2171
290534ee163c Add download links to hgwebdir index page for allowed archive types.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2170
diff changeset
    55
                yield {"type" : i, "node" : nodeid, "url": ""}
1498
78590fb4a82b hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1473
diff changeset
    56
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    57
    def listfiles(self, files, mf):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    58
        for f in files[:self.maxfiles]:
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
    59
            yield self.t("filenodelink", node=hex(mf[f]), file=f)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    60
        if len(files) > self.maxfiles:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    61
            yield self.t("fileellipses")
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    62
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    63
    def listfilediffs(self, files, changeset):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    64
        for f in files[:self.maxfiles]:
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
    65
            yield self.t("filedifflink", node=hex(changeset), file=f)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    66
        if len(files) > self.maxfiles:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    67
            yield self.t("fileellipses")
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    68
1606
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
    69
    def siblings(self, siblings=[], rev=None, hiderev=None, **args):
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
    70
        if not rev:
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
    71
            rev = lambda x: ""
1606
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
    72
        siblings = [s for s in siblings if s != nullid]
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
    73
        if len(siblings) == 1 and rev(siblings[0]) == hiderev:
1416
19d2776f1725 hgweb: hide trivial parent (like in show_changeset)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1411
diff changeset
    74
            return
1606
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
    75
        for s in siblings:
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
    76
            yield dict(node=hex(s), rev=rev(s), **args)
569
3e347929f5f9 [PATCH 1/5]: cleaning the template parent management in hgweb
mpm@selenic.com
parents: 568
diff changeset
    77
1653
e8a3df8b62b3 hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents: 1650
diff changeset
    78
    def renamelink(self, fl, node):
e8a3df8b62b3 hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents: 1650
diff changeset
    79
        r = fl.renamed(node)
e8a3df8b62b3 hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents: 1650
diff changeset
    80
        if r:
e8a3df8b62b3 hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents: 1650
diff changeset
    81
            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
    82
        return []
e8a3df8b62b3 hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents: 1650
diff changeset
    83
568
e8fd41110dce [PATCH] Add tags to hgweb
mpm@selenic.com
parents: 547
diff changeset
    84
    def showtag(self, t1, node=nullid, **args):
e8fd41110dce [PATCH] Add tags to hgweb
mpm@selenic.com
parents: 547
diff changeset
    85
        for t in self.repo.nodetags(node):
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
    86
             yield self.t(t1, tag=t, **args)
568
e8fd41110dce [PATCH] Add tags to hgweb
mpm@selenic.com
parents: 547
diff changeset
    87
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    88
    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
    89
        def filterfiles(filters, files):
1627
11cd38286fdb fix for hgweb.filterfiles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1626
diff changeset
    90
            l = [x for x in files if x in filters]
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 391
diff changeset
    91
1626
f2b1df3dbcbb make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1619
diff changeset
    92
            for t in filters:
1627
11cd38286fdb fix for hgweb.filterfiles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1626
diff changeset
    93
                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
    94
                    t += os.sep
f2b1df3dbcbb make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1619
diff changeset
    95
                l += [x for x in files if x.startswith(t)]
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    96
            return l
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    97
172
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
    98
        parity = [0]
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
    99
        def diffblock(diff, f, fn):
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
   100
            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
   101
                         lines=prettyprintlines(diff),
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   102
                         parity=parity[0],
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   103
                         file=f,
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   104
                         filenode=hex(fn or nullid))
172
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
   105
            parity[0] = 1 - parity[0]
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 391
diff changeset
   106
172
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
   107
        def prettyprintlines(diff):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   108
            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
   109
                if l.startswith('+'):
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   110
                    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
   111
                elif l.startswith('-'):
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   112
                    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
   113
                elif l.startswith('@'):
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   114
                    yield self.t("difflineat", line=l)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   115
                else:
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   116
                    yield self.t("diffline", line=l)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   117
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   118
        r = self.repo
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   119
        cl = r.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   120
        mf = r.manifest
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   121
        change1 = cl.read(node1)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   122
        change2 = cl.read(node2)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   123
        mmap1 = mf.read(change1[0])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   124
        mmap2 = mf.read(change2[0])
1333
901c645c1943 hgweb: fix date bug in hgweb diff generation
mpm@selenic.com
parents: 1324
diff changeset
   125
        date1 = util.datestr(change1[2])
901c645c1943 hgweb: fix date bug in hgweb diff generation
mpm@selenic.com
parents: 1324
diff changeset
   126
        date2 = util.datestr(change2[2])
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   127
1619
1ba0d7041ac4 Distinguish removed and deleted files. Tests are not fixed yet.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1618
diff changeset
   128
        modified, added, removed, deleted, unknown = r.changes(node1, node2)
645
a55048b2ae3a this patch permits hgweb to show the deleted files in the changeset diff
kreijack@inwind.REMOVEME.it
parents: 635
diff changeset
   129
        if files:
1626
f2b1df3dbcbb make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1619
diff changeset
   130
            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
   131
                                           (modified, added, removed))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   132
1637
3b1b44b917f4 Add new bdiff based unidiff generation.
mason@suse.com
parents: 1627
diff changeset
   133
        diffopts = self.repo.ui.diffopts()
3b1b44b917f4 Add new bdiff based unidiff generation.
mason@suse.com
parents: 1627
diff changeset
   134
        showfunc = diffopts['showfunc']
3b1b44b917f4 Add new bdiff based unidiff generation.
mason@suse.com
parents: 1627
diff changeset
   135
        ignorews = diffopts['ignorews']
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
   136
        for f in modified:
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   137
            to = r.file(f).read(mmap1[f])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   138
            tn = r.file(f).read(mmap2[f])
1637
3b1b44b917f4 Add new bdiff based unidiff generation.
mason@suse.com
parents: 1627
diff changeset
   139
            yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
3b1b44b917f4 Add new bdiff based unidiff generation.
mason@suse.com
parents: 1627
diff changeset
   140
                            showfunc=showfunc, ignorews=ignorews), 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
   141
        for f in added:
265
7ca05593bd30 hgweb: fix non-existent source or destination for diff
mpm@selenic.com
parents: 258
diff changeset
   142
            to = None
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   143
            tn = r.file(f).read(mmap2[f])
1637
3b1b44b917f4 Add new bdiff based unidiff generation.
mason@suse.com
parents: 1627
diff changeset
   144
            yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
3b1b44b917f4 Add new bdiff based unidiff generation.
mason@suse.com
parents: 1627
diff changeset
   145
                            showfunc=showfunc, ignorews=ignorews), 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
   146
        for f in removed:
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   147
            to = r.file(f).read(mmap1[f])
265
7ca05593bd30 hgweb: fix non-existent source or destination for diff
mpm@selenic.com
parents: 258
diff changeset
   148
            tn = None
1637
3b1b44b917f4 Add new bdiff based unidiff generation.
mason@suse.com
parents: 1627
diff changeset
   149
            yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
3b1b44b917f4 Add new bdiff based unidiff generation.
mason@suse.com
parents: 1627
diff changeset
   150
                            showfunc=showfunc, ignorews=ignorews), f, tn)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   151
180
f25944662097 hgweb: Fix navigate to 0 bug
mpm@selenic.com
parents: 173
diff changeset
   152
    def changelog(self, pos):
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   153
        def changenav(**map):
1703
41d884f741ca fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents: 1653
diff changeset
   154
            def seq(factor, maxchanges=None):
41d884f741ca fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents: 1653
diff changeset
   155
                if maxchanges:
41d884f741ca fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents: 1653
diff changeset
   156
                    yield maxchanges
41d884f741ca fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents: 1653
diff changeset
   157
                    if maxchanges >= 20 and maxchanges <= 40:
41d884f741ca fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents: 1653
diff changeset
   158
                        yield 50
41d884f741ca fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents: 1653
diff changeset
   159
                else:
41d884f741ca fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents: 1653
diff changeset
   160
                    yield 1 * factor
41d884f741ca fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents: 1653
diff changeset
   161
                    yield 3 * factor
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   162
                for f in seq(factor * 10):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   163
                    yield f
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   164
173
8da1df932c16 hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents: 172
diff changeset
   165
            l = []
1703
41d884f741ca fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents: 1653
diff changeset
   166
            last = 0
41d884f741ca fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents: 1653
diff changeset
   167
            for f in seq(1, self.maxchanges):
41d884f741ca fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents: 1653
diff changeset
   168
                if f < self.maxchanges or f <= last:
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   169
                    continue
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   170
                if f > count:
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   171
                    break
1703
41d884f741ca fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents: 1653
diff changeset
   172
                last = f
173
8da1df932c16 hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents: 172
diff changeset
   173
                r = "%d" % f
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   174
                if pos + f < count:
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   175
                    l.append(("+" + r, pos + f))
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   176
                if pos - f >= 0:
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   177
                    l.insert(0, ("-" + r, pos - f))
173
8da1df932c16 hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents: 172
diff changeset
   178
975
bdd7c53fca00 hgweb: Changed changelog page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 974
diff changeset
   179
            yield {"rev": 0, "label": "(0)"}
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 391
diff changeset
   180
173
8da1df932c16 hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents: 172
diff changeset
   181
            for label, rev in l:
975
bdd7c53fca00 hgweb: Changed changelog page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 974
diff changeset
   182
                yield {"label": label, "rev": rev}
173
8da1df932c16 hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents: 172
diff changeset
   183
1409
964baa35faf8 hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents: 1407
diff changeset
   184
            yield {"label": "tip", "rev": "tip"}
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   185
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   186
        def changelist(**map):
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   187
            parity = (start - end) & 1
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   188
            cl = self.repo.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   189
            l = [] # build a list in forward order for efficiency
351
9525208e1c1d hgweb: change number navigation tidy up
mpm@selenic.com
parents: 350
diff changeset
   190
            for i in range(start, end):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   191
                n = cl.node(i)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   192
                changes = cl.read(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   193
                hn = hex(n)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   194
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   195
                l.insert(0, {"parity": parity,
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   196
                             "author": changes[1],
1606
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
   197
                             "parent": self.siblings(cl.parents(n), cl.rev,
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
   198
                                                     cl.rev(n) - 1),
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
   199
                             "child": self.siblings(cl.children(n), cl.rev,
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
   200
                                                    cl.rev(n) + 1),
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   201
                             "changelogtag": self.showtag("changelogtag",n),
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   202
                             "manifest": hex(changes[0]),
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   203
                             "desc": changes[4],
1324
77cd8068dbf4 hgweb: pass date tuples around rather than whole changesets for dates
mpm@selenic.com
parents: 1321
diff changeset
   204
                             "date": changes[2],
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   205
                             "files": self.listfilediffs(changes[3], n),
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   206
                             "rev": i,
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   207
                             "node": hn})
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   208
                parity = 1 - parity
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   209
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   210
            for e in l:
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   211
                yield e
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   212
168
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   213
        cl = self.repo.changelog
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   214
        mf = cl.read(cl.tip())[0]
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   215
        count = cl.count()
351
9525208e1c1d hgweb: change number navigation tidy up
mpm@selenic.com
parents: 350
diff changeset
   216
        start = max(0, pos - self.maxchanges + 1)
9525208e1c1d hgweb: change number navigation tidy up
mpm@selenic.com
parents: 350
diff changeset
   217
        end = min(count, start + self.maxchanges)
9525208e1c1d hgweb: change number navigation tidy up
mpm@selenic.com
parents: 350
diff changeset
   218
        pos = end - 1
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   219
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   220
        yield self.t('changelog',
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   221
                     changenav=changenav,
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   222
                     manifest=hex(mf),
2170
29eeb2717915 Add archive download links to tip on main changeset list page
Colin McMillen <mcmillen@cs.cmu.edu>
parents: 2148
diff changeset
   223
                     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
   224
                     archives=self.archivelist("tip"))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   225
538
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   226
    def search(self, query):
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   227
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   228
        def changelist(**map):
538
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   229
            cl = self.repo.changelog
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   230
            count = 0
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   231
            qw = query.lower().split()
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   232
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   233
            def revgen():
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   234
                for i in range(cl.count() - 1, 0, -100):
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   235
                    l = []
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   236
                    for j in range(max(0, i - 100), i):
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   237
                        n = cl.node(j)
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   238
                        changes = cl.read(n)
1023
bc806ba72959 Minor tweak to the revgen algorithm
mpm@selenic.com
parents: 1022
diff changeset
   239
                        l.append((n, j, changes))
bc806ba72959 Minor tweak to the revgen algorithm
mpm@selenic.com
parents: 1022
diff changeset
   240
                    l.reverse()
538
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   241
                    for e in l:
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   242
                        yield e
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   243
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   244
            for n, i, changes in revgen():
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   245
                miss = 0
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   246
                for q in qw:
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   247
                    if not (q in changes[1].lower() or
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   248
                            q in changes[4].lower() or
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   249
                            q in " ".join(changes[3][:20]).lower()):
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   250
                        miss = 1
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   251
                        break
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   252
                if miss:
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   253
                    continue
538
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   254
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   255
                count += 1
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   256
                hn = hex(n)
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   257
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   258
                yield self.t('searchentry',
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   259
                             parity=count & 1,
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   260
                             author=changes[1],
1606
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
   261
                             parent=self.siblings(cl.parents(n), cl.rev),
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
   262
                             child=self.siblings(cl.children(n), cl.rev),
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   263
                             changelogtag=self.showtag("changelogtag",n),
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   264
                             manifest=hex(changes[0]),
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   265
                             desc=changes[4],
1324
77cd8068dbf4 hgweb: pass date tuples around rather than whole changesets for dates
mpm@selenic.com
parents: 1321
diff changeset
   266
                             date=changes[2],
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   267
                             files=self.listfilediffs(changes[3], n),
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   268
                             rev=i,
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   269
                             node=hn)
538
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   270
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   271
                if count >= self.maxchanges:
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   272
                    break
538
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   273
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   274
        cl = self.repo.changelog
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   275
        mf = cl.read(cl.tip())[0]
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   276
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   277
        yield self.t('search',
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   278
                     query=query,
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   279
                     manifest=hex(mf),
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   280
                     entries=changelist)
538
7140bc781655 Add multiple keyword search to hgweb
mpm@selenic.com
parents: 536
diff changeset
   281
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   282
    def changeset(self, nodeid):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   283
        cl = self.repo.changelog
1369
b6d4ebebc35c Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1348
diff changeset
   284
        n = self.repo.lookup(nodeid)
b6d4ebebc35c Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1348
diff changeset
   285
        nodeid = hex(n)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   286
        changes = cl.read(n)
598
f8d44a2e6928 [PATCH 4/5]: cleaning the template parent management in hgweb
mpm@selenic.com
parents: 582
diff changeset
   287
        p1 = cl.parents(n)[0]
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 391
diff changeset
   288
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   289
        files = []
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   290
        mf = self.repo.manifest.read(changes[0])
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   291
        for f in changes[3]:
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   292
            files.append(self.t("filenodelink",
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   293
                                filenode=hex(mf.get(f, nullid)), file=f))
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   294
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   295
        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
   296
            yield self.diff(p1, n, None)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   297
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   298
        yield self.t('changeset',
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   299
                     diff=diff,
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   300
                     rev=cl.rev(n),
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   301
                     node=nodeid,
1606
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
   302
                     parent=self.siblings(cl.parents(n), cl.rev),
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
   303
                     child=self.siblings(cl.children(n), cl.rev),
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   304
                     changesettag=self.showtag("changesettag",n),
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   305
                     manifest=hex(changes[0]),
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   306
                     author=changes[1],
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   307
                     desc=changes[4],
1324
77cd8068dbf4 hgweb: pass date tuples around rather than whole changesets for dates
mpm@selenic.com
parents: 1321
diff changeset
   308
                     date=changes[2],
1076
01db658cc78a tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents: 1073
diff changeset
   309
                     files=files,
1498
78590fb4a82b hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1473
diff changeset
   310
                     archives=self.archivelist(nodeid))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   311
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   312
    def filelog(self, f, filenode):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   313
        cl = self.repo.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   314
        fl = self.repo.file(f)
1369
b6d4ebebc35c Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1348
diff changeset
   315
        filenode = hex(fl.lookup(filenode))
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   316
        count = fl.count()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   317
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   318
        def entries(**map):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   319
            l = []
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   320
            parity = (count - 1) & 1
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 391
diff changeset
   321
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   322
            for i in range(count):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   323
                n = fl.node(i)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   324
                lr = fl.linkrev(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   325
                cn = cl.node(lr)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   326
                cs = cl.read(cl.node(lr))
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   327
978
ea67e5b37043 hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 977
diff changeset
   328
                l.insert(0, {"parity": parity,
ea67e5b37043 hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 977
diff changeset
   329
                             "filenode": hex(n),
ea67e5b37043 hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 977
diff changeset
   330
                             "filerev": i,
ea67e5b37043 hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 977
diff changeset
   331
                             "file": f,
ea67e5b37043 hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 977
diff changeset
   332
                             "node": hex(cn),
ea67e5b37043 hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 977
diff changeset
   333
                             "author": cs[1],
1324
77cd8068dbf4 hgweb: pass date tuples around rather than whole changesets for dates
mpm@selenic.com
parents: 1321
diff changeset
   334
                             "date": cs[2],
1653
e8a3df8b62b3 hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents: 1650
diff changeset
   335
                             "rename": self.renamelink(fl, n),
1606
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
   336
                             "parent": self.siblings(fl.parents(n),
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
   337
                                                     fl.rev, file=f),
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
   338
                             "child": self.siblings(fl.children(n),
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   339
                                                    fl.rev, file=f),
978
ea67e5b37043 hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 977
diff changeset
   340
                             "desc": cs[4]})
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   341
                parity = 1 - parity
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   342
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   343
            for e in l:
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   344
                yield e
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   345
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   346
        yield self.t("filelog", file=f, filenode=filenode, entries=entries)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   347
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   348
    def filerevision(self, f, node):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   349
        fl = self.repo.file(f)
1369
b6d4ebebc35c Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1348
diff changeset
   350
        n = fl.lookup(node)
b6d4ebebc35c Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1348
diff changeset
   351
        node = hex(n)
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   352
        text = fl.read(n)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   353
        changerev = fl.linkrev(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   354
        cl = self.repo.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   355
        cn = cl.node(changerev)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   356
        cs = cl.read(cn)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   357
        mfn = cs[0]
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   358
1411
e2ba788545bf hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1409
diff changeset
   359
        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
   360
        rawtext = text
e2ba788545bf hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1409
diff changeset
   361
        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
   362
            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
   363
            text = "(binary:%s)" % mt
2095
0bf2a9e5eff1 Don't send "Content-Type: none"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 1964
diff changeset
   364
        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
   365
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   366
        def lines():
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   367
            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
   368
                yield {"line": t,
5d5ab159d197 hgweb: Changed file page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 975
diff changeset
   369
                       "linenumber": "% 6d" % (l + 1),
5d5ab159d197 hgweb: Changed file page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 975
diff changeset
   370
                       "parity": l & 1}
359
0c4688e9ee5c hgweb: add file permissions
mpm@selenic.com
parents: 351
diff changeset
   371
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   372
        yield self.t("filerevision",
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   373
                     file=f,
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   374
                     filenode=node,
2356
2db831b33e8f Final stage of the hgweb split up.
Eric Hopper <hopper@omnifarious.org>
parents: 2355
diff changeset
   375
                     path=_up(f),
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   376
                     text=lines(),
1411
e2ba788545bf hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1409
diff changeset
   377
                     raw=rawtext,
e2ba788545bf hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1409
diff changeset
   378
                     mimetype=mt,
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   379
                     rev=changerev,
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   380
                     node=hex(cn),
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   381
                     manifest=hex(mfn),
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   382
                     author=cs[1],
1324
77cd8068dbf4 hgweb: pass date tuples around rather than whole changesets for dates
mpm@selenic.com
parents: 1321
diff changeset
   383
                     date=cs[2],
1606
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
   384
                     parent=self.siblings(fl.parents(n), fl.rev, file=f),
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
   385
                     child=self.siblings(fl.children(n), fl.rev, file=f),
1653
e8a3df8b62b3 hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents: 1650
diff changeset
   386
                     rename=self.renamelink(fl, n),
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   387
                     permissions=self.repo.manifest.readflags(mfn)[f])
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   388
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   389
    def fileannotate(self, f, node):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   390
        bcache = {}
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   391
        ncache = {}
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   392
        fl = self.repo.file(f)
1369
b6d4ebebc35c Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1348
diff changeset
   393
        n = fl.lookup(node)
b6d4ebebc35c Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1348
diff changeset
   394
        node = hex(n)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   395
        changerev = fl.linkrev(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   396
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   397
        cl = self.repo.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   398
        cn = cl.node(changerev)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   399
        cs = cl.read(cn)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   400
        mfn = cs[0]
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   401
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   402
        def annotate(**map):
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   403
            parity = 1
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   404
            last = None
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   405
            for r, l in fl.annotate(n):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   406
                try:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   407
                    cnode = ncache[r]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   408
                except KeyError:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   409
                    cnode = ncache[r] = self.repo.changelog.node(r)
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 391
diff changeset
   410
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   411
                try:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   412
                    name = bcache[r]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   413
                except KeyError:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   414
                    cl = self.repo.changelog.read(cnode)
1129
ee4f60abad93 Move generating short username to display in hg/hgweb annotate to ui module.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1123
diff changeset
   415
                    bcache[r] = name = self.repo.ui.shortuser(cl[1])
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   416
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   417
                if last != cnode:
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   418
                    parity = 1 - parity
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   419
                    last = cnode
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   420
977
289975641886 hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 976
diff changeset
   421
                yield {"parity": parity,
289975641886 hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 976
diff changeset
   422
                       "node": hex(cnode),
289975641886 hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 976
diff changeset
   423
                       "rev": r,
289975641886 hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 976
diff changeset
   424
                       "author": name,
289975641886 hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 976
diff changeset
   425
                       "file": f,
289975641886 hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 976
diff changeset
   426
                       "line": l}
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   427
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   428
        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
   429
                     file=f,
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   430
                     filenode=node,
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   431
                     annotate=annotate,
2356
2db831b33e8f Final stage of the hgweb split up.
Eric Hopper <hopper@omnifarious.org>
parents: 2355
diff changeset
   432
                     path=_up(f),
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   433
                     rev=changerev,
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   434
                     node=hex(cn),
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   435
                     manifest=hex(mfn),
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   436
                     author=cs[1],
1324
77cd8068dbf4 hgweb: pass date tuples around rather than whole changesets for dates
mpm@selenic.com
parents: 1321
diff changeset
   437
                     date=cs[2],
1653
e8a3df8b62b3 hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents: 1650
diff changeset
   438
                     rename=self.renamelink(fl, n),
1606
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
   439
                     parent=self.siblings(fl.parents(n), fl.rev, file=f),
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
   440
                     child=self.siblings(fl.children(n), fl.rev, file=f),
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   441
                     permissions=self.repo.manifest.readflags(mfn)[f])
136
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   442
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   443
    def manifest(self, mnode, path):
1369
b6d4ebebc35c Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1348
diff changeset
   444
        man = self.repo.manifest
b6d4ebebc35c Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1348
diff changeset
   445
        mn = man.lookup(mnode)
b6d4ebebc35c Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1348
diff changeset
   446
        mnode = hex(mn)
b6d4ebebc35c Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1348
diff changeset
   447
        mf = man.read(mn)
b6d4ebebc35c Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1348
diff changeset
   448
        rev = man.rev(mn)
2328
f789602ba840 hgweb.manifest: revno of manifest and changelog aren't always the same
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2311
diff changeset
   449
        changerev = man.linkrev(mn)
f789602ba840 hgweb.manifest: revno of manifest and changelog aren't always the same
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2311
diff changeset
   450
        node = self.repo.changelog.node(changerev)
1369
b6d4ebebc35c Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1348
diff changeset
   451
        mff = man.readflags(mn)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   452
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   453
        files = {}
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 391
diff changeset
   454
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   455
        p = path[1:]
1649
beb7da710c8a hgweb: fix breakage on manifest subdirs from path cleaning
Matt Mackall <mpm@selenic.com>
parents: 1646
diff changeset
   456
        if p and p[-1] != "/":
beb7da710c8a hgweb: fix breakage on manifest subdirs from path cleaning
Matt Mackall <mpm@selenic.com>
parents: 1646
diff changeset
   457
            p += "/"
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   458
        l = len(p)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   459
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   460
        for f,n in mf.items():
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   461
            if f[:l] != p:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   462
                continue
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   463
            remain = f[l:]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   464
            if "/" in remain:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   465
                short = remain[:remain.find("/") + 1] # bleah
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   466
                files[short] = (f, None)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   467
            else:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   468
                short = os.path.basename(remain)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   469
                files[short] = (f, n)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   470
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   471
        def filelist(**map):
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   472
            parity = 0
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   473
            fl = files.keys()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   474
            fl.sort()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   475
            for f in fl:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   476
                full, fnode = files[f]
979
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   477
                if not fnode:
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   478
                    continue
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   479
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   480
                yield {"file": full,
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   481
                       "manifest": mnode,
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   482
                       "filenode": hex(fnode),
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   483
                       "parity": parity,
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   484
                       "basename": f,
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   485
                       "permissions": mff[full]}
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   486
                parity = 1 - parity
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   487
979
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   488
        def dirlist(**map):
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   489
            parity = 0
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   490
            fl = files.keys()
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   491
            fl.sort()
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   492
            for f in fl:
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   493
                full, fnode = files[f]
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   494
                if fnode:
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   495
                    continue
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   496
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   497
                yield {"parity": parity,
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   498
                       "path": os.path.join(path, f),
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   499
                       "manifest": mnode,
980
5197fb9d65d5 Merge with MPM
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 979 939
diff changeset
   500
                       "basename": f[:-1]}
979
87d40e085e08 hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 978
diff changeset
   501
                parity = 1 - parity
982
8d2e24bae760 hgweb: convert index entries to list expansion style
mpm@selenic.com
parents: 981
diff changeset
   502
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   503
        yield self.t("manifest",
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   504
                     manifest=mnode,
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   505
                     rev=rev,
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   506
                     node=hex(node),
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   507
                     path=path,
2356
2db831b33e8f Final stage of the hgweb split up.
Eric Hopper <hopper@omnifarious.org>
parents: 2355
diff changeset
   508
                     up=_up(path),
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   509
                     fentries=filelist,
1498
78590fb4a82b hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1473
diff changeset
   510
                     dentries=dirlist,
78590fb4a82b hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1473
diff changeset
   511
                     archives=self.archivelist(hex(node)))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   512
168
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   513
    def tags(self):
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   514
        cl = self.repo.changelog
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   515
        mf = cl.read(cl.tip())[0]
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   516
343
d7df759d0e97 rework all code using tags
mpm@selenic.com
parents: 330
diff changeset
   517
        i = self.repo.tagslist()
d7df759d0e97 rework all code using tags
mpm@selenic.com
parents: 330
diff changeset
   518
        i.reverse()
168
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   519
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
   520
        def entries(notip=False, **map):
168
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   521
            parity = 0
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   522
            for k,n in i:
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
                if notip and k == "tip": continue
974
aedb47764f29 Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 938
diff changeset
   524
                yield {"parity": parity,
aedb47764f29 Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 938
diff changeset
   525
                       "tag": k,
1579
85803ec2daab Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1575
diff changeset
   526
                       "tagmanifest": hex(cl.read(n)[0]),
85803ec2daab Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1575
diff changeset
   527
                       "date": cl.read(n)[2],
974
aedb47764f29 Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 938
diff changeset
   528
                       "node": hex(n)}
168
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   529
                parity = 1 - parity
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   530
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   531
        yield self.t("tags",
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   532
                     manifest=hex(mf),
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
   533
                     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
   534
                     entriesnotip=lambda **x: entries(True, **x))
168
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   535
1572
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   536
    def summary(self):
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   537
        cl = self.repo.changelog
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   538
        mf = cl.read(cl.tip())[0]
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   539
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   540
        i = self.repo.tagslist()
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   541
        i.reverse()
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   542
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   543
        def tagentries(**map):
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   544
            parity = 0
1579
85803ec2daab Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1575
diff changeset
   545
            count = 0
1572
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   546
            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
   547
                if k == "tip": # skip tip
1572
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   548
                    continue;
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   549
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   550
                count += 1
1579
85803ec2daab Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1575
diff changeset
   551
                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
   552
                    break;
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   553
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   554
                c = cl.read(n)
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   555
                m = c[0]
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   556
                t = c[2]
1579
85803ec2daab Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1575
diff changeset
   557
1572
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   558
                yield self.t("tagentry",
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   559
                             parity = parity,
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   560
                             tag = k,
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   561
                             node = hex(n),
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   562
                             date = t,
1575
0a1cca912fda [hgweb] gitweb style: File annotate converted, file revision made more like the deafault style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1574
diff changeset
   563
                             tagmanifest = hex(m))
1572
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   564
                parity = 1 - parity
1579
85803ec2daab Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1575
diff changeset
   565
1572
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   566
        def changelist(**map):
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   567
            parity = 0
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   568
            cl = self.repo.changelog
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   569
            l = [] # build a list in forward order for efficiency
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   570
            for i in range(start, end):
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   571
                n = cl.node(i)
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   572
                changes = cl.read(n)
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   573
                hn = hex(n)
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   574
                t = changes[2]
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   575
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   576
                l.insert(0, self.t(
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   577
                    'shortlogentry',
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   578
                    parity = parity,
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   579
                    author = changes[1],
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   580
                    manifest = hex(changes[0]),
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   581
                    desc = changes[4],
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   582
                    date = t,
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   583
                    rev = i,
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   584
                    node = hn))
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   585
                parity = 1 - parity
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   586
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   587
            yield l
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
        cl = self.repo.changelog
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   590
        mf = cl.read(cl.tip())[0]
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   591
        count = cl.count()
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   592
        start = max(0, count - self.maxchanges)
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   593
        end = min(count, start + self.maxchanges)
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   594
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   595
        yield self.t("summary",
1579
85803ec2daab Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1575
diff changeset
   596
                 desc = self.repo.ui.config("web", "description", "unknown"),
85803ec2daab Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1575
diff changeset
   597
                 owner = (self.repo.ui.config("ui", "username") or # preferred
1572
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   598
                          self.repo.ui.config("web", "contact") or # deprecated
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   599
                          self.repo.ui.config("web", "author", "unknown")), # also
1579
85803ec2daab Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1575
diff changeset
   600
                 lastchange = (0, 0), # FIXME
1572
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   601
                 manifest = hex(mf),
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   602
                 tags = tagentries,
385b8872b8e3 [hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1559
diff changeset
   603
                 shortlog = changelist)
1579
85803ec2daab Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1575
diff changeset
   604
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   605
    def filediff(self, file, changeset):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   606
        cl = self.repo.changelog
1369
b6d4ebebc35c Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1348
diff changeset
   607
        n = self.repo.lookup(changeset)
b6d4ebebc35c Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents: 1348
diff changeset
   608
        changeset = hex(n)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   609
        p1 = cl.parents(n)[0]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   610
        cs = cl.read(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   611
        mf = self.repo.manifest.read(cs[0])
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 391
diff changeset
   612
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   613
        def diff(**map):
2275
714f4d25a7a9 Fix hgweb.filediff
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2174
diff changeset
   614
            yield self.diff(p1, n, [file])
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   615
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   616
        yield self.t("filediff",
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   617
                     file=file,
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   618
                     filenode=hex(mf.get(file, nullid)),
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   619
                     node=changeset,
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   620
                     rev=self.repo.changelog.rev(n),
1606
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
   621
                     parent=self.siblings(cl.parents(n), cl.rev),
ba625c8083d8 - duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents: 1579
diff changeset
   622
                     child=self.siblings(cl.children(n), cl.rev),
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   623
                     diff=diff)
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 391
diff changeset
   624
2113
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   625
    archive_specs = {
2361
d3adb454c5a9 Fix automatic decompression of tarballs with Firefox.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2359
diff changeset
   626
        '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
   627
        '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
   628
        'zip': ('application/zip', 'zip', '.zip', None),
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   629
        }
1076
01db658cc78a tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents: 1073
diff changeset
   630
2394
a8f1049d1d2d hgweb: fix errors and warnings found by pychecker
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2391
diff changeset
   631
    def archive(self, req, cnode, type_):
2113
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   632
        reponame = re.sub(r"\W+", "-", os.path.basename(self.reponame))
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   633
        name = "%s-%s" % (reponame, short(cnode))
2394
a8f1049d1d2d hgweb: fix errors and warnings found by pychecker
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2391
diff changeset
   634
        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
   635
        headers = [('Content-type', mimetype),
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   636
                   ('Content-disposition', 'attachment; filename=%s%s' %
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   637
                    (name, extension))]
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   638
        if encoding:
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   639
            headers.append(('Content-encoding', encoding))
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   640
        req.header(headers)
633d733e7b11 make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2103
diff changeset
   641
        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
   642
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   643
    # add tags to things
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   644
    # tags -> list of changesets corresponding to tags
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   645
    # find tag, changeset, file
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   646
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   647
    def cleanpath(self, path):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   648
        p = util.normpath(path)
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   649
        if p[:2] == "..":
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   650
            raise Exception("suspicious path")
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   651
        return p
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   652
2535
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2534
diff changeset
   653
    def run(self):
2538
f4b7d71c1c60 Cleanup hgweb and hgwebdir's run method a bit.
Eric Hopper <hopper@omnifarious.org>
parents: 2535
diff changeset
   654
        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
   655
            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
   656
        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
   657
        from request import wsgiapplication
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2534
diff changeset
   658
        def make_web_app():
2538
f4b7d71c1c60 Cleanup hgweb and hgwebdir's run method a bit.
Eric Hopper <hopper@omnifarious.org>
parents: 2535
diff changeset
   659
            return self
2535
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2534
diff changeset
   660
        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
   661
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2534
diff changeset
   662
    def run_wsgi(self, req):
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   663
        def header(**map):
2514
419c42223bee Really fix http headers for web UI and issue 254.
Eric Hopper <hopper@omnifarious.org>
parents: 2509
diff changeset
   664
            header_file = cStringIO.StringIO(''.join(self.t("header", **map)))
419c42223bee Really fix http headers for web UI and issue 254.
Eric Hopper <hopper@omnifarious.org>
parents: 2509
diff changeset
   665
            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
   666
            req.header(msg.items())
419c42223bee Really fix http headers for web UI and issue 254.
Eric Hopper <hopper@omnifarious.org>
parents: 2509
diff changeset
   667
            yield header_file.read()
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   668
2534
d5a3cc6520d5 Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
   669
        def rawfileheader(**map):
d5a3cc6520d5 Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
   670
            req.header([('Content-type', map['mimetype']),
d5a3cc6520d5 Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
   671
                        ('Content-disposition', 'filename=%s' % map['file']),
d5a3cc6520d5 Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
   672
                        ('Content-length', str(len(map['raw'])))])
d5a3cc6520d5 Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
   673
            yield ''
d5a3cc6520d5 Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
   674
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   675
        def footer(**map):
2148
c72e618c1204 Add MOTD display to hgweb and hgwebdir.
Colin McMillen <mcmillen@cs.cmu.edu>
parents: 2127
diff changeset
   676
            yield self.t("footer",
c72e618c1204 Add MOTD display to hgweb and hgwebdir.
Colin McMillen <mcmillen@cs.cmu.edu>
parents: 2127
diff changeset
   677
                         motd=self.repo.ui.config("web", "motd", ""),
c72e618c1204 Add MOTD display to hgweb and hgwebdir.
Colin McMillen <mcmillen@cs.cmu.edu>
parents: 2127
diff changeset
   678
                         **map)
1409
964baa35faf8 hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents: 1407
diff changeset
   679
1406
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   680
        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
   681
            shortcuts = {
1409
964baa35faf8 hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents: 1407
diff changeset
   682
                'cl': [('cmd', ['changelog']), ('rev', None)],
1406
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   683
                '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
   684
                '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
   685
                '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
   686
                '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
   687
                '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
   688
                '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
   689
                '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
   690
                '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
   691
                'tip': [('cmd', ['changeset']), ('node', ['tip'])],
1777
a2316878f19d [hgweb] Static content serving
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents: 1703
diff changeset
   692
                '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
   693
            }
1409
964baa35faf8 hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents: 1407
diff changeset
   694
1406
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   695
            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
   696
                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
   697
                    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
   698
                        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
   699
                            value = form[k]
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   700
                        form[name] = value
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   701
                    del form[k]
857
41b344235bb7 [PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents: 839
diff changeset
   702
258
268bcb5a072a hgweb: watch changelog for changes
mpm@selenic.com
parents: 241
diff changeset
   703
        self.refresh()
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   704
1406
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   705
        expand_form(req.form)
34cb3957d875 hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
   706
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   707
        m = os.path.join(self.templatepath, "map")
986
2810c625ca98 Add web:style option
mpm@selenic.com
parents: 984
diff changeset
   708
        style = self.repo.ui.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
   709
        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
   710
            style = req.form['style'][0]
986
2810c625ca98 Add web:style option
mpm@selenic.com
parents: 984
diff changeset
   711
        if style:
2810c625ca98 Add web:style option
mpm@selenic.com
parents: 984
diff changeset
   712
            b = os.path.basename("map-" + style)
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   713
            p = os.path.join(self.templatepath, b)
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   714
            if os.path.isfile(p):
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   715
                m = p
515
03f27b1381f9 Whitespace cleanups
mpm@selenic.com
parents: 391
diff changeset
   716
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
   717
        port = req.env["SERVER_PORT"]
601
8865eb8ade99 Add globals to templater/fixup RSS
mpm@selenic.com
parents: 600
diff changeset
   718
        port = port != "80" and (":" + port) or ""
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
   719
        uri = req.env["REQUEST_URI"]
1063
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   720
        if "?" in uri:
58eefdfb8472 Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1062
diff changeset
   721
            uri = uri.split("?")[0]
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
   722
        url = "http://%s%s%s" % (req.env["SERVER_NAME"], port, uri)
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
   723
        if not self.reponame:
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
   724
            self.reponame = (self.repo.ui.config("web", "name")
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
   725
                             or uri.strip('/') or self.repo.root)
601
8865eb8ade99 Add globals to templater/fixup RSS
mpm@selenic.com
parents: 600
diff changeset
   726
1896
f8f818a04f5b move hgweb template code out to templater
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1796
diff changeset
   727
        self.t = templater.templater(m, templater.common_filters,
1964
778281d46bb2 fix template bug that made hgweb break.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1920
diff changeset
   728
                                     defaults={"url": url,
778281d46bb2 fix template bug that made hgweb break.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1920
diff changeset
   729
                                               "repo": self.reponame,
778281d46bb2 fix template bug that made hgweb break.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1920
diff changeset
   730
                                               "header": header,
778281d46bb2 fix template bug that made hgweb break.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1920
diff changeset
   731
                                               "footer": footer,
2534
d5a3cc6520d5 Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
   732
                                               "rawfileheader": rawfileheader,
1964
778281d46bb2 fix template bug that made hgweb break.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1920
diff changeset
   733
                                               })
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   734
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
   735
        if not req.form.has_key('cmd'):
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
   736
            req.form['cmd'] = [self.t.cache['default'],]
937
e4f1b76831b2 Whitespace
mpm@selenic.com
parents: 896
diff changeset
   737
2119
f62195054c5b Cleaned hgweb.py a little bit
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2113
diff changeset
   738
        cmd = req.form['cmd'][0]
575
7f5ce4bbdd7b More whitespace cleanups
mpm@selenic.com
parents: 572
diff changeset
   739
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   740
        method = getattr(self, 'do_' + cmd, None)
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   741
        if method:
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   742
            method(req)
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   743
        else:
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
   744
            req.write(self.t("error"))
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   745
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   746
    def do_changelog(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   747
        hi = self.repo.changelog.count() - 1
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   748
        if req.form.has_key('rev'):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   749
            hi = req.form['rev'][0]
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   750
            try:
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   751
                hi = self.repo.changelog.rev(self.repo.lookup(hi))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   752
            except hg.RepoError:
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   753
                req.write(self.search(hi)) # XXX redirect to 404 page?
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   754
                return
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   755
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   756
        req.write(self.changelog(hi))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   757
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   758
    def do_changeset(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   759
        req.write(self.changeset(req.form['node'][0]))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   760
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   761
    def do_manifest(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   762
        req.write(self.manifest(req.form['manifest'][0],
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   763
                                self.cleanpath(req.form['path'][0])))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   764
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   765
    def do_tags(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   766
        req.write(self.tags())
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   767
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   768
    def do_summary(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   769
        req.write(self.summary())
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   770
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   771
    def do_filediff(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   772
        req.write(self.filediff(self.cleanpath(req.form['file'][0]),
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   773
                                req.form['node'][0]))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   774
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   775
    def do_file(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   776
        req.write(self.filerevision(self.cleanpath(req.form['file'][0]),
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   777
                                    req.form['filenode'][0]))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   778
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   779
    def do_annotate(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   780
        req.write(self.fileannotate(self.cleanpath(req.form['file'][0]),
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   781
                                    req.form['filenode'][0]))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   782
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   783
    def do_filelog(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   784
        req.write(self.filelog(self.cleanpath(req.form['file'][0]),
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   785
                               req.form['filenode'][0]))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   786
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   787
    def do_heads(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   788
        resp = " ".join(map(hex, self.repo.heads())) + "\n"
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   789
        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
   790
        req.write(resp)
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   791
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   792
    def do_branches(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   793
        nodes = []
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   794
        if req.form.has_key('nodes'):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   795
            nodes = map(bin, req.form['nodes'][0].split(" "))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   796
        resp = cStringIO.StringIO()
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   797
        for b in self.repo.branches(nodes):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   798
            resp.write(" ".join(map(hex, b)) + "\n")
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   799
        resp = resp.getvalue()
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   800
        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
   801
        req.write(resp)
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   802
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   803
    def do_between(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   804
        nodes = []
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   805
        if req.form.has_key('pairs'):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   806
            pairs = [map(bin, p.split("-"))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   807
                     for p in req.form['pairs'][0].split(" ")]
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   808
        resp = cStringIO.StringIO()
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   809
        for b in self.repo.between(pairs):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   810
            resp.write(" ".join(map(hex, b)) + "\n")
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   811
        resp = resp.getvalue()
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   812
        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
   813
        req.write(resp)
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   814
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   815
    def do_changegroup(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   816
        req.httphdr("application/mercurial-0.1")
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   817
        nodes = []
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   818
        if not self.allowpull:
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   819
            return
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   820
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   821
        if req.form.has_key('roots'):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   822
            nodes = map(bin, req.form['roots'][0].split(" "))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   823
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   824
        z = zlib.compressobj()
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   825
        f = self.repo.changegroup(nodes, 'serve')
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   826
        while 1:
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   827
            chunk = f.read(4096)
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   828
            if not chunk:
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   829
                break
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   830
            req.write(z.compress(chunk))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   831
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   832
        req.write(z.flush())
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   833
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   834
    def do_archive(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   835
        changeset = self.repo.lookup(req.form['node'][0])
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   836
        type_ = req.form['type'][0]
2500
76ff5efe8181 Fixed [web] allow_archive for comma separated parameters by using ui.configlist.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2466
diff changeset
   837
        allowed = self.repo.ui.configlist("web", "allow_archive")
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   838
        if (type_ in self.archives and (type_ in allowed or
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   839
            self.repo.ui.configbool("web", "allow" + type_, False))):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   840
            self.archive(req, changeset, type_)
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   841
            return
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   842
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   843
        req.write(self.t("error"))
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   844
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   845
    def do_static(self, req):
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   846
        fname = req.form['file'][0]
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   847
        static = self.repo.ui.config("web", "static",
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   848
                                     os.path.join(self.templatepath,
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   849
                                                  "static"))
2514
419c42223bee Really fix http headers for web UI and issue 254.
Eric Hopper <hopper@omnifarious.org>
parents: 2509
diff changeset
   850
        req.write(staticfile(static, fname, req)
2436
f910b91dd912 hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2434
diff changeset
   851
                  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
   852
c660691fb45d http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2436
diff changeset
   853
    def do_capabilities(self, req):
2464
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   854
        resp = 'unbundle'
2442
c660691fb45d http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2436
diff changeset
   855
        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
   856
        req.write(resp)
c660691fb45d http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2436
diff changeset
   857
2466
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   858
    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
   859
        '''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
   860
        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
   861
        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
   862
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   863
        user = req.env.get('REMOTE_USER')
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   864
2501
b73552a00b20 Make "[web] allow_push, deny_push" and "[http_proxy] no" use ui.configlist.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2500
diff changeset
   865
        deny = self.repo.ui.configlist('web', 'deny_' + op)
2466
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   866
        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
   867
            return False
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   868
2501
b73552a00b20 Make "[web] allow_push, deny_push" and "[http_proxy] no" use ui.configlist.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2500
diff changeset
   869
        allow = self.repo.ui.configlist('web', 'allow_' + op)
2466
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   870
        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
   871
2464
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   872
    def do_unbundle(self, req):
2466
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   873
        def bail(response, headers={}):
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   874
            length = int(req.env['CONTENT_LENGTH'])
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   875
            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
   876
                # 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
   877
                # response when run outside cgi script
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   878
                pass
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   879
            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
   880
            req.write('0\n')
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   881
            req.write(response)
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   882
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   883
        # 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
   884
        # replayed
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   885
        ssl_req = self.repo.ui.configbool('web', 'push_ssl', True)
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   886
        if ssl_req and not req.env.get('HTTPS'):
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   887
            bail(_('ssl required\n'))
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   888
            return
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   889
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   890
        # 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
   891
        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
   892
            bail(_('push not authorized\n'),
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   893
                 headers={'status': '401 Unauthorized'})
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   894
            return
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   895
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   896
        req.httphdr("application/mercurial-0.1")
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   897
2464
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   898
        their_heads = req.form['heads'][0].split(' ')
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   899
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   900
        def check_heads():
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   901
            heads = map(hex, self.repo.heads())
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   902
            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
   903
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   904
        # fail early if possible
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   905
        if not check_heads():
2466
e10665147d26 push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2464
diff changeset
   906
            bail(_('unsynced changes\n'))
2464
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   907
            return
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   908
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   909
        # 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
   910
        # streamed. save to temporary file.
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   911
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   912
        fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-')
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   913
        fp = os.fdopen(fd, 'wb+')
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   914
        try:
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   915
            length = int(req.env['CONTENT_LENGTH'])
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   916
            for s in util.filechunkiter(req, limit=length):
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   917
                fp.write(s)
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   918
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   919
            lock = self.repo.lock()
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   920
            try:
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   921
                if not check_heads():
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   922
                    req.write('0\n')
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   923
                    req.write(_('unsynced changes\n'))
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   924
                    return
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   925
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   926
                fp.seek(0)
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   927
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   928
                # send addchangegroup output to client
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   929
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   930
                old_stdout = sys.stdout
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   931
                sys.stdout = cStringIO.StringIO()
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   932
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   933
                try:
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   934
                    ret = self.repo.addchangegroup(fp, 'serve')
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   935
                finally:
2558
1120302009d7 hgweb: fix unbundle.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2538
diff changeset
   936
                    val = sys.stdout.getvalue()
2464
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   937
                    sys.stdout = old_stdout
2558
1120302009d7 hgweb: fix unbundle.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2538
diff changeset
   938
                req.write('%d\n' % ret)
1120302009d7 hgweb: fix unbundle.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2538
diff changeset
   939
                req.write(val)
2464
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   940
            finally:
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   941
                lock.release()
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   942
        finally:
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   943
            fp.close()
09b1c9ef317c push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2442
diff changeset
   944
            os.unlink(tempname)