hgweb.py
author mpm@selenic.com
Wed, 18 May 2005 16:45:44 -0800
changeset 96 fce47326677c
parent 61 1215bf60468f
child 99 db5eb6a86179
child 102 58039eddbdda
permissions -rw-r--r--
Add updated merge3 code
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
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
    27
def httphdr(type = "text/html"):
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
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    30
def htmldoctype():
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    31
    print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    32
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    33
def htmlhead(title):
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    34
    print '<HTML>'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    35
    print '<!-- created by hgweb 0.1 - jake@edge2.net -->'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    36
    print '<HEAD><TITLE>%s</TITLE></HEAD>' % (title, )
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    37
    print '<style type="text/css">'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    38
    print 'body { font-family: sans-serif; font-size: 12px; }'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    39
    print 'table { font-size: 12px; }'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    40
    print '.errmsg { font-size: 200%; color: red; }'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    41
    print '.filename { font-size: 150%; color: purple; }'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    42
    print '.plusline { color: green; }'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    43
    print '.minusline { color: red; }'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    44
    print '.atline { color: purple; }'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    45
    print '</style>'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    46
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
    47
def startpage(title):
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
    48
    httphdr()
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
    49
    htmldoctype()
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
    50
    htmlhead(title)
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
    51
    print '<BODY>'
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
    52
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
    53
def endpage():
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
    54
    print '</BODY>'
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
    55
    print '</HTML>'
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
    56
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
    57
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
    58
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    59
def ent_change(repo, nodeid):
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    60
    changes = repo.changelog.read(nodeid)
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    61
    hn = hg.hex(nodeid)
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    62
    i = repo.changelog.rev(nodeid)
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    63
    (h1, h2) = [ hg.hex(x) for x in repo.changelog.parents(nodeid) ]
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    64
    datestr = time.asctime(time.gmtime(float(changes[2].split(' ')[0])))
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    65
    print '<table width="100%" border="1">'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    66
    print '\t<tr><td valign="top" width="10%%">author:</td>' + \
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    67
            '<td valign="top" width="20%%">%s</td>' % (obfuscate(changes[1]), )
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    68
    print '\t\t<td valign="top" width="10%%">description:</td>' + \
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    69
            '<td width="60%%">' + \
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    70
            '<a href="?cmd=chkin;nd=%s">%s</a></td></tr>' % \
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    71
            (hn, nl2br(changes[4]), )
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    72
    print '\t<tr><td>date:</td><td>%s UTC</td>' % (datestr, )
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    73
    print '\t\t<td valign="top">files:</td><td valign="top">'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    74
    for f in changes[3]:
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
    75
        print '\t\t%s&nbsp;&nbsp;' % f
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    76
    print '\t</td></tr>'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    77
#    print '\t<tr><td>revision:</td><td colspan="3">%d:<a ' % (i, ) + \
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    78
#            'href="?cmd=rev;nd=%s">%s</a></td></tr>' % (hn, hn, )
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    79
    print '</table><br />'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    80
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    81
def ent_diff(a, b, fn):
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    82
    a = a.splitlines(1)
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    83
    b = b.splitlines(1)
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    84
    l = difflib.unified_diff(a, b, fn, fn)
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    85
    print '<pre>'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    86
    for line in l:
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    87
        line = cgi.escape(line[:-1])
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    88
        if line.startswith('+'):
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    89
            print '<span class="plusline">%s</span>' % (line, )
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    90
        elif line.startswith('-'):
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    91
            print '<span class="minusline">%s</span>' % (line, )
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    92
        elif line.startswith('@'):
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    93
            print '<span class="atline">%s</span>' % (line, )
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    94
        else:
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    95
            print line
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    96
    print '</pre>'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    97
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
    98
def ent_checkin(repo, nodeid):
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
    99
    startpage("Mercurial Web")
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   100
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   101
    changes = repo.changelog.read(nodeid)
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   102
    hn = hg.hex(nodeid)
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   103
    i = repo.changelog.rev(nodeid)
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   104
    parents = repo.changelog.parents(nodeid)
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   105
    (h1, h2) = [ hg.hex(x) for x in parents ]
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   106
    (i1, i2) = [ repo.changelog.rev(x) for x in parents ]
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   107
    datestr = time.asctime(time.gmtime(float(changes[2].split(' ')[0])))
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   108
    mf = repo.manifest.read(changes[0])
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   109
    print '<table width="100%" border="1">'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   110
    print '\t<tr><td>revision:</td><td colspan="3">%d:' % (i, ),
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   111
    print '<a href="?cmd=rev;nd=%s">%s</a></td></tr>' % (hn, hn, )
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   112
    print '\t<tr><td>parent(s):</td><td colspan="3">%d:' % (i1, )
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   113
    print '<a href="?cmd=rev;nd=%s">%s</a>' % (h1, h1, ),
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   114
    if i2 != -1:
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   115
        print '&nbsp;&nbsp;%d:<a href="?cmd=rev;nd=%s">%s</a>' % \
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   116
                (i2, h2, h2, ),
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   117
    else:
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   118
        print '&nbsp;&nbsp;%d:%s' % (i2, h2, ),
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   119
    print '</td></tr>'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   120
    print '\t<tr><td>manifest:</td><td colspan="3">%d:' % \
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   121
            (repo.manifest.rev(changes[0]), ),
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   122
    print '<a href="?cmd=mf;nd=%s">%s</a></td></tr>' % \
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   123
            (hg.hex(changes[0]), hg.hex(changes[0]), )
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   124
    print '\t<tr><td valign="top" width="10%%">author:</td>' + \
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   125
            '<td valign="top" width="20%%">%s</td>' % (obfuscate(changes[1]), )
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   126
    print '\t\t<td valign="top" width="10%%">description:</td>' + \
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   127
            '<td width="60%%">' + \
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   128
            '<a href="?cmd=chkin;nd=%s">%s</a></td></tr>' % \
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   129
            (hn, nl2br(changes[4]), )
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   130
    print '\t<tr><td>date:</td><td>%s UTC</td>' % (datestr, )
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   131
    print '\t\t<td valign="top">files:</td><td valign="top">'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   132
    for f in changes[3]:
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   133
        print '\t\t<a href="?cmd=file;nd=%s&fn=%s">%s</a>' % \
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   134
                (hg.hex(mf[f]), f, f, ),
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   135
        print '&nbsp;&nbsp;'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   136
    print '\t</td></tr>'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   137
    print '</table><br />'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   138
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   139
    (c, a, d) = repo.diffrevs(parents[0], nodeid)
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   140
    change = repo.changelog.read(parents[0])
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   141
    mf2 = repo.manifest.read(change[0])
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   142
    for f in c:
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   143
        ent_diff(repo.file(f).read(mf2[f]), repo.file(f).read(mf[f]), f)
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   144
    for f in a:
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   145
        ent_diff('', repo.file(f).read(mf[f]), f)
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   146
    for f in d:
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   147
        ent_diff(repo.file(f).read(mf2[f]), '', f)
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   148
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   149
    endpage()
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   150
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   151
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   152
def ent_file(repo, nodeid, fn):
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   153
    print '<div class="filename">%s (%s)</div>' % (fn, hg.hex(nodeid), )
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   154
    print '<pre>'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   155
    print cgi.escape(repo.file(fn).read(nodeid))
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   156
    print '</pre>'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   157
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   158
def change_page():
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   159
    startpage("Mercurial Web")
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   160
    print '<table width="100%" align="center">'
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   161
    for i in xrange(0, repo.changelog.count()):
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   162
        n = repo.changelog.node(i)
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   163
        print '<tr><td>'
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   164
        ent_change(repo, n)
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   165
        print '</td></th>'
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   166
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   167
    print '</table>'
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   168
    endpage()
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   169
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   170
args = cgi.parse()
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   171
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   172
ui = hg.ui()
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   173
repo = hg.repository(ui, repo_path)
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   174
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   175
if not args.has_key('cmd'):
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   176
    change_page()
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   177
    
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   178
elif args['cmd'][0] == 'chkin':
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   179
    if not args.has_key('nd'):
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   180
        print '<div class="errmsg">No Node!</div>'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   181
    else:
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   182
        ent_checkin(repo, hg.bin(args['nd'][0]))
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   183
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   184
elif args['cmd'][0] == 'file':
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   185
    startpage("Mercurial Web")
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   186
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   187
    if not args.has_key('nd'):
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   188
        print '<div class="errmsg">No Node!</div>'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   189
    elif not args.has_key('fn'):
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   190
        print '<div class="errmsg">No Filename!</div>'
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   191
    else:
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   192
        ent_file(repo, hg.bin(args['nd'][0]), args['fn'][0])
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   193
    endpage()
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   194
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   195
elif args['cmd'][0] == 'branches':
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   196
    httphdr("text/plain")
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   197
    nodes = []
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   198
    if args.has_key('nodes'):
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   199
        nodes = map(hg.bin, args['nodes'][0].split(" "))
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   200
    for b in repo.branches(nodes):
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   201
        print " ".join(map(hg.hex, b))
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   202
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   203
elif args['cmd'][0] == 'between':
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   204
    httphdr("text/plain")
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   205
    nodes = []
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   206
    if args.has_key('pairs'):
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   207
        pairs = [ map(hg.bin, p.split("-"))
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   208
                  for p in args['pairs'][0].split(" ") ]
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   209
    for b in repo.between(pairs):
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   210
        print " ".join(map(hg.hex, b))
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   211
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   212
elif args['cmd'][0] == 'changegroup':
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   213
    httphdr("application/hg-changegroup")
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   214
    nodes = []
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   215
    if args.has_key('roots'):
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   216
        nodes = map(hg.bin, args['roots'][0].split(" "))
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   217
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   218
    z = zlib.compressobj()
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   219
    for chunk in repo.changegroup(nodes):
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   220
        sys.stdout.write(z.compress(chunk))
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   221
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   222
    sys.stdout.write(z.flush())
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   223
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   224
else:
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   225
    startpage("Mercurial Web Error")
57
115106376f45 hgweb.py from Jake Edge
mpm@selenic.com
parents:
diff changeset
   226
    print '<div class="errmsg">unknown command: ', args['cmd'][0], '</div>'
61
1215bf60468f Add server side of hg:// protocol to hgweb
mpm@selenic.com
parents: 57
diff changeset
   227
    endpage()