# HG changeset patch # User mpm@selenic.com # Date 1115889757 28800 # Node ID 1215bf60468f4f8bde16fa3a5c3d1d94b5732fae # Parent e32fdbd978396c92d1d18f64ba143c810af0fd01 Add server side of hg:// protocol to hgweb diff -r e32fdbd97839 -r 1215bf60468f hgweb.py --- a/hgweb.py Thu May 12 01:21:58 2005 -0800 +++ b/hgweb.py Thu May 12 01:22:37 2005 -0800 @@ -10,7 +10,7 @@ import cgitb cgitb.enable() -import os, cgi, time, re, difflib +import os, cgi, time, re, difflib, sys, zlib from mercurial import hg, mdiff repo_path = "." # change as needed @@ -24,8 +24,8 @@ l.append('&#%d;' % ord(c)) return ''.join(l) -def httphdr(): - print 'Content-type: text/html\n\n' +def httphdr(type = "text/html"): + print 'Content-type: %s\n' % type def htmldoctype(): print '' @@ -44,13 +44,24 @@ print '.atline { color: purple; }' print '' +def startpage(title): + httphdr() + htmldoctype() + htmlhead(title) + print '' + +def endpage(): + print '' + print '' + + + def ent_change(repo, nodeid): changes = repo.changelog.read(nodeid) hn = hg.hex(nodeid) i = repo.changelog.rev(nodeid) (h1, h2) = [ hg.hex(x) for x in repo.changelog.parents(nodeid) ] datestr = time.asctime(time.gmtime(float(changes[2].split(' ')[0]))) - mf = repo.manifest.read(changes[0]) print '' print '\t' + \ '' % (obfuscate(changes[1]), ) @@ -61,9 +72,7 @@ print '\t' % (datestr, ) print '\t\t' # print '\t' % (hn, hn, ) @@ -87,6 +96,8 @@ print '' def ent_checkin(repo, nodeid): + startpage("Mercurial Web") + changes = repo.changelog.read(nodeid) hn = hg.hex(nodeid) i = repo.changelog.rev(nodeid) @@ -135,18 +146,26 @@ for f in d: ent_diff(repo.file(f).read(mf2[f]), '', f) + endpage() + + def ent_file(repo, nodeid, fn): print '
%s (%s)
' % (fn, hg.hex(nodeid), ) print '
'
     print cgi.escape(repo.file(fn).read(nodeid))
     print '
' -httphdr() -htmldoctype() -htmlhead('Mercurial Web') +def change_page(): + startpage("Mercurial Web") + print '
author:%s
date:%s UTCfiles:' for f in changes[3]: - print '\t\t%s' % \ - (hg.hex(mf[f]), f, f, ), - print '  ' + print '\t\t%s  ' % f print '\t
revision:%d:%s
' + for i in xrange(0, repo.changelog.count()): + n = repo.changelog.node(i) + print '' -print '' - + print '
' + ent_change(repo, n) + print '
' + endpage() args = cgi.parse() @@ -154,29 +173,55 @@ repo = hg.repository(ui, repo_path) if not args.has_key('cmd'): - print '' - for i in xrange(repo.changelog.count()-1, -1, -1): - n = repo.changelog.node(i) - print '' - - print '
' - ent_change(repo, n) - print '
' + change_page() + elif args['cmd'][0] == 'chkin': if not args.has_key('nd'): print '
No Node!
' else: ent_checkin(repo, hg.bin(args['nd'][0])) + elif args['cmd'][0] == 'file': + startpage("Mercurial Web") + if not args.has_key('nd'): print '
No Node!
' elif not args.has_key('fn'): print '
No Filename!
' else: ent_file(repo, hg.bin(args['nd'][0]), args['fn'][0]) + endpage() + +elif args['cmd'][0] == 'branches': + httphdr("text/plain") + nodes = [] + if args.has_key('nodes'): + nodes = map(hg.bin, args['nodes'][0].split(" ")) + for b in repo.branches(nodes): + print " ".join(map(hg.hex, b)) + +elif args['cmd'][0] == 'between': + httphdr("text/plain") + nodes = [] + if args.has_key('pairs'): + pairs = [ map(hg.bin, p.split("-")) + for p in args['pairs'][0].split(" ") ] + for b in repo.between(pairs): + print " ".join(map(hg.hex, b)) + +elif args['cmd'][0] == 'changegroup': + httphdr("application/hg-changegroup") + nodes = [] + if args.has_key('roots'): + nodes = map(hg.bin, args['roots'][0].split(" ")) + + z = zlib.compressobj() + for chunk in repo.changegroup(nodes): + sys.stdout.write(z.compress(chunk)) + + sys.stdout.write(z.flush()) else: + startpage("Mercurial Web Error") print '
unknown command: ', args['cmd'][0], '
' - -print '' -print '' + endpage()