mercurial/hgweb.py
author mpm@selenic.com
Sat, 04 Jun 2005 18:34:35 -0800
changeset 254 c03f58e5fd2d
parent 241 afe895fcc0d0
child 258 268bcb5a072a
permissions -rw-r--r--
unify checkout and resolve into update -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 unify checkout and resolve into update This replaces checkout and resolve with a single command: $ hg help co hg update [node] update or merge working directory If there are no outstanding changes in the working directory and there is a linear relationship between the current version and the requested version, the result is the requested version. Otherwise the result is a merge between the contents of the current working directory and the requested version. Files that changed between either parent are marked as changed for the next commit and a commit must be performed before any further updates are allowed. manifest hash: 513d285d7fb775d0560de49387042a685ea062f7 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFComS7ywK+sNU5EO8RAmgRAJ96GA6qvHLy0Jp0fzUrR2os2azPuACePsdC YBldZtA7yIuTnV2vIbn7OSE= =QtM/ -----END PGP SIGNATURE-----
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
238
3b92f8fe47ae hgweb.py: kill #! line, clean up copyright notice
mpm@selenic.com
parents: 222
diff changeset
     1
# hgweb.py - web interface to a mercurial 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>
3b92f8fe47ae hgweb.py: kill #! line, clean up copyright notice
mpm@selenic.com
parents: 222
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
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
     9
# useful for debugging
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    10
import cgitb
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    11
cgitb.enable()
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    12
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    13
import os, cgi, time, re, difflib, sys, zlib
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    14
from mercurial.hg import *
215
9ff5a78d0c45 hgweb: import ui
mpm@selenic.com
parents: 201
diff changeset
    15
from mercurial.ui import *
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    16
157
2653740d8118 Install the templates where they can be found by hgweb.py
mpm@selenic.com
parents: 156
diff changeset
    17
def templatepath():
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
    18
    for f in "templates", "../templates":
157
2653740d8118 Install the templates where they can be found by hgweb.py
mpm@selenic.com
parents: 156
diff changeset
    19
        p = os.path.join(os.path.dirname(__file__), f)
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
    20
        if os.path.isdir(p): return p
157
2653740d8118 Install the templates where they can be found by hgweb.py
mpm@selenic.com
parents: 156
diff changeset
    21
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    22
def age(t):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    23
    def plural(t, c):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    24
        if c == 1: return t
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    25
        return t + "s"
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    26
    def fmt(t, c):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    27
        return "%d %s" % (c, plural(t, c))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    28
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    29
    now = time.time()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    30
    delta = max(1, int(now - t))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    31
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    32
    scales = [["second", 1],
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    33
              ["minute", 60],
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    34
              ["hour", 3600],
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    35
              ["day", 3600 * 24],
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    36
              ["week", 3600 * 24 * 7],
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    37
              ["month", 3600 * 24 * 30],
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    38
              ["year", 3600 * 24 * 365]]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    39
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    40
    scales.reverse()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    41
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    42
    for t, s in scales:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    43
        n = delta / s
195
b98bcf66dd9d hgweb: make age() smarter
mpm@selenic.com
parents: 183
diff changeset
    44
        if n >= 2 or s == 1: return fmt(t, n)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    45
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    46
def nl2br(text):
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
    47
    return text.replace('\n', '<br/>\n')
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    48
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    49
def obfuscate(text):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    50
    return ''.join([ '&#%d' % ord(c) for c in text ])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    51
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    52
def up(p):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    53
    if p[0] != "/": p = "/" + p
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    54
    if p[-1] == "/": p = p[:-1]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    55
    up = os.path.dirname(p)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    56
    if up == "/":
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    57
        return "/"
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    58
    return up + "/"
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    59
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    60
def httphdr(type):
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    61
    print 'Content-type: %s\n' % type
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    62
135
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    63
def write(*things):
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    64
    for thing in things:
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    65
        if hasattr(thing, "__iter__"):
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    66
            for part in thing:
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    67
                write(part)
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    68
        else:
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    69
            sys.stdout.write(str(thing))
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    70
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
    71
def template(tmpl, filters = {}, **map):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    72
    while tmpl:
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
    73
        m = re.search(r"#([a-zA-Z0-9]+)((\|[a-zA-Z0-9]+)*)#", tmpl)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    74
        if m:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    75
            yield tmpl[:m.start(0)]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    76
            v = map.get(m.group(1), "")
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
    77
            v = callable(v) and v() or v
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
    78
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
    79
            fl = m.group(2)
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
    80
            if fl:
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
    81
                for f in fl.split("|")[1:]:
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
    82
                    v = filters[f](v)
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
    83
                
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
    84
            yield v
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    85
            tmpl = tmpl[m.end(0):]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    86
        else:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    87
            yield tmpl
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    88
            return
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    89
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    90
class templater:
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
    91
    def __init__(self, mapfile, filters = {}):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    92
        self.cache = {}
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    93
        self.map = {}
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    94
        self.base = os.path.dirname(mapfile)
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
    95
        self.filters = filters
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    96
        
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    97
        for l in file(mapfile):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    98
            m = re.match(r'(\S+)\s*=\s*"(.*)"$', l)
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    99
            if m:
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   100
                self.cache[m.group(1)] = m.group(2)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   101
            else:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   102
                m = re.match(r'(\S+)\s*=\s*(\S+)', l)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   103
                if m:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   104
                    self.map[m.group(1)] = os.path.join(self.base, m.group(2))
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   105
                else:
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   106
                    raise "unknown map entry '%s'"  % l
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   107
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   108
    def __call__(self, t, **map):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   109
        try:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   110
            tmpl = self.cache[t]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   111
        except KeyError:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   112
            tmpl = self.cache[t] = file(self.map[t]).read()
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   113
        return template(tmpl, self.filters, **map)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   114
        
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   115
class hgweb:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   116
    maxchanges = 20
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   117
    maxfiles = 10
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   118
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   119
    def __init__(self, path, name, templates = ""):
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   120
        self.templates = templates or templatepath()
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   121
        self.reponame = name
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   122
        self.repo = repository(ui(), path)
197
b388603984fc hgweb: add view-only support
mpm@selenic.com
parents: 195
diff changeset
   123
        self.viewonly = 0
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   124
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   125
        self.filters = {
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   126
            "escape": cgi.escape,
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   127
            "age": age,
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   128
            "date": (lambda x: time.asctime(time.gmtime(x))),
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   129
            "addbreaks": nl2br,
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   130
            "obfuscate": obfuscate,
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   131
            "firstline": (lambda x: x.splitlines(1)[0]),
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   132
            }
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   133
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   134
    def date(self, cs):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   135
        return time.asctime(time.gmtime(float(cs[2].split(' ')[0])))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   136
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   137
    def listfiles(self, files, mf):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   138
        for f in files[:self.maxfiles]:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   139
            yield self.t("filenodelink", node = hex(mf[f]), file = f)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   140
        if len(files) > self.maxfiles:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   141
            yield self.t("fileellipses")
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   142
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   143
    def listfilediffs(self, files, changeset):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   144
        for f in files[:self.maxfiles]:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   145
            yield self.t("filedifflink", node = hex(changeset), file = f)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   146
        if len(files) > self.maxfiles:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   147
            yield self.t("fileellipses")
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   148
156
32ce2c5d4d25 Fix some broken parent links in hgweb
mpm@selenic.com
parents: 155
diff changeset
   149
    def parent(self, t1, node=nullid, rev=-1, **args):
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   150
        if node != hex(nullid):
156
32ce2c5d4d25 Fix some broken parent links in hgweb
mpm@selenic.com
parents: 155
diff changeset
   151
            yield self.t(t1, node = node, rev = rev, **args)
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   152
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   153
    def diff(self, node1, node2, files):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   154
        def filterfiles(list, files):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   155
            l = [ x for x in list if x in files ]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   156
            
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   157
            for f in files:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   158
                if f[-1] != os.sep: f += os.sep
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   159
                l += [ x for x in list if x.startswith(f) ]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   160
            return l
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   161
172
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
   162
        parity = [0]
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
   163
        def diffblock(diff, f, fn):
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
   164
            yield self.t("diffblock",
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
   165
                         lines = prettyprintlines(diff),
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
   166
                         parity = parity[0],
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
   167
                         file = f,
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
   168
                         filenode = hex(fn))
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
   169
            parity[0] = 1 - parity[0]
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
   170
            
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
   171
        def prettyprintlines(diff):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   172
            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
   173
                if l.startswith('+'):
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   174
                    yield self.t("difflineplus", line = l)
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   175
                elif l.startswith('-'):
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   176
                    yield self.t("difflineminus", line = l)
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   177
                elif l.startswith('@'):
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   178
                    yield self.t("difflineat", line = l)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   179
                else:
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   180
                    yield self.t("diffline", line = l)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   181
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   182
        r = self.repo
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   183
        cl = r.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   184
        mf = r.manifest
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   185
        change1 = cl.read(node1)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   186
        change2 = cl.read(node2)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   187
        mmap1 = mf.read(change1[0])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   188
        mmap2 = mf.read(change2[0])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   189
        date1 = self.date(change1)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   190
        date2 = self.date(change2)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   191
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   192
        c, a, d = r.diffrevs(node1, node2)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   193
        c, a, d = map(lambda x: filterfiles(x, files), (c, a, d))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   194
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   195
        for f in c:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   196
            to = r.file(f).read(mmap1[f])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   197
            tn = r.file(f).read(mmap2[f])
172
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
   198
            yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   199
        for f in a:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   200
            to = ""
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   201
            tn = r.file(f).read(mmap2[f])
172
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
   202
            yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   203
        for f in d:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   204
            to = r.file(f).read(mmap1[f])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   205
            tn = ""
172
e9b1147db448 hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents: 168
diff changeset
   206
            yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   207
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   208
    def header(self):
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   209
        yield self.t("header", repo = self.reponame)
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   210
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   211
    def footer(self):
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   212
        yield self.t("footer", repo = self.reponame)
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   213
180
f25944662097 hgweb: Fix navigate to 0 bug
mpm@selenic.com
parents: 173
diff changeset
   214
    def changelog(self, pos):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   215
        def changenav():
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   216
            def seq(factor = 1):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   217
                yield 1 * factor
173
8da1df932c16 hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents: 172
diff changeset
   218
                yield 3 * factor
8da1df932c16 hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents: 172
diff changeset
   219
                #yield 5 * factor
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   220
                for f in seq(factor * 10):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   221
                    yield f
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   222
173
8da1df932c16 hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents: 172
diff changeset
   223
            l = []
8da1df932c16 hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents: 172
diff changeset
   224
            for f in seq():
8da1df932c16 hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents: 172
diff changeset
   225
                if f < self.maxchanges / 2: continue
8da1df932c16 hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents: 172
diff changeset
   226
                if f > count: break
8da1df932c16 hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents: 172
diff changeset
   227
                r = "%d" % f
8da1df932c16 hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents: 172
diff changeset
   228
                if pos + f < count - (f/2): l.append(("+" + r, pos + f))
8da1df932c16 hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents: 172
diff changeset
   229
                if pos - f >= 0 + (f/2): l.insert(0, ("-" + r, pos - f))
8da1df932c16 hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents: 172
diff changeset
   230
8da1df932c16 hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents: 172
diff changeset
   231
            yield self.t("naventry", rev = 0, label="(0)")
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   232
                    
173
8da1df932c16 hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents: 172
diff changeset
   233
            for label, rev in l:
8da1df932c16 hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents: 172
diff changeset
   234
                yield self.t("naventry", label = label, rev = rev)
8da1df932c16 hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents: 172
diff changeset
   235
198
c88ef31fb5c0 hgweb: fix tip so that it doesn't need refreshing
mpm@selenic.com
parents: 197
diff changeset
   236
            yield self.t("naventry", label="tip")
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   237
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   238
        def changelist():
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   239
            parity = (start - end) & 1
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   240
            cl = self.repo.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   241
            l = [] # build a list in forward order for efficiency
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   242
            for i in range(start, end + 1):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   243
                n = cl.node(i)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   244
                changes = cl.read(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   245
                hn = hex(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   246
                p1, p2 = cl.parents(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   247
                t = float(changes[2].split(' ')[0])
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   248
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   249
                l.insert(0, self.t(
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   250
                    'changelogentry',
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   251
                    parity = parity,
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   252
                    author = changes[1],
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   253
                    parent1 = self.parent("changelogparent",
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   254
                                          hex(p1), cl.rev(p1)),
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   255
                    parent2 = self.parent("changelogparent",
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   256
                                          hex(p2), cl.rev(p2)),
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   257
                    p1 = hex(p1), p2 = hex(p2),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   258
                    p1rev = cl.rev(p1), p2rev = cl.rev(p2),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   259
                    manifest = hex(changes[0]),
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   260
                    desc = changes[4],
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   261
                    date = t,
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   262
                    files = self.listfilediffs(changes[3], n),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   263
                    rev = i,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   264
                    node = hn))
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   265
                parity = 1 - parity
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   266
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   267
            yield l
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   268
168
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   269
        cl = self.repo.changelog
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   270
        mf = cl.read(cl.tip())[0]
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   271
        count = cl.count()
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   272
        end = min(pos, count - 1)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   273
        start = max(0, pos - self.maxchanges)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   274
        end = min(count - 1, start + self.maxchanges)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   275
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   276
        yield self.t('changelog',
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   277
                     header = self.header(),
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   278
                     footer = self.footer(),
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   279
                     repo = self.reponame,
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   280
                     changenav = changenav,
168
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   281
                     manifest = hex(mf),
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   282
                     rev = pos, changesets = count, entries = changelist)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   283
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   284
    def changeset(self, nodeid):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   285
        n = bin(nodeid)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   286
        cl = self.repo.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   287
        changes = cl.read(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   288
        p1, p2 = cl.parents(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   289
        p1rev, p2rev = cl.rev(p1), cl.rev(p2)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   290
        t = float(changes[2].split(' ')[0])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   291
        
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   292
        files = []
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   293
        mf = self.repo.manifest.read(changes[0])
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   294
        for f in changes[3]:
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   295
            files.append(self.t("filenodelink",
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   296
                                filenode = hex(mf[f]), file = f))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   297
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   298
        def diff():
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   299
            yield self.diff(p1, n, changes[3])
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   300
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   301
        yield self.t('changeset',
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   302
                     header = self.header(),
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   303
                     footer = self.footer(),
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   304
                     repo = self.reponame,
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   305
                     diff = diff,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   306
                     rev = cl.rev(n),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   307
                     node = nodeid,
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   308
                     parent1 = self.parent("changesetparent",
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   309
                                           hex(p1), cl.rev(p1)),
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   310
                     parent2 = self.parent("changesetparent",
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   311
                                           hex(p2), cl.rev(p2)),
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   312
                     p1 = hex(p1), p2 = hex(p2),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   313
                     p1rev = cl.rev(p1), p2rev = cl.rev(p2),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   314
                     manifest = hex(changes[0]),
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   315
                     author = changes[1],
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   316
                     desc = changes[4],
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   317
                     date = t,
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   318
                     files = files)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   319
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   320
    def filelog(self, f, filenode):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   321
        cl = self.repo.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   322
        fl = self.repo.file(f)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   323
        count = fl.count()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   324
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   325
        def entries():
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   326
            l = []
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   327
            parity = (count - 1) & 1
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   328
            
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   329
            for i in range(count):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   330
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   331
                n = fl.node(i)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   332
                lr = fl.linkrev(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   333
                cn = cl.node(lr)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   334
                cs = cl.read(cl.node(lr))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   335
                p1, p2 = fl.parents(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   336
                t = float(cs[2].split(' ')[0])
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   337
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   338
                l.insert(0, self.t("filelogentry",
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   339
                                   parity = parity,
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   340
                                   filenode = hex(n),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   341
                                   filerev = i,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   342
                                   file = f,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   343
                                   node = hex(cn),
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   344
                                   author = cs[1],
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   345
                                   date = t,
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   346
                                   desc = cs[4],
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   347
                                   p1 = hex(p1), p2 = hex(p2),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   348
                                   p1rev = fl.rev(p1), p2rev = fl.rev(p2)))
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   349
                parity = 1 - parity
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   350
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   351
            yield l
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   352
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   353
        yield self.t("filelog",
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   354
                     header = self.header(),
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   355
                     footer = self.footer(),
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   356
                     repo = self.reponame,
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   357
                     file = f,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   358
                     filenode = filenode,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   359
                     entries = entries)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   360
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   361
    def filerevision(self, f, node):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   362
        fl = self.repo.file(f)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   363
        n = bin(node)
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   364
        text = fl.read(n)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   365
        changerev = fl.linkrev(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   366
        cl = self.repo.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   367
        cn = cl.node(changerev)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   368
        cs = cl.read(cn)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   369
        p1, p2 = fl.parents(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   370
        t = float(cs[2].split(' ')[0])
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
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   373
        def lines():
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   374
            for l, t in enumerate(text.splitlines(1)):
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   375
                yield self.t("fileline", line = t,
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   376
                             linenumber = "% 6d" % (l + 1),
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   377
                             parity = l & 1)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   378
        
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   379
        yield self.t("filerevision", file = f,
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   380
                     header = self.header(),
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   381
                     footer = self.footer(),
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   382
                     repo = self.reponame,
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   383
                     filenode = node,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   384
                     path = up(f),
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   385
                     text = lines(),
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   386
                     rev = changerev,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   387
                     node = hex(cn),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   388
                     manifest = hex(mfn),
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   389
                     author = cs[1],
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   390
                     date = t,
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   391
                     parent1 = self.parent("filerevparent",
156
32ce2c5d4d25 Fix some broken parent links in hgweb
mpm@selenic.com
parents: 155
diff changeset
   392
                                           hex(p1), fl.rev(p1), file=f),
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   393
                     parent2 = self.parent("filerevparent",
156
32ce2c5d4d25 Fix some broken parent links in hgweb
mpm@selenic.com
parents: 155
diff changeset
   394
                                           hex(p2), fl.rev(p2), file=f),
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   395
                     p1 = hex(p1), p2 = hex(p2),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   396
                     p1rev = fl.rev(p1), p2rev = fl.rev(p2))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   397
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   398
    def fileannotate(self, f, node):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   399
        bcache = {}
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   400
        ncache = {}
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   401
        fl = self.repo.file(f)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   402
        n = bin(node)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   403
        changerev = fl.linkrev(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   404
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   405
        cl = self.repo.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   406
        cn = cl.node(changerev)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   407
        cs = cl.read(cn)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   408
        p1, p2 = fl.parents(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   409
        t = float(cs[2].split(' ')[0])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   410
        mfn = cs[0]
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   411
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   412
        def annotate():
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   413
            parity = 1
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   414
            last = None
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   415
            for r, l in fl.annotate(n):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   416
                try:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   417
                    cnode = ncache[r]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   418
                except KeyError:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   419
                    cnode = ncache[r] = self.repo.changelog.node(r)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   420
                    
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   421
                try:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   422
                    name = bcache[r]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   423
                except KeyError:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   424
                    cl = self.repo.changelog.read(cnode)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   425
                    name = cl[1]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   426
                    f = name.find('@')
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   427
                    if f >= 0:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   428
                        name = name[:f]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   429
                    bcache[r] = name
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
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   435
                yield self.t("annotateline",
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   436
                             parity = parity,
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   437
                             node = hex(cnode),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   438
                             rev = r,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   439
                             author = name,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   440
                             file = f,
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   441
                             line = l)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   442
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   443
        yield self.t("fileannotate",
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   444
                     header = self.header(),
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   445
                     footer = self.footer(),
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   446
                     repo = self.reponame,
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   447
                     file = f,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   448
                     filenode = node,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   449
                     annotate = annotate,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   450
                     path = up(f),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   451
                     rev = changerev,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   452
                     node = hex(cn),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   453
                     manifest = hex(mfn),
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   454
                     author = cs[1],
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   455
                     date = t,
156
32ce2c5d4d25 Fix some broken parent links in hgweb
mpm@selenic.com
parents: 155
diff changeset
   456
                     parent1 = self.parent("fileannotateparent",
32ce2c5d4d25 Fix some broken parent links in hgweb
mpm@selenic.com
parents: 155
diff changeset
   457
                                           hex(p1), fl.rev(p1), file=f),
32ce2c5d4d25 Fix some broken parent links in hgweb
mpm@selenic.com
parents: 155
diff changeset
   458
                     parent2 = self.parent("fileannotateparent",
32ce2c5d4d25 Fix some broken parent links in hgweb
mpm@selenic.com
parents: 155
diff changeset
   459
                                           hex(p2), fl.rev(p2), file=f),
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   460
                     p1 = hex(p1), p2 = hex(p2),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   461
                     p1rev = fl.rev(p1), p2rev = fl.rev(p2))
136
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   462
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   463
    def manifest(self, mnode, path):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   464
        mf = self.repo.manifest.read(bin(mnode))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   465
        rev = self.repo.manifest.rev(bin(mnode))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   466
        node = self.repo.changelog.node(rev)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   467
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   468
        files = {}
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   469
 
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   470
        p = path[1:]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   471
        l = len(p)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   472
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   473
        for f,n in mf.items():
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   474
            if f[:l] != p:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   475
                continue
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   476
            remain = f[l:]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   477
            if "/" in remain:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   478
                short = remain[:remain.find("/") + 1] # bleah
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   479
                files[short] = (f, None)
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   480
            else:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   481
                short = os.path.basename(remain)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   482
                files[short] = (f, n)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   483
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   484
        def filelist():
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   485
            parity = 0
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   486
            fl = files.keys()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   487
            fl.sort()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   488
            for f in fl:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   489
                full, fnode = files[f]
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   490
                if fnode:
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   491
                    yield self.t("manifestfileentry",
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   492
                                 file = full,
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   493
                                 manifest = mnode,
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   494
                                 filenode = hex(fnode),
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   495
                                 parity = parity,
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   496
                                 basename = f)
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   497
                else:
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   498
                    yield self.t("manifestdirentry",
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   499
                                 parity = parity,
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   500
                                 path = os.path.join(path, f),
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   501
                                 manifest = mnode, basename = f[:-1])
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   502
                parity = 1 - parity
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   503
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   504
        yield self.t("manifest",
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   505
                     header = self.header(),
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   506
                     footer = self.footer(),
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   507
                     repo = self.reponame,
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   508
                     manifest = mnode,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   509
                     rev = rev,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   510
                     node = hex(node),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   511
                     path = path,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   512
                     up = up(path),
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   513
                     entries = filelist)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   514
168
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   515
    def tags(self):
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   516
        cl = self.repo.changelog
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   517
        mf = cl.read(cl.tip())[0]
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   518
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   519
        self.repo.lookup(0) # prime the cache
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   520
        i = self.repo.tags.items()
183
767916673e16 hgweb: Sort tags by revision number
mpm@selenic.com
parents: 182
diff changeset
   521
        n = [ (cl.rev(e[1]), e) for e in i ] # sort by revision
767916673e16 hgweb: Sort tags by revision number
mpm@selenic.com
parents: 182
diff changeset
   522
        n.sort()
767916673e16 hgweb: Sort tags by revision number
mpm@selenic.com
parents: 182
diff changeset
   523
        n.reverse()
767916673e16 hgweb: Sort tags by revision number
mpm@selenic.com
parents: 182
diff changeset
   524
        i = [ e[1] for e in n ]
168
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   525
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   526
        def entries():
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   527
            parity = 0
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   528
            for k,n in i:
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   529
                yield self.t("tagentry",
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   530
                             parity = parity,
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   531
                             tag = k,
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   532
                             node = hex(n))
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   533
                parity = 1 - parity
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   534
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   535
        yield self.t("tags",
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   536
                     header = self.header(),
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   537
                     footer = self.footer(),
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   538
                     repo = self.reponame,
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   539
                     manifest = hex(mf),
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   540
                     entries = entries)
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   541
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   542
    def filediff(self, file, changeset):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   543
        n = bin(changeset)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   544
        cl = self.repo.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   545
        p1 = cl.parents(n)[0]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   546
        cs = cl.read(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   547
        mf = self.repo.manifest.read(cs[0])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   548
        
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   549
        def diff():
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   550
            yield self.diff(p1, n, file)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   551
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   552
        yield self.t("filediff",
142
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   553
                     header = self.header(),
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   554
                     footer = self.footer(),
529bf610092e Prettify the web interface
mpm@selenic.com
parents: 138
diff changeset
   555
                     repo = self.reponame,
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   556
                     file = file,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   557
                     filenode = hex(mf[file]),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   558
                     node = changeset,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   559
                     rev = self.repo.changelog.rev(n),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   560
                     p1 = hex(p1),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   561
                     p1rev = self.repo.changelog.rev(p1),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   562
                     diff = diff)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   563
                     
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   564
    # add tags to things
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   565
    # tags -> list of changesets corresponding to tags
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   566
    # find tag, changeset, file
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   567
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   568
    def run(self):
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   569
        args = cgi.parse()
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   570
201
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   571
        m = os.path.join(self.templates, "map")
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   572
        if args.has_key('style'):
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   573
            b = os.path.basename("map-" + args['style'][0])
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   574
            p = os.path.join(self.templates, b)
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   575
            if os.path.isfile(p): m = p
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   576
            
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   577
        self.t = templater(m, self.filters)
f918a6fa2572 hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents: 198
diff changeset
   578
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   579
        if not args.has_key('cmd') or args['cmd'][0] == 'changelog':
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   580
            hi = self.repo.changelog.count()
153
e8a360cd5a9f changed pos to rev for changelog cmd, changed & to ;
jake@edge2.net
parents: 142
diff changeset
   581
            if args.has_key('rev'):
165
7fc8385df514 Add tag/rev/node search to hgweb
mpm@selenic.com
parents: 158
diff changeset
   582
                hi = args['rev'][0]
166
39624c47060f hgweb: don't blow up on search for unknown keys
mpm@selenic.com
parents: 165
diff changeset
   583
                try:
39624c47060f hgweb: don't blow up on search for unknown keys
mpm@selenic.com
parents: 165
diff changeset
   584
                    hi = self.repo.changelog.rev(self.repo.lookup(hi))
39624c47060f hgweb: don't blow up on search for unknown keys
mpm@selenic.com
parents: 165
diff changeset
   585
                except KeyError:
39624c47060f hgweb: don't blow up on search for unknown keys
mpm@selenic.com
parents: 165
diff changeset
   586
                    hi = self.repo.changelog.count()
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   587
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   588
            write(self.changelog(hi))
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   589
            
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   590
        elif args['cmd'][0] == 'changeset':
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   591
            write(self.changeset(args['node'][0]))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   592
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   593
        elif args['cmd'][0] == 'manifest':
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   594
            write(self.manifest(args['manifest'][0], args['path'][0]))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   595
168
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   596
        elif args['cmd'][0] == 'tags':
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   597
            write(self.tags())
65cf1b0cfe86 hgweb: add tags links and manifest links
mpm@selenic.com
parents: 166
diff changeset
   598
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   599
        elif args['cmd'][0] == 'filediff':
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   600
            write(self.filediff(args['file'][0], args['node'][0]))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   601
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   602
        elif args['cmd'][0] == 'file':
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   603
            write(self.filerevision(args['file'][0], args['filenode'][0]))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   604
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   605
        elif args['cmd'][0] == 'annotate':
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   606
            write(self.fileannotate(args['file'][0], args['filenode'][0]))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   607
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   608
        elif args['cmd'][0] == 'filelog':
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   609
            write(self.filelog(args['file'][0], args['filenode'][0]))
136
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   610
222
87484f627422 make pull work for multiple heads
mpm@selenic.com
parents: 215
diff changeset
   611
        elif args['cmd'][0] == 'heads':
87484f627422 make pull work for multiple heads
mpm@selenic.com
parents: 215
diff changeset
   612
            httphdr("text/plain")
87484f627422 make pull work for multiple heads
mpm@selenic.com
parents: 215
diff changeset
   613
            h = self.repo.heads()
87484f627422 make pull work for multiple heads
mpm@selenic.com
parents: 215
diff changeset
   614
            sys.stdout.write(" ".join(map(hex, h)) + "\n")
87484f627422 make pull work for multiple heads
mpm@selenic.com
parents: 215
diff changeset
   615
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   616
        elif args['cmd'][0] == 'branches':
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   617
            httphdr("text/plain")
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   618
            nodes = []
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   619
            if args.has_key('nodes'):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   620
                nodes = map(bin, args['nodes'][0].split(" "))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   621
            for b in self.repo.branches(nodes):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   622
                sys.stdout.write(" ".join(map(hex, b)) + "\n")
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   623
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   624
        elif args['cmd'][0] == 'between':
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   625
            httphdr("text/plain")
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   626
            nodes = []
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   627
            if args.has_key('pairs'):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   628
                pairs = [ map(bin, p.split("-"))
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   629
                          for p in args['pairs'][0].split(" ") ]
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   630
            for b in self.repo.between(pairs):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   631
                sys.stdout.write(" ".join(map(hex, b)) + "\n")
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   632
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   633
        elif args['cmd'][0] == 'changegroup':
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   634
            httphdr("application/hg-changegroup")
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   635
            nodes = []
197
b388603984fc hgweb: add view-only support
mpm@selenic.com
parents: 195
diff changeset
   636
            if self.viewonly:
b388603984fc hgweb: add view-only support
mpm@selenic.com
parents: 195
diff changeset
   637
                return
b388603984fc hgweb: add view-only support
mpm@selenic.com
parents: 195
diff changeset
   638
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   639
            if args.has_key('roots'):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   640
                nodes = map(bin, args['roots'][0].split(" "))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   641
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   642
            z = zlib.compressobj()
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   643
            for chunk in self.repo.changegroup(nodes):
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   644
                sys.stdout.write(z.compress(chunk))
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   645
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   646
            sys.stdout.write(z.flush())
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   647
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   648
        else:
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   649
            write(self.t("error"))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   650
158
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   651
def server(path, name, templates, address, port):
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   652
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   653
    import BaseHTTPServer
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   654
    import sys, os
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   655
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   656
    class hgwebhandler(BaseHTTPServer.BaseHTTPRequestHandler):
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   657
        def do_POST(self):
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   658
            self.do_hgweb()
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   659
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   660
        def do_GET(self):
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   661
            self.do_hgweb()
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   662
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   663
        def do_hgweb(self):
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   664
            query = ""
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   665
            p = self.path.find("?")
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   666
            if p:
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   667
                query = self.path[p + 1:]
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   668
                query = query.replace('+', ' ')
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   669
        
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   670
            env = {}
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   671
            env['GATEWAY_INTERFACE'] = 'CGI/1.1'
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   672
            env['REQUEST_METHOD'] = self.command
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   673
            if query:
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   674
                env['QUERY_STRING'] = query
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   675
            host = self.address_string()
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   676
            if host != self.client_address[0]:
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   677
                env['REMOTE_HOST'] = host
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   678
                env['REMOTE_ADDR'] = self.client_address[0]
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   679
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   680
            if self.headers.typeheader is None:
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   681
                env['CONTENT_TYPE'] = self.headers.type
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   682
            else:
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   683
                env['CONTENT_TYPE'] = self.headers.typeheader
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   684
            length = self.headers.getheader('content-length')
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   685
            if length:
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   686
                env['CONTENT_LENGTH'] = length
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   687
            accept = []
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   688
            for line in self.headers.getallmatchingheaders('accept'):
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   689
                if line[:1] in "\t\n\r ":
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   690
                    accept.append(line.strip())
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   691
                else:
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   692
                    accept = accept + line[7:].split(',')
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   693
            env['HTTP_ACCEPT'] = ','.join(accept)
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   694
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   695
            os.environ.update(env)
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   696
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   697
            save = sys.argv, sys.stdin, sys.stdout, sys.stderr
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   698
            try:
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   699
                sys.stdin = self.rfile
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   700
                sys.stdout = self.wfile
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   701
                sys.argv = ["hgweb.py"]
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   702
                if '=' not in query:
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   703
                    sys.argv.append(query)
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   704
                self.send_response(200, "Script output follows")
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   705
                hg.run()
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   706
            finally:
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   707
                sys.argv, sys.stdin, sys.stdout, sys.stderr = save
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   708
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   709
    hg = hgweb(path, name, templates)
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   710
    httpd = BaseHTTPServer.HTTPServer((address, port), hgwebhandler)
be7103467d2e Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents: 157
diff changeset
   711
    httpd.serve_forever()