##// 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 if k == '*':
22 if k == '*':
23 star = {}
23 star = {}
24 for key in self.req.form.keys():
24 for key in self.req.form.keys():
25 if key not in keys:
25 if key != 'cmd' and key not in keys:
26 star[key] = self.req.form[key][0]
26 star[key] = self.req.form[key][0]
27 data['*'] = star
27 data['*'] = star
28 else:
28 else:
@@ -119,8 +119,23 b' class sshrepository(wireproto.wirereposi'
119 def _callstream(self, cmd, **args):
119 def _callstream(self, cmd, **args):
120 self.ui.debug("sending %s command\n" % cmd)
120 self.ui.debug("sending %s command\n" % cmd)
121 self.pipeo.write("%s\n" % cmd)
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 self.pipeo.write("%s %d\n" % (k, len(v)))
133 self.pipeo.write("%s %d\n" % (k, len(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:
124 self.pipeo.write(v)
139 self.pipeo.write(v)
125 self.pipeo.flush()
140 self.pipeo.flush()
126
141
@@ -30,17 +30,18 b' class sshserver(object):'
30 for n in xrange(len(keys)):
30 for n in xrange(len(keys)):
31 argline = self.fin.readline()[:-1]
31 argline = self.fin.readline()[:-1]
32 arg, l = argline.split()
32 arg, l = argline.split()
33 val = self.fin.read(int(l))
34 if arg not in keys:
33 if arg not in keys:
35 raise util.Abort("unexpected parameter %r" % arg)
34 raise util.Abort("unexpected parameter %r" % arg)
36 if arg == '*':
35 if arg == '*':
37 star = {}
36 star = {}
38 for n in xrange(int(l)):
37 for k in xrange(int(l)):
38 argline = self.fin.readline()[:-1]
39 arg, l = argline.split()
39 arg, l = argline.split()
40 val = self.fin.read(int(l))
40 val = self.fin.read(int(l))
41 star[arg] = val
41 star[arg] = val
42 data['*'] = star
42 data['*'] = star
43 else:
43 else:
44 val = self.fin.read(int(l))
44 data[arg] = val
45 data[arg] = val
45 return [data[k] for k in keys]
46 return [data[k] for k in keys]
46
47
@@ -161,6 +161,17 b' def dispatch(repo, proto, command):'
161 args = proto.getargs(spec)
161 args = proto.getargs(spec)
162 return func(repo, proto, *args)
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 def between(repo, proto, pairs):
175 def between(repo, proto, pairs):
165 pairs = [decodelist(p, '-') for p in pairs.split(" ")]
176 pairs = [decodelist(p, '-') for p in pairs.split(" ")]
166 r = []
177 r = []
@@ -208,8 +219,10 b' def changegroupsubset(repo, proto, bases'
208 cg = repo.changegroupsubset(bases, heads, 'serve')
219 cg = repo.changegroupsubset(bases, heads, 'serve')
209 return streamres(proto.groupchunks(cg))
220 return streamres(proto.groupchunks(cg))
210
221
211 def debugwireargs(repo, proto, one, two):
222 def debugwireargs(repo, proto, one, two, others):
212 return repo.debugwireargs(one, two)
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 def heads(repo, proto):
227 def heads(repo, proto):
215 h = repo.heads()
228 h = repo.heads()
@@ -355,7 +368,7 b' commands = {'
355 'capabilities': (capabilities, ''),
368 'capabilities': (capabilities, ''),
356 'changegroup': (changegroup, 'roots'),
369 'changegroup': (changegroup, 'roots'),
357 'changegroupsubset': (changegroupsubset, 'bases heads'),
370 'changegroupsubset': (changegroupsubset, 'bases heads'),
358 'debugwireargs': (debugwireargs, 'one two'),
371 'debugwireargs': (debugwireargs, 'one two *'),
359 'heads': (heads, ''),
372 'heads': (heads, ''),
360 'hello': (hello, ''),
373 'hello': (hello, ''),
361 'listkeys': (listkeys, 'namespace'),
374 'listkeys': (listkeys, 'namespace'),
@@ -7,6 +7,10 b' Setup repo:'
7
7
8 Local:
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 $ hg debugwireargs repo eins zwei
14 $ hg debugwireargs repo eins zwei
11 eins zwei None None
15 eins zwei None None
12
16
@@ -15,10 +19,20 b' HTTP:'
15 $ hg serve -R repo -p $HGPORT -d --pid-file=hg1.pid -E error.log -A access.log
19 $ hg serve -R repo -p $HGPORT -d --pid-file=hg1.pid -E error.log -A access.log
16 $ cat hg1.pid >> $DAEMON_PIDS
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 $ hg debugwireargs http://localhost:$HGPORT/ eins zwei
26 $ hg debugwireargs http://localhost:$HGPORT/ eins zwei
19 eins zwei None None
27 eins zwei None None
20 $ cat access.log
28 $ cat access.log
21 * - - [*] "GET /?cmd=capabilities HTTP/1.1" 200 - (glob)
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 * - - [*] "GET /?cmd=debugwireargs&one=eins&two=zwei HTTP/1.1" 200 - (glob)
36 * - - [*] "GET /?cmd=debugwireargs&one=eins&two=zwei HTTP/1.1" 200 - (glob)
23 * - - [*] "GET /?cmd=debugwireargs&one=eins&two=zwei HTTP/1.1" 200 - (glob)
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 > sys.exit(bool(r))
51 > sys.exit(bool(r))
38 > EOF
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 $ hg debugwireargs --ssh "python ./dummyssh" ssh://user@dummy/repo eins zwei
58 $ hg debugwireargs --ssh "python ./dummyssh" ssh://user@dummy/repo eins zwei
41 eins zwei None None
59 eins zwei None None
42
60
General Comments 0
You need to be logged in to leave comments. Login now