##// END OF EJS Templates
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht -
r13721:3458c15a default
parent child Browse files
Show More
@@ -22,7 +22,7 b' class webproto(object):'
22 22 if k == '*':
23 23 star = {}
24 24 for key in self.req.form.keys():
25 if key not in keys:
25 if key != 'cmd' and key not in keys:
26 26 star[key] = self.req.form[key][0]
27 27 data['*'] = star
28 28 else:
@@ -119,9 +119,24 b' class sshrepository(wireproto.wirereposi'
119 119 def _callstream(self, cmd, **args):
120 120 self.ui.debug("sending %s command\n" % cmd)
121 121 self.pipeo.write("%s\n" % cmd)
122 for k, v in sorted(args.iteritems()):
122 _func, names = wireproto.commands[cmd]
123 keys = names.split()
124 wireargs = {}
125 for k in keys:
126 if k == '*':
127 wireargs['*'] = args
128 break
129 else:
130 wireargs[k] = args[k]
131 del args[k]
132 for k, v in sorted(wireargs.iteritems()):
123 133 self.pipeo.write("%s %d\n" % (k, len(v)))
124 self.pipeo.write(v)
134 if isinstance(v, dict):
135 for dk, dv in v.iteritems():
136 self.pipeo.write("%s %d\n" % (dk, len(dv)))
137 self.pipeo.write(dv)
138 else:
139 self.pipeo.write(v)
125 140 self.pipeo.flush()
126 141
127 142 return self.pipei
@@ -30,17 +30,18 b' class sshserver(object):'
30 30 for n in xrange(len(keys)):
31 31 argline = self.fin.readline()[:-1]
32 32 arg, l = argline.split()
33 val = self.fin.read(int(l))
34 33 if arg not in keys:
35 34 raise util.Abort("unexpected parameter %r" % arg)
36 35 if arg == '*':
37 36 star = {}
38 for n in xrange(int(l)):
37 for k in xrange(int(l)):
38 argline = self.fin.readline()[:-1]
39 39 arg, l = argline.split()
40 40 val = self.fin.read(int(l))
41 41 star[arg] = val
42 42 data['*'] = star
43 43 else:
44 val = self.fin.read(int(l))
44 45 data[arg] = val
45 46 return [data[k] for k in keys]
46 47
@@ -161,6 +161,17 b' def dispatch(repo, proto, command):'
161 161 args = proto.getargs(spec)
162 162 return func(repo, proto, *args)
163 163
164 def options(cmd, keys, others):
165 opts = {}
166 for k in keys:
167 if k in others:
168 opts[k] = others[k]
169 del others[k]
170 if others:
171 sys.stderr.write("abort: %s got unexpected arguments %s\n"
172 % (cmd, ",".join(others)))
173 return opts
174
164 175 def between(repo, proto, pairs):
165 176 pairs = [decodelist(p, '-') for p in pairs.split(" ")]
166 177 r = []
@@ -208,8 +219,10 b' def changegroupsubset(repo, proto, bases'
208 219 cg = repo.changegroupsubset(bases, heads, 'serve')
209 220 return streamres(proto.groupchunks(cg))
210 221
211 def debugwireargs(repo, proto, one, two):
212 return repo.debugwireargs(one, two)
222 def debugwireargs(repo, proto, one, two, others):
223 # only accept optional args from the known set
224 opts = options('debugwireargs', ['three', 'four'], others)
225 return repo.debugwireargs(one, two, **opts)
213 226
214 227 def heads(repo, proto):
215 228 h = repo.heads()
@@ -355,7 +368,7 b' commands = {'
355 368 'capabilities': (capabilities, ''),
356 369 'changegroup': (changegroup, 'roots'),
357 370 'changegroupsubset': (changegroupsubset, 'bases heads'),
358 'debugwireargs': (debugwireargs, 'one two'),
371 'debugwireargs': (debugwireargs, 'one two *'),
359 372 'heads': (heads, ''),
360 373 'hello': (hello, ''),
361 374 'listkeys': (listkeys, 'namespace'),
@@ -7,6 +7,10 b' Setup repo:'
7 7
8 8 Local:
9 9
10 $ hg debugwireargs repo eins zwei --three drei --four vier
11 eins zwei drei vier
12 $ hg debugwireargs repo eins zwei --four vier
13 eins zwei None vier
10 14 $ hg debugwireargs repo eins zwei
11 15 eins zwei None None
12 16
@@ -15,10 +19,20 b' HTTP:'
15 19 $ hg serve -R repo -p $HGPORT -d --pid-file=hg1.pid -E error.log -A access.log
16 20 $ cat hg1.pid >> $DAEMON_PIDS
17 21
22 $ hg debugwireargs http://localhost:$HGPORT/ un deux trois quatre
23 un deux trois quatre
24 $ hg debugwireargs http://localhost:$HGPORT/ eins zwei --four vier
25 eins zwei None vier
18 26 $ hg debugwireargs http://localhost:$HGPORT/ eins zwei
19 27 eins zwei None None
20 28 $ cat access.log
21 29 * - - [*] "GET /?cmd=capabilities HTTP/1.1" 200 - (glob)
30 * - - [*] "GET /?cmd=debugwireargs&four=quatre&one=un&three=trois&two=deux HTTP/1.1" 200 - (glob)
31 * - - [*] "GET /?cmd=debugwireargs&four=quatre&one=un&three=trois&two=deux HTTP/1.1" 200 - (glob)
32 * - - [*] "GET /?cmd=capabilities HTTP/1.1" 200 - (glob)
33 * - - [*] "GET /?cmd=debugwireargs&four=vier&one=eins&two=zwei HTTP/1.1" 200 - (glob)
34 * - - [*] "GET /?cmd=debugwireargs&four=vier&one=eins&two=zwei HTTP/1.1" 200 - (glob)
35 * - - [*] "GET /?cmd=capabilities HTTP/1.1" 200 - (glob)
22 36 * - - [*] "GET /?cmd=debugwireargs&one=eins&two=zwei HTTP/1.1" 200 - (glob)
23 37 * - - [*] "GET /?cmd=debugwireargs&one=eins&two=zwei HTTP/1.1" 200 - (glob)
24 38
@@ -37,6 +51,10 b' SSH (try to exercise the ssh functionali'
37 51 > sys.exit(bool(r))
38 52 > EOF
39 53
54 $ hg debugwireargs --ssh "python ./dummyssh" ssh://user@dummy/repo uno due tre quattro
55 uno due tre quattro
56 $ hg debugwireargs --ssh "python ./dummyssh" ssh://user@dummy/repo eins zwei --four vier
57 eins zwei None vier
40 58 $ hg debugwireargs --ssh "python ./dummyssh" ssh://user@dummy/repo eins zwei
41 59 eins zwei None None
42 60
General Comments 0
You need to be logged in to leave comments. Login now