mercurial/hgweb.py
author mpm@selenic.com
Mon, 23 May 2005 16:00:02 -0800
changeset 138 c77a679e9cfa
parent 137 b45b1b00fc9e
child 142 529bf610092e
permissions -rw-r--r--
Revamped templated hgweb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
     1
#!/usr/bin/env python
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
     2
#
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
     3
# hgweb.py - 0.2 - 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net>
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
     4
#    - web interface to a mercurial repository
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 *
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    15
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    16
def age(t):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    17
    def plural(t, c):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    18
        if c == 1: return t
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    19
        return t + "s"
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    20
    def fmt(t, c):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    21
        return "%d %s" % (c, plural(t, c))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    22
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    23
    now = time.time()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    24
    delta = max(1, int(now - t))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    25
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    26
    scales = [["second", 1],
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    27
              ["minute", 60],
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    28
              ["hour", 3600],
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    29
              ["day", 3600 * 24],
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    30
              ["week", 3600 * 24 * 7],
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    31
              ["month", 3600 * 24 * 30],
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    32
              ["year", 3600 * 24 * 365]]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    33
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    34
    scales.reverse()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    35
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    36
    for t, s in scales:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    37
        n = delta / s
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    38
        if n >= 1: return fmt(t, n)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    39
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    40
def nl2br(text):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    41
    return text.replace('\n', '<br/>')
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    42
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    43
def obfuscate(text):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    44
    return ''.join([ '&#%d' % ord(c) for c in text ])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    45
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    46
def up(p):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    47
    if p[0] != "/": p = "/" + p
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    48
    if p[-1] == "/": p = p[:-1]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    49
    up = os.path.dirname(p)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    50
    if up == "/":
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    51
        return "/"
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    52
    return up + "/"
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    53
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    54
def httphdr(type):
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    55
    print 'Content-type: %s\n' % type
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    56
135
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    57
def write(*things):
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    58
    for thing in things:
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    59
        if hasattr(thing, "__iter__"):
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    60
            for part in thing:
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    61
                write(part)
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    62
        else:
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    63
            sys.stdout.write(str(thing))
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    64
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    65
def template(tmpl, **map):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    66
    while tmpl:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    67
        m = re.search(r"#([a-zA-Z0-9]+)#", tmpl)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    68
        if m:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    69
            yield tmpl[:m.start(0)]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    70
            v = map.get(m.group(1), "")
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    71
            yield callable(v) and v() or v
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    72
            tmpl = tmpl[m.end(0):]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    73
        else:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    74
            yield tmpl
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    75
            return
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    76
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    77
class templater:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    78
    def __init__(self, mapfile):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    79
        self.cache = {}
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    80
        self.map = {}
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    81
        self.base = os.path.dirname(mapfile)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    82
        
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    83
        for l in file(mapfile):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    84
            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
    85
            if m:
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    86
                self.cache[m.group(1)] = m.group(2)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    87
            else:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    88
                m = re.match(r'(\S+)\s*=\s*(\S+)', l)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    89
                if m:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    90
                    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
    91
                else:
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    92
                    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
    93
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    94
    def __call__(self, t, **map):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    95
        try:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    96
            tmpl = self.cache[t]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    97
        except KeyError:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    98
            tmpl = self.cache[t] = file(self.map[t]).read()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    99
        return template(tmpl, **map)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   100
        
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   101
class hgweb:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   102
    maxchanges = 20
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   103
    maxfiles = 10
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   104
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   105
    def __init__(self, path, name, templatemap):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   106
        self.reponame = name
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   107
        self.repo = repository(ui(), path)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   108
        self.t = templater(templatemap)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   109
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   110
    def date(self, cs):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   111
        return time.asctime(time.gmtime(float(cs[2].split(' ')[0])))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   112
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   113
    def listfiles(self, files, mf):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   114
        for f in files[:self.maxfiles]:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   115
            yield self.t("filenodelink", node = hex(mf[f]), file = f)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   116
        if len(files) > self.maxfiles:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   117
            yield self.t("fileellipses")
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   118
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   119
    def listfilediffs(self, files, changeset):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   120
        for f in files[:self.maxfiles]:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   121
            yield self.t("filedifflink", node = hex(changeset), file = f)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   122
        if len(files) > self.maxfiles:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   123
            yield self.t("fileellipses")
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   124
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   125
    def diff(self, node1, node2, files):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   126
        def filterfiles(list, files):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   127
            l = [ x for x in list if x in files ]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   128
            
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   129
            for f in files:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   130
                if f[-1] != os.sep: f += os.sep
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   131
                l += [ x for x in list if x.startswith(f) ]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   132
            return l
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   133
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   134
        def prettyprint(diff):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   135
            for l in diff.splitlines(1):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   136
                line = cgi.escape(l)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   137
                if line.startswith('+'):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   138
                    yield self.t("difflineplus", line = line)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   139
                elif line.startswith('-'):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   140
                    yield self.t("difflineminus", line = line)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   141
                elif line.startswith('@'):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   142
                    yield self.t("difflineat", line = line)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   143
                else:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   144
                    yield self.t("diffline", line = line)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   145
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   146
        r = self.repo
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   147
        cl = r.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   148
        mf = r.manifest
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   149
        change1 = cl.read(node1)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   150
        change2 = cl.read(node2)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   151
        mmap1 = mf.read(change1[0])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   152
        mmap2 = mf.read(change2[0])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   153
        date1 = self.date(change1)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   154
        date2 = self.date(change2)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   155
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   156
        c, a, d = r.diffrevs(node1, node2)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   157
        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
   158
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   159
        for f in c:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   160
            to = r.file(f).read(mmap1[f])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   161
            tn = r.file(f).read(mmap2[f])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   162
            yield prettyprint(mdiff.unidiff(to, date1, tn, date2, f))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   163
        for f in a:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   164
            to = ""
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   165
            tn = r.file(f).read(mmap2[f])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   166
            yield prettyprint(mdiff.unidiff(to, date1, tn, date2, f))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   167
        for f in d:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   168
            to = r.file(f).read(mmap1[f])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   169
            tn = ""
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   170
            yield prettyprint(mdiff.unidiff(to, date1, tn, date2, f))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   171
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   172
    def changelog(self, pos=None):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   173
        def changenav():
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   174
            def seq(factor = 1):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   175
                yield 1 * factor
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   176
                yield 2 * factor
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   177
                yield 5 * factor
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   178
                for f in seq(factor * 10):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   179
                    yield f
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   180
                    
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   181
            linear = range(0, count - 2, self.maxchanges)[0:8]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   182
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   183
            for i in linear:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   184
                yield self.t("naventry", rev = max(i, 1))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   185
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   186
            for s in seq():
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   187
                if s > count - 2: break
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   188
                if s > linear[-1]:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   189
                    yield self.t("naventry", rev = s)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   190
                    
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   191
            yield self.t("naventry", rev = count - 1)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   192
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   193
        def changelist():
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   194
            cl = self.repo.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   195
            l = [] # build a list in forward order for efficiency
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   196
            for i in range(start, end + 1):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   197
                n = cl.node(i)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   198
                changes = cl.read(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   199
                hn = hex(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   200
                p1, p2 = cl.parents(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   201
                t = float(changes[2].split(' ')[0])
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   202
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   203
                l.insert(0, self.t(
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   204
                    'changelogentry',
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   205
                    author = obfuscate(changes[1]),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   206
                    shortdesc = cgi.escape(changes[4].splitlines()[0]),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   207
                    age = age(t),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   208
                    p1 = hex(p1), p2 = hex(p2),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   209
                    p1rev = cl.rev(p1), p2rev = cl.rev(p2),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   210
                    manifest = hex(changes[0]),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   211
                    desc = nl2br(cgi.escape(changes[4])),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   212
                    date = time.asctime(time.gmtime(t)),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   213
                    files = self.listfilediffs(changes[3], n),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   214
                    rev = i,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   215
                    node = hn))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   216
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   217
            yield l
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   218
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   219
        count = self.repo.changelog.count()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   220
        pos = pos or count - 1
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   221
        end = min(pos, count - 1)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   222
        start = max(0, pos - self.maxchanges)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   223
        end = min(count - 1, start + self.maxchanges)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   224
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   225
        yield self.t('changelog', repo = self.reponame, changenav = changenav,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   226
                     rev = pos, changesets = count, changelist = changelist)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   227
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   228
    def changeset(self, nodeid):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   229
        n = bin(nodeid)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   230
        cl = self.repo.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   231
        changes = cl.read(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   232
        p1, p2 = cl.parents(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   233
        p1rev, p2rev = cl.rev(p1), cl.rev(p2)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   234
        t = float(changes[2].split(' ')[0])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   235
        
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   236
        files = []
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   237
        mf = self.repo.manifest.read(changes[0])
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   238
        for f in changes[3]:
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   239
            files.append(self.t("filenodelink",
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   240
                                filenode = hex(mf[f]), file = f))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   241
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   242
        def diff():
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   243
            yield self.diff(p1, n, changes[3])
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   244
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   245
        yield self.t('changeset',
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   246
                     diff = diff,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   247
                     rev = cl.rev(n),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   248
                     node = nodeid,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   249
                     shortdesc = cgi.escape(changes[4].splitlines()[0]),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   250
                     p1 = hex(p1), p2 = hex(p2),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   251
                     p1rev = cl.rev(p1), p2rev = cl.rev(p2),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   252
                     manifest = hex(changes[0]),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   253
                     author = obfuscate(changes[1]),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   254
                     desc = nl2br(cgi.escape(changes[4])),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   255
                     date = time.asctime(time.gmtime(t)),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   256
                     files = files)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   257
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   258
    def filelog(self, f, filenode):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   259
        cl = self.repo.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   260
        fl = self.repo.file(f)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   261
        count = fl.count()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   262
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   263
        def entries():
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   264
            l = []
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   265
            for i in range(count):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   266
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   267
                n = fl.node(i)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   268
                lr = fl.linkrev(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   269
                cn = cl.node(lr)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   270
                cs = cl.read(cl.node(lr))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   271
                p1, p2 = fl.parents(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   272
                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
   273
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   274
                l.insert(0, self.t("filelogentry",
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   275
                                   filenode = hex(n),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   276
                                   filerev = i,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   277
                                   file = f,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   278
                                   node = hex(cn),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   279
                                   author = obfuscate(cs[1]),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   280
                                   age = age(t),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   281
                                   date = time.asctime(time.gmtime(t)),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   282
                                   shortdesc = cgi.escape(cs[4].splitlines()[0]),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   283
                                   p1 = hex(p1), p2 = hex(p2),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   284
                                   p1rev = fl.rev(p1), p2rev = fl.rev(p2)))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   285
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   286
            yield l
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   287
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   288
        yield self.t("filelog",
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   289
                     file = f,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   290
                     filenode = filenode,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   291
                     entries = entries)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   292
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   293
    def filerevision(self, f, node):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   294
        fl = self.repo.file(f)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   295
        n = bin(node)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   296
        text = cgi.escape(fl.read(n))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   297
        changerev = fl.linkrev(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   298
        cl = self.repo.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   299
        cn = cl.node(changerev)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   300
        cs = cl.read(cn)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   301
        p1, p2 = fl.parents(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   302
        t = float(cs[2].split(' ')[0])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   303
        mfn = cs[0]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   304
        
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   305
        yield self.t("filerevision", file = f,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   306
                     filenode = node,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   307
                     path = up(f),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   308
                     text = text,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   309
                     rev = changerev,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   310
                     node = hex(cn),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   311
                     manifest = hex(mfn),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   312
                     author = obfuscate(cs[1]),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   313
                     age = age(t),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   314
                     date = time.asctime(time.gmtime(t)),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   315
                     shortdesc = cgi.escape(cs[4].splitlines()[0]),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   316
                     p1 = hex(p1), p2 = hex(p2),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   317
                     p1rev = fl.rev(p1), p2rev = fl.rev(p2))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   318
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 fileannotate(self, f, node):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   321
        bcache = {}
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   322
        ncache = {}
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   323
        fl = self.repo.file(f)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   324
        n = bin(node)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   325
        changerev = fl.linkrev(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   326
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   327
        cl = self.repo.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   328
        cn = cl.node(changerev)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   329
        cs = cl.read(cn)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   330
        p1, p2 = fl.parents(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   331
        t = float(cs[2].split(' ')[0])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   332
        mfn = cs[0]
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   333
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   334
        def annotate():
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   335
            for r, l in fl.annotate(n):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   336
                try:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   337
                    cnode = ncache[r]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   338
                except KeyError:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   339
                    cnode = ncache[r] = self.repo.changelog.node(r)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   340
                    
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   341
                try:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   342
                    name = bcache[r]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   343
                except KeyError:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   344
                    cl = self.repo.changelog.read(cnode)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   345
                    name = cl[1]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   346
                    f = name.find('@')
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   347
                    if f >= 0:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   348
                        name = name[:f]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   349
                    bcache[r] = name
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   350
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   351
                yield self.t("annotateline",
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   352
                             node = hex(cnode),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   353
                             rev = r,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   354
                             author = name,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   355
                             file = f,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   356
                             line = cgi.escape(l))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   357
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   358
        yield self.t("fileannotate",
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   359
                     file = f,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   360
                     filenode = node,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   361
                     annotate = annotate,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   362
                     path = up(f),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   363
                     rev = changerev,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   364
                     node = hex(cn),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   365
                     manifest = hex(mfn),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   366
                     author = obfuscate(cs[1]),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   367
                     age = age(t),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   368
                     date = time.asctime(time.gmtime(t)),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   369
                     shortdesc = cgi.escape(cs[4].splitlines()[0]),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   370
                     p1 = hex(p1), p2 = hex(p2),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   371
                     p1rev = fl.rev(p1), p2rev = fl.rev(p2))
136
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   372
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   373
    def manifest(self, mnode, path):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   374
        mf = self.repo.manifest.read(bin(mnode))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   375
        rev = self.repo.manifest.rev(bin(mnode))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   376
        node = self.repo.changelog.node(rev)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   377
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   378
        dirs = {}
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   379
        files = {}
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   380
        short = {}
136
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   381
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   382
        p = path[1:]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   383
        l = len(p)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   384
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   385
        for f,n in mf.items():
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   386
            if f[:l] != p:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   387
                continue
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   388
            remain = f[l:]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   389
            if "/" in remain:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   390
                short = remain[:remain.find("/") + 1] # bleah
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   391
                dirs[short] = 1
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   392
            else:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   393
                short = os.path.basename(remain)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   394
                files[short] = (f, n)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   395
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   396
        def dirlist():
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   397
            dl = dirs.keys()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   398
            dl.sort()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   399
            
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   400
            for d in dl:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   401
                yield self.t("manifestdirentry",
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   402
                             path = os.path.join(path, d),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   403
                             manifest = mnode, basename = d[:-1])
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   404
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   405
        def filelist():
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   406
            fl = files.keys()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   407
            fl.sort()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   408
            for f in fl:
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   409
                full, fnode = files[f]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   410
                yield self.t("manifestfileentry",
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   411
                             file = full, manifest = mnode, filenode = hex(fnode),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   412
                             basename = f)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   413
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   414
        yield self.t("manifest",
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   415
                     manifest = mnode,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   416
                     rev = rev,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   417
                     node = hex(node),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   418
                     path = path,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   419
                     up = up(path),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   420
                     dirs = dirlist,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   421
                     files = filelist)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   422
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   423
    def filediff(self, file, changeset):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   424
        n = bin(changeset)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   425
        cl = self.repo.changelog
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   426
        p1 = cl.parents(n)[0]
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   427
        cs = cl.read(n)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   428
        mf = self.repo.manifest.read(cs[0])
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   429
        
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   430
        def diff():
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   431
            yield self.diff(p1, n, file)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   432
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   433
        yield self.t("filediff",
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   434
                     file = file,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   435
                     filenode = hex(mf[file]),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   436
                     node = changeset,
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   437
                     rev = self.repo.changelog.rev(n),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   438
                     p1 = hex(p1),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   439
                     p1rev = self.repo.changelog.rev(p1),
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   440
                     diff = diff)
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   441
                     
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   442
    # header and footer, css
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   443
    # add tags to things
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   444
    # show parents
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   445
    # diff between rev and parent in changeset and file
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   446
    # manifest links
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   447
    # browse at top
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   448
    # tags -> list of changesets corresponding to tags
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   449
    # find tag, changeset, file
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   450
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   451
    def run(self):
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   452
        args = cgi.parse()
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   453
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   454
        if not args.has_key('cmd') or args['cmd'][0] == 'changelog':
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   455
            hi = self.repo.changelog.count()
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   456
            if args.has_key('pos'):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   457
                hi = int(args['pos'][0])
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   458
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   459
            write(self.changelog(hi))
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   460
            
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   461
        elif args['cmd'][0] == 'changeset':
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   462
            write(self.changeset(args['node'][0]))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   463
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   464
        elif args['cmd'][0] == 'manifest':
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   465
            write(self.manifest(args['manifest'][0], args['path'][0]))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   466
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   467
        elif args['cmd'][0] == 'filediff':
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   468
            write(self.filediff(args['file'][0], args['node'][0]))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   469
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   470
        elif args['cmd'][0] == 'file':
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   471
            write(self.filerevision(args['file'][0], args['filenode'][0]))
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
        elif args['cmd'][0] == 'annotate':
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   474
            write(self.fileannotate(args['file'][0], args['filenode'][0]))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   475
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   476
        elif args['cmd'][0] == 'filelog':
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   477
            write(self.filelog(args['file'][0], args['filenode'][0]))
136
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   478
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   479
        elif args['cmd'][0] == 'branches':
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   480
            httphdr("text/plain")
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   481
            nodes = []
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   482
            if args.has_key('nodes'):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   483
                nodes = map(bin, args['nodes'][0].split(" "))
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   484
            for b in self.repo.branches(nodes):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   485
                sys.stdout.write(" ".join(map(hex, b)) + "\n")
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   486
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   487
        elif args['cmd'][0] == 'between':
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   488
            httphdr("text/plain")
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   489
            nodes = []
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   490
            if args.has_key('pairs'):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   491
                pairs = [ map(bin, p.split("-"))
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   492
                          for p in args['pairs'][0].split(" ") ]
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   493
            for b in self.repo.between(pairs):
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   494
                sys.stdout.write(" ".join(map(hex, b)) + "\n")
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   495
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   496
        elif args['cmd'][0] == 'changegroup':
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   497
            httphdr("application/hg-changegroup")
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   498
            nodes = []
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   499
            if args.has_key('roots'):
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   500
                nodes = map(bin, args['roots'][0].split(" "))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   501
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   502
            z = zlib.compressobj()
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   503
            for chunk in self.repo.changegroup(nodes):
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   504
                sys.stdout.write(z.compress(chunk))
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   505
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   506
            sys.stdout.write(z.flush())
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   507
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   508
        else:
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
   509
            write(self.t("error"))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   510
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   511
if __name__ == "__main__":
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   512
    hgweb().run()