hgweb.py
author mpm@selenic.com
Wed, 18 May 2005 17:06:07 -0800
changeset 102 58039eddbdda
parent 61 1215bf60468f
parent 101 6da5cf0c4193
permissions -rw-r--r--
Merge from hgweb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
     1
#!/usr/bin/env python
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
     2
#
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
     3
# hgweb.py - 0.1 - 9 May 2005 - (c) 2005 Jake Edge <jake@edge2.net>
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
     4
#    - web interface to a mercurial repository
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
     5
#
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
     6
# This software may be used and distributed according to the terms
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
     7
# of the GNU General Public License, incorporated herein by reference.
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
     8
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
     9
# useful for debugging
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    10
import cgitb
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    11
cgitb.enable()
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    12
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
    13
import os, cgi, time, re, difflib, sys, zlib
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    14
from mercurial import hg, mdiff
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    15
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    16
repo_path = "."  # change as needed
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    17
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    18
def nl2br(text):
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    19
    return re.sub('\n', '<br />', text)
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    20
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    21
def obfuscate(text):
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    22
    l = []
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    23
    for c in text:
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    24
        l.append('&#%d;' % ord(c))
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    25
    return ''.join(l)
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    26
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    27
def httphdr(type):
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
    28
    print 'Content-type: %s\n' % type
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    29
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    30
class page:
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    31
    def __init__(self, type="text/html", title="Mercurial Web", 
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    32
            charset="ISO-8859-1"):
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    33
        print 'Content-type: %s; charset=%s\n' % (type, charset)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    34
        print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    35
        print '<HTML>'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    36
        print '<!-- created by hgweb 0.1 - jake@edge2.net -->'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    37
        print '<HEAD><TITLE>%s</TITLE>' % title
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    38
        print '<style type="text/css">'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    39
        print 'body { font-family: sans-serif; font-size: 12px; }'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    40
        print 'table { font-size: 12px; }'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    41
        print '.errmsg { font-size: 200%; color: red; }'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    42
        print '.filename { font-size: 150%; color: purple; }'
101
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
    43
        print '.manifest { font-size: 150%; color: purple; }'
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
    44
        print '.filehist { font-size: 150%; color: purple; }'
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    45
        print '.plusline { color: green; }'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    46
        print '.minusline { color: red; }'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    47
        print '.atline { color: purple; }'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    48
        print '</style>'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    49
        print '</HEAD>'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    50
        print '<BODY>'
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    51
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    52
    def endpage(self):
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    53
        print '</BODY>'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    54
        print '</HTML>'
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
    55
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    56
    def show_diff(self, a, b, fn):
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    57
        a = a.splitlines(1)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    58
        b = b.splitlines(1)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    59
        l = difflib.unified_diff(a, b, fn, fn)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    60
        print '<pre>'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    61
        for line in l:
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    62
            line = cgi.escape(line[:-1])
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    63
            if line.startswith('+'):
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    64
                print '<span class="plusline">%s</span>' % (line, )
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    65
            elif line.startswith('-'):
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    66
                print '<span class="minusline">%s</span>' % (line, )
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    67
            elif line.startswith('@'):
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    68
                print '<span class="atline">%s</span>' % (line, )
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    69
            else:
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    70
                print line
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    71
        print '</pre>'
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    72
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    73
class errpage(page):
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    74
    def __init__(self):
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    75
        page.__init__(self, title="Mercurial Web Error Page")
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    76
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    77
class change_list(page):
101
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
    78
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
    79
    numchanges = 50   # number of changes to show
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
    80
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    81
    def __init__(self, repo, reponame):
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    82
        page.__init__(self)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    83
        self.repo = repo
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    84
        print '<h3>Changes For: %s</h3>' % reponame
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    85
101
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
    86
    def content(self, hi=None):
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
    87
        cl = []
101
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
    88
        count = self.repo.changelog.count()
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
    89
        if not hi:
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
    90
            hi = count
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
    91
        elif hi < self.numchanges:
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
    92
            hi = self.numchanges
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
    93
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
    94
        start = 0
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
    95
        if hi - self.numchanges >= 0:
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
    96
            start = hi - self.numchanges
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
    97
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
    98
        nav = "Displaying Revisions: %d-%d" % (start, hi-1)
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
    99
        if start != 0:
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   100
            nav = ('<a href="?cmd=changes;hi=%d">Previous %d</a>&nbsp;&nbsp;' \
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   101
                    % (start, self.numchanges)) + nav
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   102
        if hi != count:
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   103
            if hi + self.numchanges <= count:
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   104
                nav += '&nbsp;&nbsp;<a href="?cmd=changes;hi=%d">Next %d</a>' \
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   105
                        % (hi + self.numchanges, self.numchanges)
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   106
            else:
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   107
                nav += '&nbsp;&nbsp;<a href="?cmd=changes">Next %d</a>' % \
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   108
                        self.numchanges
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   109
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   110
        print '<center>%s</center>' % nav
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   111
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   112
        for i in xrange(start, hi):
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   113
            n = self.repo.changelog.node(i)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   114
            cl.append((n, self.repo.changelog.read(n)))
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   115
        cl.reverse()
101
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   116
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   117
        print '<table summary="" width="100%" align="center">'
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   118
        for n, ch in cl:
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   119
            print '<tr><td>'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   120
            self.change_table(n, ch)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   121
            print '</td></tr>'
101
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   122
        print '</table>'
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   123
101
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   124
        print '<center>%s</center>' % nav
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   125
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   126
    def change_table(self, nodeid, changes):
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   127
        hn = hg.hex(nodeid)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   128
        i = self.repo.changelog.rev(nodeid)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   129
        (h1, h2) = [ hg.hex(x) for x in self.repo.changelog.parents(nodeid) ]
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   130
        datestr = time.asctime(time.gmtime(float(changes[2].split(' ')[0])))
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   131
        print '<table summary="" width="100%" border="1">'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   132
        print '\t<tr><td valign="top" width="10%">author:</td>' + \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   133
                '<td valign="top" width="20%%">%s</td>' % \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   134
                (obfuscate(changes[1]), )
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   135
        print '\t\t<td valign="top" width="10%">description:</td>' + \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   136
                '<td width="60%">' + \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   137
                '<a href="?cmd=chkin;nd=%s">%s</a></td></tr>' % \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   138
                (hn, nl2br(cgi.escape(changes[4])), )
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   139
        print '\t<tr><td>date:</td><td>%s UTC</td>' % (datestr, )
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   140
        print '\t\t<td valign="top">files:</td><td valign="top">'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   141
        for f in changes[3]:
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   142
            print '\t\t<a href="?cmd=file;cs=%s;fn=%s">%s</a>&nbsp;&nbsp;' % \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   143
                    (hn, f, cgi.escape(f), )
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   144
        print '\t</td></tr>'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   145
        print '\t<tr><td>revision:</td><td colspan="3">%d:<a ' % (i, ) + \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   146
                'href="?cmd=chkin;nd=%s">%s</a></td></tr>' % (hn, hn, )
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   147
        print '</table><br />'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   148
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   149
class checkin(page):
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   150
    def __init__(self, repo, nodestr):
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   151
        page.__init__(self)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   152
        self.repo = repo
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   153
        self.node = hg.bin(nodestr)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   154
        self.nodestr = nodestr
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   155
        print '<h3>Checkin: %s</h3>' % nodestr
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   156
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   157
    def content(self):
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   158
        changes = self.repo.changelog.read(self.node)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   159
        i = self.repo.changelog.rev(self.node)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   160
        parents = self.repo.changelog.parents(self.node)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   161
        (h1, h2) = [ hg.hex(x) for x in parents ]
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   162
        (i1, i2) = [ self.repo.changelog.rev(x) for x in parents ]
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   163
        datestr = time.asctime(time.gmtime(float(changes[2].split(' ')[0])))
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   164
        mf = self.repo.manifest.read(changes[0])
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   165
        print '<table summary="" width="100%" border="1">'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   166
        print '\t<tr><td>revision:</td><td colspan="3">%d:' % (i, ),
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   167
        print '<a href="?cmd=chkin;nd=%s">%s</a></td></tr>' % \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   168
                (self.nodestr, self.nodestr, )
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   169
        print '\t<tr><td>parent(s):</td><td colspan="3">%d:' % (i1, )
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   170
        print '<a href="?cmd=chkin;nd=%s">%s</a>' % (h1, h1, ),
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   171
        if i2 != -1:
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   172
            print '&nbsp;&nbsp;%d:<a href="?cmd=chkin;nd=%s">%s</a>' % \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   173
                    (i2, h2, h2, ),
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   174
        else:
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   175
            print '&nbsp;&nbsp;%d:%s' % (i2, h2, ),
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   176
        print '</td></tr>'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   177
        print '\t<tr><td>manifest:</td><td colspan="3">%d:' % \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   178
                (self.repo.manifest.rev(changes[0]), ),
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   179
        print '<a href="?cmd=mf;nd=%s">%s</a></td></tr>' % \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   180
                (hg.hex(changes[0]), hg.hex(changes[0]), )
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   181
        print '\t<tr><td valign="top" width="10%">author:</td>' + \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   182
                '<td valign="top" width="20%%">%s</td>' % \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   183
                (obfuscate(changes[1]), )
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   184
        print '\t\t<td valign="top" width="10%">description:</td>' + \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   185
                '<td width="60%">' + \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   186
                '<a href="?cmd=chkin;nd=%s">%s</a></td></tr>' % \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   187
                (self.nodestr, nl2br(cgi.escape(changes[4])), )
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   188
        print '\t<tr><td>date:</td><td>%s UTC</td>' % (datestr, )
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   189
        print '\t\t<td valign="top">files:</td><td valign="top">'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   190
        for f in changes[3]:
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   191
            print '\t\t<a href="?cmd=file;nd=%s&fn=%s">%s</a>' % \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   192
                    (hg.hex(mf[f]), f, cgi.escape(f), ),
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   193
            print '&nbsp;&nbsp;'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   194
        print '\t</td></tr>'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   195
        print '</table><br />'
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   196
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   197
        (c, a, d) = self.repo.diffrevs(parents[0], self.node)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   198
        change = self.repo.changelog.read(parents[0])
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   199
        mf2 = self.repo.manifest.read(change[0])
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   200
        for f in c:
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   201
            self.show_diff(self.repo.file(f).read(mf2[f]), \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   202
                    self.repo.file(f).read(mf[f]), f)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   203
        for f in a:
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   204
            self.show_diff('', self.repo.file(f).read(mf[f]), f)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   205
        for f in d:
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   206
            self.show_diff(self.repo.file(f).read(mf2[f]), '', f)
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   207
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   208
class filepage(page):
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   209
    def __init__(self, repo, fn, node=None, cs=None):
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   210
        page.__init__(self)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   211
        self.repo = repo
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   212
        self.fn = fn
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   213
        if cs: 
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   214
            chng = self.repo.changelog.read(hg.bin(cs))
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   215
            mf = self.repo.manifest.read(chng[0])
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   216
            self.node = mf[self.fn]
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   217
            self.nodestr = hg.hex(self.node)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   218
        else:
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   219
            self.nodestr = node
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   220
            self.node = hg.bin(node)
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   221
        print '<div class="filename">%s (%s)</div>' % \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   222
                (cgi.escape(self.fn), self.nodestr, )
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   223
        print '<a href="?cmd=hist;fn=%s">history</a><br />' % self.fn
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   224
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   225
    def content(self):
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   226
        print '<pre>'
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   227
        print cgi.escape(self.repo.file(self.fn).read(self.node))
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   228
        print '</pre>'
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   229
101
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   230
class mfpage(page):
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   231
    def __init__(self, repo, node):
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   232
        page.__init__(self)
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   233
        self.repo = repo
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   234
        self.nodestr = node
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   235
        self.node = hg.bin(node)
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   236
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   237
    def content(self):
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   238
        mf = self.repo.manifest.read(self.node)
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   239
        fns = mf.keys()
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   240
        fns.sort()
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   241
        print '<div class="manifest">Manifest (%s)</div>' % self.nodestr
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   242
        for f in fns:
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   243
            print '<a href="?cmd=file;fn=%s;nd=%s">%s</a><br />' % \
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   244
                    (f, hg.hex(mf[f]), f)
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   245
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   246
class histpage(page):
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   247
    def __init__(self, repo, fn):
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   248
        page.__init__(self)
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   249
        self.repo = repo
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   250
        self.fn = fn
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   251
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   252
    def content(self):
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   253
        print '<div class="filehist">File History: %s</div>' % self.fn
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   254
        r = self.repo.file(self.fn)
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   255
        print '<br />'
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   256
        print '<table summary="" width="100%" align="center">'
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   257
        for i in xrange(r.count()-1, -1, -1):
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   258
            n = r.node(i)
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   259
            (p1, p2) = r.parents(n)
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   260
            (h, h1, h2) = map(hg.hex, (n, p1, p2))
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   261
            (i1, i2) = map(r.rev, (p1, p2))
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   262
            ci = r.linkrev(n)
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   263
            cn = self.repo.changelog.node(ci)
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   264
            cs = hg.hex(cn)
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   265
            changes = self.repo.changelog.read(cn)
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   266
            print '<tr><td>'
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   267
            self.hist_ent(i, h, i1, h1, i2, h2, ci, cs, changes)
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   268
            print '</tr></td>'
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   269
        print '</table>'
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   270
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   271
    def hist_ent(self, revi, revs, p1i, p1s, p2i, p2s, ci, cs, changes):
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   272
        datestr = time.asctime(time.gmtime(float(changes[2].split(' ')[0])))
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   273
        print '<table summary="" width="100%" border="1">'
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   274
        print '\t<tr><td valign="top" width="10%">author:</td>' + \
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   275
                '<td valign="top" width="20%%">%s</td>' % \
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   276
                (obfuscate(changes[1]), )
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   277
        print '\t\t<td valign="top" width="10%">description:</td>' + \
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   278
                '<td width="60%">' + \
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   279
                '<a href="?cmd=chkin;nd=%s">%s</a></td></tr>' % \
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   280
                (cs, nl2br(cgi.escape(changes[4])), )
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   281
        print '\t<tr><td>date:</td><td>%s UTC</td>' % (datestr, )
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   282
        print '\t\t<td>revision:</td><td>%d:<a ' % (revi, ) + \
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   283
                'href="?cmd=file;cs=%s;fn=%s">%s</a></td></tr>' % \
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   284
                (cs, self.fn, revs )
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   285
        print '\t<tr><td>parent(s):</td><td colspan="3">%d:' % (p1i, )
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   286
        print '<a href="?cmd=file;nd=%s;fn=%s">%s</a>' % (p1s, self.fn, p1s, ),
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   287
        if p2i != -1:
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   288
            print '&nbsp;&nbsp;%d:<a href="?cmd=file;nd=%s;fn=%s">%s</a>' % \
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   289
                    (p2i, p2s, self.fn, p2s ),
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   290
        print '</td></tr>'
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   291
        print '</table><br />'
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   292
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   293
args = cgi.parse()
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   294
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   295
ui = hg.ui()
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   296
repo = hg.repository(ui, repo_path)
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   297
101
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   298
if not args.has_key('cmd') or args['cmd'][0] == 'changes':
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   299
    page = change_list(repo, 'Mercurial')
101
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   300
    hi = args.get('hi', ( repo.changelog.count(), ))
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   301
    page.content(hi = int(hi[0]))
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   302
    page.endpage()
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   303
    
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   304
elif args['cmd'][0] == 'chkin':
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   305
    if not args.has_key('nd'):
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   306
        page = errpage()
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   307
        print '<div class="errmsg">No Node!</div>'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   308
    else:
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   309
        page = checkin(repo, args['nd'][0])
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   310
        page.content()
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   311
    page.endpage()
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   312
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   313
elif args['cmd'][0] == 'file':
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   314
    if not (args.has_key('nd') and args.has_key('fn')) and \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   315
            not (args.has_key('cs') and args.has_key('fn')):
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   316
        page = errpage()
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   317
        print '<div class="errmsg">Invalid Args!</div>'
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   318
    else:
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   319
        if args.has_key('nd'):
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   320
            page = filepage(repo, args['fn'][0], node=args['nd'][0])
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   321
        else:
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   322
            page = filepage(repo, args['fn'][0], cs=args['cs'][0])
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   323
        page.content()
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   324
    page.endpage()
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   325
101
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   326
elif args['cmd'][0] == 'mf':
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   327
    if not args.has_key('nd'):
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   328
        page = errpage()
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   329
        print '<div class="errmsg">No Node!</div>'
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   330
    else:
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   331
        page = mfpage(repo, args['nd'][0])
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   332
        page.content()
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   333
    page.endpage()
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   334
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   335
elif args['cmd'][0] == 'hist':
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   336
    if not args.has_key('fn'):
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   337
        page = errpage()
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   338
        print '<div class="errmsg">No Filename!</div>'
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   339
    else:
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   340
        page = histpage(repo, args['fn'][0])
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   341
        page.content()
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   342
    page.endpage()
6da5cf0c4193 added pagination for changes (front) page
jake@edge2.net
parents: 100
diff changeset
   343
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   344
elif args['cmd'][0] == 'branches':
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   345
    httphdr("text/plain")
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   346
    nodes = []
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   347
    if args.has_key('nodes'):
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   348
        nodes = map(hg.bin, args['nodes'][0].split(" "))
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   349
    for b in repo.branches(nodes):
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   350
        print " ".join(map(hg.hex, b))
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   351
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   352
elif args['cmd'][0] == 'between':
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   353
    httphdr("text/plain")
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   354
    nodes = []
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   355
    if args.has_key('pairs'):
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   356
        pairs = [ map(hg.bin, p.split("-"))
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   357
                  for p in args['pairs'][0].split(" ") ]
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   358
    for b in repo.between(pairs):
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   359
        print " ".join(map(hg.hex, b))
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   360
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   361
elif args['cmd'][0] == 'changegroup':
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   362
    httphdr("application/hg-changegroup")
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   363
    nodes = []
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   364
    if args.has_key('roots'):
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   365
        nodes = map(hg.bin, args['roots'][0].split(" "))
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   366
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   367
    z = zlib.compressobj()
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   368
    for chunk in repo.changegroup(nodes):
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   369
        sys.stdout.write(z.compress(chunk))
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   370
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   371
    sys.stdout.write(z.flush())
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   372
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   373
else:
100
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   374
    page = errpage()
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   375
    print '<div class="errmsg">unknown command: %s</div>' % \
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   376
            cgi.escape(args['cmd'][0])
526722d24ee5 reorganize code into classes
jake@edge2.net
parents: 99
diff changeset
   377
    page.endpage()