comparison upmana/mercurial/hgweb/protocol.py @ 121:496dbf12a6cb alpha

Traipse Alpha 'OpenRPG' {091030-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Cleaning up for Beta): Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images! Changes made to the map for increased portability. SnowDog has changes planned in Core, though. Added an initial push to the BCG. Not much to see, just shows off how it is re-writing Main code. Fix to remote admin commands Minor fix to texted based server, works in /System/ folder Some Core changes to gametree to correctly disply Pretty Print, thanks David! Fix to Splitter Nodes not being created. Added images to Plugin Control panel for Autostart feature Fix to massive amounts of images loading; from Core fix to gsclient so with_statement imports Added 'boot' command to remote admin Prep work in Pass tool for remote admin rankings and different passwords, ei, Server, Admin, Moderator, etc. Remote Admin Commands more organized, more prep work. Added Confirmation window for sent nodes. Minor changes to allow for portability to an OpenSUSE linux OS (hopefully without breaking) {091028} Made changes to gametree to start working with Element Tree, mostly from Core Minor changes to Map to start working with Element Tree, from Core Preliminary changes to map efficiency, from FlexiRPG Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Changes to main.py to start working with Element Tree {091029} Changes made to server to start working with Element Tree. Changes made to Meta Server Lib. Prepping test work for a multi meta network page. Minor bug fixed with mini to gametree Zoom Mouse plugin added. {091030} Getting ready for Beta. Server needs debugging so Alpha remains bugged. Plugin UI code cleaned. Auto start works with a graphic, pop-up asks to enable or disable plugin. Update Manager now has a partially working Status Bar. Status Bar captures terminal text, so Merc out put is visible. Manifest.xml file, will be renamed, is now much cleaner. Debug Console has a clear button and a Report Bug button. Prep work for a Term2Win class in Debug Console. Known: Current Alpha fails in Windows.
author sirebral
date Fri, 30 Oct 2009 22:21:40 -0500
parents
children 36919b8a3ef9
comparison
equal deleted inserted replaced
120:d86e762a994f 121:496dbf12a6cb
1 #
2 # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net>
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
4 #
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2, incorporated herein by reference.
7
8 import cStringIO, zlib, tempfile, errno, os, sys, urllib
9 from mercurial import util, streamclone
10 from mercurial.node import bin, hex
11 from mercurial import changegroup as changegroupmod
12 from common import ErrorResponse, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
13
14 # __all__ is populated with the allowed commands. Be sure to add to it if
15 # you're adding a new command, or the new command won't work.
16
17 __all__ = [
18 'lookup', 'heads', 'branches', 'between', 'changegroup',
19 'changegroupsubset', 'capabilities', 'unbundle', 'stream_out',
20 'branchmap',
21 ]
22
23 HGTYPE = 'application/mercurial-0.1'
24
25 def lookup(repo, req):
26 try:
27 r = hex(repo.lookup(req.form['key'][0]))
28 success = 1
29 except Exception,inst:
30 r = str(inst)
31 success = 0
32 resp = "%s %s\n" % (success, r)
33 req.respond(HTTP_OK, HGTYPE, length=len(resp))
34 yield resp
35
36 def heads(repo, req):
37 resp = " ".join(map(hex, repo.heads())) + "\n"
38 req.respond(HTTP_OK, HGTYPE, length=len(resp))
39 yield resp
40
41 def branchmap(repo, req):
42 branches = repo.branchmap()
43 heads = []
44 for branch, nodes in branches.iteritems():
45 branchname = urllib.quote(branch)
46 branchnodes = [hex(node) for node in nodes]
47 heads.append('%s %s' % (branchname, ' '.join(branchnodes)))
48 resp = '\n'.join(heads)
49 req.respond(HTTP_OK, HGTYPE, length=len(resp))
50 yield resp
51
52 def branches(repo, req):
53 nodes = []
54 if 'nodes' in req.form:
55 nodes = map(bin, req.form['nodes'][0].split(" "))
56 resp = cStringIO.StringIO()
57 for b in repo.branches(nodes):
58 resp.write(" ".join(map(hex, b)) + "\n")
59 resp = resp.getvalue()
60 req.respond(HTTP_OK, HGTYPE, length=len(resp))
61 yield resp
62
63 def between(repo, req):
64 if 'pairs' in req.form:
65 pairs = [map(bin, p.split("-"))
66 for p in req.form['pairs'][0].split(" ")]
67 resp = cStringIO.StringIO()
68 for b in repo.between(pairs):
69 resp.write(" ".join(map(hex, b)) + "\n")
70 resp = resp.getvalue()
71 req.respond(HTTP_OK, HGTYPE, length=len(resp))
72 yield resp
73
74 def changegroup(repo, req):
75 req.respond(HTTP_OK, HGTYPE)
76 nodes = []
77
78 if 'roots' in req.form:
79 nodes = map(bin, req.form['roots'][0].split(" "))
80
81 z = zlib.compressobj()
82 f = repo.changegroup(nodes, 'serve')
83 while 1:
84 chunk = f.read(4096)
85 if not chunk:
86 break
87 yield z.compress(chunk)
88
89 yield z.flush()
90
91 def changegroupsubset(repo, req):
92 req.respond(HTTP_OK, HGTYPE)
93 bases = []
94 heads = []
95
96 if 'bases' in req.form:
97 bases = [bin(x) for x in req.form['bases'][0].split(' ')]
98 if 'heads' in req.form:
99 heads = [bin(x) for x in req.form['heads'][0].split(' ')]
100
101 z = zlib.compressobj()
102 f = repo.changegroupsubset(bases, heads, 'serve')
103 while 1:
104 chunk = f.read(4096)
105 if not chunk:
106 break
107 yield z.compress(chunk)
108
109 yield z.flush()
110
111 def capabilities(repo, req):
112 caps = ['lookup', 'changegroupsubset', 'branchmap']
113 if repo.ui.configbool('server', 'uncompressed', untrusted=True):
114 caps.append('stream=%d' % repo.changelog.version)
115 if changegroupmod.bundlepriority:
116 caps.append('unbundle=%s' % ','.join(changegroupmod.bundlepriority))
117 rsp = ' '.join(caps)
118 req.respond(HTTP_OK, HGTYPE, length=len(rsp))
119 yield rsp
120
121 def unbundle(repo, req):
122
123 proto = req.env.get('wsgi.url_scheme') or 'http'
124 their_heads = req.form['heads'][0].split(' ')
125
126 def check_heads():
127 heads = map(hex, repo.heads())
128 return their_heads == [hex('force')] or their_heads == heads
129
130 # fail early if possible
131 if not check_heads():
132 req.drain()
133 raise ErrorResponse(HTTP_OK, 'unsynced changes')
134
135 # do not lock repo until all changegroup data is
136 # streamed. save to temporary file.
137
138 fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-')
139 fp = os.fdopen(fd, 'wb+')
140 try:
141 length = int(req.env['CONTENT_LENGTH'])
142 for s in util.filechunkiter(req, limit=length):
143 fp.write(s)
144
145 try:
146 lock = repo.lock()
147 try:
148 if not check_heads():
149 raise ErrorResponse(HTTP_OK, 'unsynced changes')
150
151 fp.seek(0)
152 header = fp.read(6)
153 if header.startswith('HG') and not header.startswith('HG10'):
154 raise ValueError('unknown bundle version')
155 elif header not in changegroupmod.bundletypes:
156 raise ValueError('unknown bundle compression type')
157 gen = changegroupmod.unbundle(header, fp)
158
159 # send addchangegroup output to client
160
161 oldio = sys.stdout, sys.stderr
162 sys.stderr = sys.stdout = cStringIO.StringIO()
163
164 try:
165 url = 'remote:%s:%s:%s' % (
166 proto,
167 urllib.quote(req.env.get('REMOTE_HOST', '')),
168 urllib.quote(req.env.get('REMOTE_USER', '')))
169 try:
170 ret = repo.addchangegroup(gen, 'serve', url)
171 except util.Abort, inst:
172 sys.stdout.write("abort: %s\n" % inst)
173 ret = 0
174 finally:
175 val = sys.stdout.getvalue()
176 sys.stdout, sys.stderr = oldio
177 req.respond(HTTP_OK, HGTYPE)
178 return '%d\n%s' % (ret, val),
179 finally:
180 lock.release()
181 except ValueError, inst:
182 raise ErrorResponse(HTTP_OK, inst)
183 except (OSError, IOError), inst:
184 filename = getattr(inst, 'filename', '')
185 # Don't send our filesystem layout to the client
186 if filename.startswith(repo.root):
187 filename = filename[len(repo.root)+1:]
188 else:
189 filename = ''
190 error = getattr(inst, 'strerror', 'Unknown error')
191 if inst.errno == errno.ENOENT:
192 code = HTTP_NOT_FOUND
193 else:
194 code = HTTP_SERVER_ERROR
195 raise ErrorResponse(code, '%s: %s' % (error, filename))
196 finally:
197 fp.close()
198 os.unlink(tempname)
199
200 def stream_out(repo, req):
201 req.respond(HTTP_OK, HGTYPE)
202 try:
203 for chunk in streamclone.stream_out(repo, untrusted=True):
204 yield chunk
205 except streamclone.StreamException, inst:
206 yield str(inst)