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