mercurial/hgweb.py
author jake@edge2.net
Sat, 21 May 2005 22:43:14 -0700
changeset 136 0e8d60d2bb2b
parent 135 c0faf50822ea
child 137 b45b1b00fc9e
permissions -rw-r--r--
added annotate fixed error page to get tmpl_dir
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
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    14
from mercurial import hg, mdiff
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    15
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    16
def nl2br(text):
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    17
    return re.sub('\n', '<br />', text)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    18
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    19
def obfuscate(text):
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    20
    l = []
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    21
    for c in text:
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    22
        l.append('&#%d;' % ord(c))
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    23
    return ''.join(l)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    24
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    25
def httphdr(type):
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    26
    print 'Content-type: %s\n' % type
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    27
135
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    28
def write(*things):
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    29
    for thing in things:
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    30
        if hasattr(thing, "__iter__"):
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    31
            for part in thing:
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    32
                write(part)
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    33
        else:
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    34
            sys.stdout.write(str(thing))
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    35
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    36
class template:
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    37
    def __init__(self, tmpl_dir):
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    38
        self.tmpl_dir = tmpl_dir
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    39
    def do_page(self, tmpl_fn, **map):
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    40
        txt = file(os.path.join(self.tmpl_dir, tmpl_fn)).read()
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    41
        while txt:
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    42
            m = re.search(r"#([a-zA-Z0-9]+)#", txt)
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    43
            if m:
135
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    44
                yield txt[:m.start(0)]
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    45
                v = map.get(m.group(1), "")
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    46
                if callable(v):
135
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    47
                   for y in v(**map): yield y
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    48
                else:
135
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    49
                   yield v
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    50
                txt = txt[m.end(0):]
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    51
            else:
135
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    52
                yield txt
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    53
                txt = ''
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    54
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    55
class page:
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    56
    def __init__(self, tmpl_dir = "", type="text/html", title="Mercurial Web", 
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    57
            charset="ISO-8859-1"):
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    58
        self.tmpl = template(tmpl_dir)
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    59
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    60
        print 'Content-type: %s; charset=%s\n' % (type, charset)
135
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    61
        write(self.tmpl.do_page('htmlstart.tmpl', title = title))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    62
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    63
    def endpage(self):
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    64
        print '</BODY>'
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    65
        print '</HTML>'
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    66
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    67
    def show_diff(self, a, b, fn):
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    68
        a = a.splitlines(1)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    69
        b = b.splitlines(1)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    70
        l = difflib.unified_diff(a, b, fn, fn)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    71
        print '<pre>'
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    72
        for line in l:
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    73
            line = cgi.escape(line[:-1])
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    74
            if line.startswith('+'):
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    75
                print '<span class="plusline">%s</span>' % (line, )
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    76
            elif line.startswith('-'):
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    77
                print '<span class="minusline">%s</span>' % (line, )
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    78
            elif line.startswith('@'):
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    79
                print '<span class="atline">%s</span>' % (line, )
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    80
            else:
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    81
                print line
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    82
        print '</pre>'
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    83
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    84
class errpage(page):
136
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
    85
    def __init__(self, tmpl_dir):
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
    86
        page.__init__(self, tmpl_dir, title="Mercurial Web Error Page")
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    87
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    88
class change_list(page):
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    89
    def __init__(self, repo, tmpl_dir, reponame, numchanges = 50):
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    90
        page.__init__(self, tmpl_dir)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    91
        self.repo = repo
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
    92
        self.numchanges = numchanges
135
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
    93
        write(self.tmpl.do_page('changestitle.tmpl', reponame=reponame))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    94
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    95
    def content(self, hi=None):
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    96
        cl = []
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    97
        count = self.repo.changelog.count()
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    98
        if not hi:
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
    99
            hi = count
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   100
        elif hi < self.numchanges:
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   101
            hi = self.numchanges
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   102
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   103
        start = 0
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   104
        if hi - self.numchanges >= 0:
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   105
            start = hi - self.numchanges
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   106
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   107
        nav = "Displaying Revisions: %d-%d" % (start, hi-1)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   108
        if start != 0:
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   109
            nav = ('<a href="?cmd=changes;hi=%d">Previous %d</a>&nbsp;&nbsp;' \
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   110
                    % (start, self.numchanges)) + nav
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   111
        if hi != count:
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   112
            if hi + self.numchanges <= count:
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   113
                nav += '&nbsp;&nbsp;<a href="?cmd=changes;hi=%d">Next %d</a>' \
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   114
                        % (hi + self.numchanges, self.numchanges)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   115
            else:
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   116
                nav += '&nbsp;&nbsp;<a href="?cmd=changes">Next %d</a>' % \
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   117
                        self.numchanges
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   118
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   119
        print '<center>%s</center>' % nav
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   120
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   121
        for i in xrange(start, hi):
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   122
            n = self.repo.changelog.node(i)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   123
            cl.append((n, self.repo.changelog.read(n)))
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   124
        cl.reverse()
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   125
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   126
        print '<table summary="" width="100%" align="center">'
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   127
        for n, ch in cl:
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   128
            print '<tr><td>'
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   129
            self.change_table(n, ch)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   130
            print '</td></tr>'
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   131
        print '</table>'
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   132
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   133
        print '<center>%s</center>' % nav
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   134
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   135
    def change_table(self, nodeid, changes):
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   136
        hn = hg.hex(nodeid)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   137
        i = self.repo.changelog.rev(nodeid)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   138
        (h1, h2) = [ hg.hex(x) for x in self.repo.changelog.parents(nodeid) ]
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   139
        datestr = time.asctime(time.gmtime(float(changes[2].split(' ')[0])))
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   140
        files = []
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   141
        for f in changes[3]:
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   142
            files.append('<a href="?cmd=file;cs=%s;fn=%s">%s</a>&nbsp;&nbsp;' \
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   143
                % (hn, f, cgi.escape(f)))
135
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
   144
        write(self.tmpl.do_page('change_table.tmpl',
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   145
                author=obfuscate(changes[1]),
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   146
                desc=nl2br(cgi.escape(changes[4])), date=datestr, 
135
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
   147
                files=' '.join(files), revnum=i, revnode=hn))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   148
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   149
class checkin(page):
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   150
    def __init__(self, repo, tmpl_dir, nodestr):
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   151
        page.__init__(self, tmpl_dir)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   152
        self.repo = repo
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   153
        self.node = hg.bin(nodestr)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   154
        self.nodestr = nodestr
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   155
        print '<h3>Checkin: %s</h3>' % nodestr
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   156
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   157
    def content(self):
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   158
        changes = self.repo.changelog.read(self.node)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   159
        i = self.repo.changelog.rev(self.node)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   160
        parents = self.repo.changelog.parents(self.node)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   161
        (h1, h2) = [ hg.hex(x) for x in parents ]
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   162
        (i1, i2) = [ self.repo.changelog.rev(x) for x in parents ]
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   163
        datestr = time.asctime(time.gmtime(float(changes[2].split(' ')[0])))
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   164
        mf = self.repo.manifest.read(changes[0])
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   165
        files = []
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   166
        for f in changes[3]:
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   167
            files.append('<a href="?cmd=file;nd=%s;fn=%s">%s</a>&nbsp;&nbsp;' \
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   168
                % (hg.hex(mf[f]), f, cgi.escape(f)))
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   169
        p2link = h2
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   170
        if i2 != -1:
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   171
            p2link = '<a href="?cmd=chkin;nd=%s">%s</a>' % (h2, h2)
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   172
135
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
   173
        write(self.tmpl.do_page('checkin.tmpl', revnum=i, revnode=self.nodestr,
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   174
                p1num=i1, p1node=h1, p2num=i2, p2node=h2, p2link=p2link,
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   175
                mfnum=self.repo.manifest.rev(changes[0]), 
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   176
                mfnode=hg.hex(changes[0]), author=obfuscate(changes[1]),
134
13d609f8d830 fix problem with non wrapping file list
jake@edge2.net
parents: 133
diff changeset
   177
                desc=nl2br(cgi.escape(changes[4])), date=datestr,
135
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
   178
                files=' '.join(files)))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   179
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   180
        (c, a, d) = self.repo.diffrevs(parents[0], self.node)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   181
        change = self.repo.changelog.read(parents[0])
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   182
        mf2 = self.repo.manifest.read(change[0])
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   183
        for f in c:
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   184
            self.show_diff(self.repo.file(f).read(mf2[f]), \
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   185
                    self.repo.file(f).read(mf[f]), f)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   186
        for f in a:
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   187
            self.show_diff('', self.repo.file(f).read(mf[f]), f)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   188
        for f in d:
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   189
            self.show_diff(self.repo.file(f).read(mf2[f]), '', f)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   190
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   191
class filepage(page):
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   192
    def __init__(self, repo, tmpl_dir, fn, node=None, cs=None):
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   193
        page.__init__(self, tmpl_dir)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   194
        self.repo = repo
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   195
        self.fn = fn
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   196
        if cs: 
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   197
            chng = self.repo.changelog.read(hg.bin(cs))
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   198
            mf = self.repo.manifest.read(chng[0])
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   199
            self.node = mf[self.fn]
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   200
            self.nodestr = hg.hex(self.node)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   201
        else:
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   202
            self.nodestr = node
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   203
            self.node = hg.bin(node)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   204
        print '<div class="filename">%s (%s)</div>' % \
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   205
                (cgi.escape(self.fn), self.nodestr, )
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   206
        print '<a href="?cmd=hist;fn=%s">history</a><br />' % self.fn
136
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   207
        print '<a href="?cmd=ann;fn=%s;nd=%s">annotate</a><br />' % \
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   208
                (self.fn, self.nodestr)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   209
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   210
    def content(self):
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   211
        print '<pre>'
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   212
        print cgi.escape(self.repo.file(self.fn).read(self.node))
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   213
        print '</pre>'
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   214
136
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   215
class annpage(page):
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   216
    def __init__(self, repo, tmpl_dir, fn, node):
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   217
        page.__init__(self, tmpl_dir)
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   218
        self.repo = repo
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   219
        self.fn = fn
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   220
        self.nodestr = node
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   221
        self.node = hg.bin(node)
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   222
        print '<div class="annotation">Annotated: %s (%s)</div>' % \
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   223
                (cgi.escape(self.fn), self.nodestr, )
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   224
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   225
    def content(self):
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   226
        print '<pre>'
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   227
        for n, l in self.repo.file(self.fn).annotate(self.node):
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   228
            cnode = self.repo.changelog.lookup(n)
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   229
            write(self.tmpl.do_page('annline.tmpl', cnode=hg.hex(cnode),
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   230
                    cnum='% 6s' % n, fn=self.fn, line=cgi.escape(l[:-1])))
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   231
        print '</pre>'
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   232
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   233
class mfpage(page):
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   234
    def __init__(self, repo, tmpl_dir, node):
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   235
        page.__init__(self, tmpl_dir)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   236
        self.repo = repo
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   237
        self.nodestr = node
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   238
        self.node = hg.bin(node)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   239
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   240
    def content(self):
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   241
        mf = self.repo.manifest.read(self.node)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   242
        fns = mf.keys()
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   243
        fns.sort()
135
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
   244
        write(self.tmpl.do_page('mftitle.tmpl', node = self.nodestr))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   245
        for f in fns:
135
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
   246
            write(self.tmpl.do_page('mfentry.tmpl', fn=f, node=hg.hex(mf[f])))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   247
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   248
class histpage(page):
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   249
    def __init__(self, repo, tmpl_dir, fn):
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   250
        page.__init__(self, tmpl_dir)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   251
        self.repo = repo
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   252
        self.fn = fn
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   253
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   254
    def content(self):
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   255
        print '<div class="filehist">File History: %s</div>' % self.fn
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   256
        r = self.repo.file(self.fn)
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   257
        print '<br />'
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   258
        print '<table summary="" width="100%" align="center">'
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   259
        for i in xrange(r.count()-1, -1, -1):
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   260
            print '<tr><td>'
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   261
            self.hist_ent(i, r)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   262
            print '</tr></td>'
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   263
        print '</table>'
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   264
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   265
    def hist_ent(self, i, r):
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   266
        n = r.node(i)
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   267
        (p1, p2) = r.parents(n)
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   268
        (h, h1, h2) = map(hg.hex, (n, p1, p2))
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   269
        (i1, i2) = map(r.rev, (p1, p2))
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   270
        ci = r.linkrev(n)
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   271
        cn = self.repo.changelog.node(ci)
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   272
        cs = hg.hex(cn)
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   273
        changes = self.repo.changelog.read(cn)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   274
        datestr = time.asctime(time.gmtime(float(changes[2].split(' ')[0])))
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   275
        p2entry = ''
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   276
        if i2 != -1:
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   277
            p2entry = '&nbsp;&nbsp;%d:<a href="?cmd=file;nd=%s;fn=%s">%s</a>' \
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   278
                    % (i2, h2, self.fn, h2 ),
135
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
   279
        write(self.tmpl.do_page('hist_ent.tmpl', author=obfuscate(changes[1]),
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   280
                csnode=cs, desc=nl2br(cgi.escape(changes[4])), 
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   281
                date = datestr, fn=self.fn, revnode=h, p1num = i1,
135
c0faf50822ea change template to a generator
jake@edge2.net
parents: 134
diff changeset
   282
                p1node=h1, p2entry=p2entry))
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   283
                
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   284
class hgweb:
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   285
    repo_path = "."
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   286
    numchanges = 50
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   287
    tmpl_dir = "templates"
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   288
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   289
    def __init__(self):
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   290
        pass
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   291
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   292
    def run(self):
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   293
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   294
        args = cgi.parse()
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   295
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   296
        ui = hg.ui()
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   297
        repo = hg.repository(ui, self.repo_path)
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   298
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   299
        if not args.has_key('cmd') or args['cmd'][0] == 'changes':
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   300
            page = change_list(repo, self.tmpl_dir, 'Mercurial', 
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   301
                    self.numchanges)
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   302
            hi = args.get('hi', ( repo.changelog.count(), ))
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   303
            page.content(hi = int(hi[0]))
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   304
            page.endpage()
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   305
            
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   306
        elif args['cmd'][0] == 'chkin':
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   307
            if not args.has_key('nd'):
136
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   308
                page = errpage(self.tmpl_dir)
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   309
                print '<div class="errmsg">No Node!</div>'
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   310
            else:
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   311
                page = checkin(repo, self.tmpl_dir, args['nd'][0])
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   312
                page.content()
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   313
            page.endpage()
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   314
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   315
        elif args['cmd'][0] == 'file':
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   316
            if not (args.has_key('nd') and args.has_key('fn')) and \
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   317
                    not (args.has_key('cs') and args.has_key('fn')):
136
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   318
                page = errpage(self.tmpl_dir)
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   319
                print '<div class="errmsg">Invalid Args!</div>'
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   320
            else:
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   321
                if args.has_key('nd'):
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   322
                    page = filepage(repo, self.tmpl_dir, 
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   323
                            args['fn'][0], node=args['nd'][0])
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   324
                else:
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   325
                    page = filepage(repo, self.tmpl_dir,
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   326
                            args['fn'][0], cs=args['cs'][0])
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   327
                page.content()
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   328
            page.endpage()
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   329
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   330
        elif args['cmd'][0] == 'mf':
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   331
            if not args.has_key('nd'):
136
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   332
                page = errpage(self.tmpl_dir)
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   333
                print '<div class="errmsg">No Node!</div>'
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   334
            else:
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   335
                page = mfpage(repo, self.tmpl_dir, args['nd'][0])
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   336
                page.content()
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   337
            page.endpage()
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   338
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   339
        elif args['cmd'][0] == 'hist':
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   340
            if not args.has_key('fn'):
136
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   341
                page = errpage(self.tmpl_dir)
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   342
                print '<div class="errmsg">No Filename!</div>'
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   343
            else:
133
fb84d3e71042 added template support for some hgweb output, also, template files for
jake@edge2.net
parents: 132
diff changeset
   344
                page = histpage(repo, self.tmpl_dir, args['fn'][0])
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   345
                page.content()
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   346
            page.endpage()
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   347
136
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   348
        elif args['cmd'][0] == 'ann':
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   349
            if not args.has_key('fn'):
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   350
                page = errpage(self.tmpl_dir)
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   351
                print '<div class="errmsg">No Filename!</div>'
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   352
            elif not args.has_key('nd'):
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   353
                page = errpage(self.tmpl_dir)
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   354
                print '<div class="errmsg">No Node!</div>'
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   355
            else:
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   356
                page = annpage(repo, self.tmpl_dir, args['fn'][0], 
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   357
                        args['nd'][0])
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   358
                page.content()
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   359
            page.endpage()
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   360
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   361
        elif args['cmd'][0] == 'branches':
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   362
            httphdr("text/plain")
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   363
            nodes = []
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   364
            if args.has_key('nodes'):
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   365
                nodes = map(hg.bin, args['nodes'][0].split(" "))
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   366
            for b in repo.branches(nodes):
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   367
                print " ".join(map(hg.hex, b))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   368
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   369
        elif args['cmd'][0] == 'between':
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   370
            httphdr("text/plain")
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   371
            nodes = []
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   372
            if args.has_key('pairs'):
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   373
                pairs = [ map(hg.bin, p.split("-"))
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   374
                          for p in args['pairs'][0].split(" ") ]
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   375
            for b in repo.between(pairs):
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   376
                print " ".join(map(hg.hex, b))
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   377
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   378
        elif args['cmd'][0] == 'changegroup':
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   379
            httphdr("application/hg-changegroup")
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   380
            nodes = []
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   381
            if args.has_key('roots'):
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   382
                nodes = map(hg.bin, args['roots'][0].split(" "))
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   383
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   384
            z = zlib.compressobj()
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   385
            for chunk in repo.changegroup(nodes):
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   386
                sys.stdout.write(z.compress(chunk))
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   387
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   388
            sys.stdout.write(z.flush())
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   389
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   390
        else:
136
0e8d60d2bb2b added annotate
jake@edge2.net
parents: 135
diff changeset
   391
            page = errpage(self.tmpl_dir)
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   392
            print '<div class="errmsg">unknown command: %s</div>' % \
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   393
                    cgi.escape(args['cmd'][0])
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   394
            page.endpage()
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
   395
132
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   396
if __name__ == "__main__":
210eeb6f5197 making hgweb class
jake@edge2.net
parents: 131
diff changeset
   397
    hgweb().run()