Mercurial > hg-stable
annotate mercurial/wireproto.py @ 13720:9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Tests argument passing locally, via HTTP, and via SSH. This is mainly preparation
for the next patch.
author | Peter Arrenbrecht <peter.arrenbrecht@gmail.com> |
---|---|
date | Tue, 22 Mar 2011 07:38:32 +0100 |
parents | b3f9af7c22c5 |
children | 3458c15ab2f0 |
rev | line source |
---|---|
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
1 # wireproto.py - generic wire protocol support functions |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
2 # |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
3 # Copyright 2005-2010 Matt Mackall <mpm@selenic.com> |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
4 # |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
7 |
11879
4e804302d30c
fix undefined variables, spotted by pylint
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11627
diff
changeset
|
8 import urllib, tempfile, os, sys |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
9 from i18n import _ |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
10 from node import bin, hex |
11593
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
11 import changegroup as changegroupmod |
11627
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
12 import repo, error, encoding, util, store |
12085
6f833fc3ccab
Consistently import foo as foomod when foo to avoid shadowing
Martin Geisler <mg@aragost.com>
parents:
12063
diff
changeset
|
13 import pushkey as pushkeymod |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
14 |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
15 # list of nodes encoding / decoding |
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
16 |
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
17 def decodelist(l, sep=' '): |
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
18 return map(bin, l.split(sep)) |
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
19 |
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
20 def encodelist(l, sep=' '): |
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
21 return sep.join(map(hex, l)) |
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
22 |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
23 # client side |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
24 |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
25 class wirerepository(repo.repository): |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
26 def lookup(self, key): |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
27 self.requirecap('lookup', _('look up remote revision')) |
13049
d588326f6321
wireproto: use proper UTF-8 handling for key lookup
Matt Mackall <mpm@selenic.com>
parents:
13047
diff
changeset
|
28 d = self._call("lookup", key=encoding.fromlocal(key)) |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
29 success, data = d[:-1].split(" ", 1) |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
30 if int(success): |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
31 return bin(data) |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
32 self._abort(error.RepoError(data)) |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
33 |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
34 def heads(self): |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
35 d = self._call("heads") |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
36 try: |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
37 return decodelist(d[:-1]) |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
38 except: |
11879
4e804302d30c
fix undefined variables, spotted by pylint
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11627
diff
changeset
|
39 self._abort(error.ResponseError(_("unexpected response:"), d)) |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
40 |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
41 def branchmap(self): |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
42 d = self._call("branchmap") |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
43 try: |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
44 branchmap = {} |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
45 for branchpart in d.splitlines(): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
46 branchname, branchheads = branchpart.split(' ', 1) |
13047
6c375e07d673
branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents:
12703
diff
changeset
|
47 branchname = encoding.tolocal(urllib.unquote(branchname)) |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
48 branchheads = decodelist(branchheads) |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
49 branchmap[branchname] = branchheads |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
50 return branchmap |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
51 except TypeError: |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
52 self._abort(error.ResponseError(_("unexpected response:"), d)) |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
53 |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
54 def branches(self, nodes): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
55 n = encodelist(nodes) |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
56 d = self._call("branches", nodes=n) |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
57 try: |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
58 br = [tuple(decodelist(b)) for b in d.splitlines()] |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
59 return br |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
60 except: |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
61 self._abort(error.ResponseError(_("unexpected response:"), d)) |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
62 |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
63 def between(self, pairs): |
11587
a036f6bd1da3
protocol: unify basic http client requests
Matt Mackall <mpm@selenic.com>
parents:
11586
diff
changeset
|
64 batch = 8 # avoid giant requests |
a036f6bd1da3
protocol: unify basic http client requests
Matt Mackall <mpm@selenic.com>
parents:
11586
diff
changeset
|
65 r = [] |
a036f6bd1da3
protocol: unify basic http client requests
Matt Mackall <mpm@selenic.com>
parents:
11586
diff
changeset
|
66 for i in xrange(0, len(pairs), batch): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
67 n = " ".join([encodelist(p, '-') for p in pairs[i:i + batch]]) |
11587
a036f6bd1da3
protocol: unify basic http client requests
Matt Mackall <mpm@selenic.com>
parents:
11586
diff
changeset
|
68 d = self._call("between", pairs=n) |
a036f6bd1da3
protocol: unify basic http client requests
Matt Mackall <mpm@selenic.com>
parents:
11586
diff
changeset
|
69 try: |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
70 r.extend(l and decodelist(l) or [] for l in d.splitlines()) |
11587
a036f6bd1da3
protocol: unify basic http client requests
Matt Mackall <mpm@selenic.com>
parents:
11586
diff
changeset
|
71 except: |
a036f6bd1da3
protocol: unify basic http client requests
Matt Mackall <mpm@selenic.com>
parents:
11586
diff
changeset
|
72 self._abort(error.ResponseError(_("unexpected response:"), d)) |
a036f6bd1da3
protocol: unify basic http client requests
Matt Mackall <mpm@selenic.com>
parents:
11586
diff
changeset
|
73 return r |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
74 |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
75 def pushkey(self, namespace, key, old, new): |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
76 if not self.capable('pushkey'): |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
77 return False |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
78 d = self._call("pushkey", |
13050 | 79 namespace=encoding.fromlocal(namespace), |
80 key=encoding.fromlocal(key), | |
81 old=encoding.fromlocal(old), | |
82 new=encoding.fromlocal(new)) | |
13450
b3f9af7c22c5
wireproto: catch possible cast error in pushkey
David Soria Parra <dsp@php.net>
parents:
13050
diff
changeset
|
83 try: |
b3f9af7c22c5
wireproto: catch possible cast error in pushkey
David Soria Parra <dsp@php.net>
parents:
13050
diff
changeset
|
84 d = bool(int(d)) |
b3f9af7c22c5
wireproto: catch possible cast error in pushkey
David Soria Parra <dsp@php.net>
parents:
13050
diff
changeset
|
85 except ValueError: |
b3f9af7c22c5
wireproto: catch possible cast error in pushkey
David Soria Parra <dsp@php.net>
parents:
13050
diff
changeset
|
86 raise error.ResponseError( |
b3f9af7c22c5
wireproto: catch possible cast error in pushkey
David Soria Parra <dsp@php.net>
parents:
13050
diff
changeset
|
87 _('push failed (unexpected response):'), d) |
b3f9af7c22c5
wireproto: catch possible cast error in pushkey
David Soria Parra <dsp@php.net>
parents:
13050
diff
changeset
|
88 return d |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
89 |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
90 def listkeys(self, namespace): |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
91 if not self.capable('pushkey'): |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
92 return {} |
13050 | 93 d = self._call("listkeys", namespace=encoding.fromlocal(namespace)) |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
94 r = {} |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
95 for l in d.splitlines(): |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
96 k, v = l.split('\t') |
13050 | 97 r[encoding.tolocal(k)] = encoding.tolocal(v) |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
98 return r |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
99 |
11588
8a1f625e971d
protocol: unify stream_out client code
Matt Mackall <mpm@selenic.com>
parents:
11587
diff
changeset
|
100 def stream_out(self): |
8a1f625e971d
protocol: unify stream_out client code
Matt Mackall <mpm@selenic.com>
parents:
11587
diff
changeset
|
101 return self._callstream('stream_out') |
8a1f625e971d
protocol: unify stream_out client code
Matt Mackall <mpm@selenic.com>
parents:
11587
diff
changeset
|
102 |
11591
0d9cb3f3b0a1
protocol: unify client changegroup methods
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
103 def changegroup(self, nodes, kind): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
104 n = encodelist(nodes) |
11591
0d9cb3f3b0a1
protocol: unify client changegroup methods
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
105 f = self._callstream("changegroup", roots=n) |
12337
6a6149487817
bundle: encapsulate all bundle streams in unbundle class
Matt Mackall <mpm@selenic.com>
parents:
12296
diff
changeset
|
106 return changegroupmod.unbundle10(self._decompress(f), 'UN') |
11591
0d9cb3f3b0a1
protocol: unify client changegroup methods
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
107 |
0d9cb3f3b0a1
protocol: unify client changegroup methods
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
108 def changegroupsubset(self, bases, heads, kind): |
0d9cb3f3b0a1
protocol: unify client changegroup methods
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
109 self.requirecap('changegroupsubset', _('look up remote changes')) |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
110 bases = encodelist(bases) |
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
111 heads = encodelist(heads) |
12337
6a6149487817
bundle: encapsulate all bundle streams in unbundle class
Matt Mackall <mpm@selenic.com>
parents:
12296
diff
changeset
|
112 f = self._callstream("changegroupsubset", |
6a6149487817
bundle: encapsulate all bundle streams in unbundle class
Matt Mackall <mpm@selenic.com>
parents:
12296
diff
changeset
|
113 bases=bases, heads=heads) |
6a6149487817
bundle: encapsulate all bundle streams in unbundle class
Matt Mackall <mpm@selenic.com>
parents:
12296
diff
changeset
|
114 return changegroupmod.unbundle10(self._decompress(f), 'UN') |
11591
0d9cb3f3b0a1
protocol: unify client changegroup methods
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
115 |
11592
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
116 def unbundle(self, cg, heads, source): |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
117 '''Send cg (a readable file-like object representing the |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
118 changegroup to push, typically a chunkbuffer object) to the |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
119 remote server as a bundle. Return an integer indicating the |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
120 result of the push (see localrepository.addchangegroup()).''' |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
121 |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
122 ret, output = self._callpush("unbundle", cg, heads=encodelist(heads)) |
11592
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
123 if ret == "": |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
124 raise error.ResponseError( |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
125 _('push failed:'), output) |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
126 try: |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
127 ret = int(ret) |
12063
516b000fbb7e
cleanup: remove unused variables
Brodie Rao <brodie@bitheap.org>
parents:
12042
diff
changeset
|
128 except ValueError: |
11592
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
129 raise error.ResponseError( |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
130 _('push failed (unexpected response):'), ret) |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
131 |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
132 for l in output.splitlines(True): |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
133 self.ui.status(_('remote: '), l) |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
134 return ret |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
135 |
13720
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
136 def debugwireargs(self, one, two, three=None, four=None): |
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
137 # don't pass optional arguments left at their default value |
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
138 opts = {} |
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
139 if three is not None: |
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
140 opts['three'] = three |
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
141 if four is not None: |
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
142 opts['four'] = four |
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
143 return self._call('debugwireargs', one=one, two=two, **opts) |
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
144 |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
145 # server side |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
146 |
11625
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
147 class streamres(object): |
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
148 def __init__(self, gen): |
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
149 self.gen = gen |
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
150 |
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
151 class pushres(object): |
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
152 def __init__(self, res): |
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
153 self.res = res |
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
154 |
12703
40bb5853fc4b
wireproto: introduce pusherr() to deal with "unsynced changes" error
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12702
diff
changeset
|
155 class pusherr(object): |
40bb5853fc4b
wireproto: introduce pusherr() to deal with "unsynced changes" error
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12702
diff
changeset
|
156 def __init__(self, res): |
40bb5853fc4b
wireproto: introduce pusherr() to deal with "unsynced changes" error
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12702
diff
changeset
|
157 self.res = res |
40bb5853fc4b
wireproto: introduce pusherr() to deal with "unsynced changes" error
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12702
diff
changeset
|
158 |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
159 def dispatch(repo, proto, command): |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
160 func, spec = commands[command] |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
161 args = proto.getargs(spec) |
11625
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
162 return func(repo, proto, *args) |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
163 |
11583
944c23762c3c
protocol: add proto to method prototypes
Matt Mackall <mpm@selenic.com>
parents:
11581
diff
changeset
|
164 def between(repo, proto, pairs): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
165 pairs = [decodelist(p, '-') for p in pairs.split(" ")] |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
166 r = [] |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
167 for b in repo.between(pairs): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
168 r.append(encodelist(b) + "\n") |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
169 return "".join(r) |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
170 |
11583
944c23762c3c
protocol: add proto to method prototypes
Matt Mackall <mpm@selenic.com>
parents:
11581
diff
changeset
|
171 def branchmap(repo, proto): |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
172 branchmap = repo.branchmap() |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
173 heads = [] |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
174 for branch, nodes in branchmap.iteritems(): |
13047
6c375e07d673
branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents:
12703
diff
changeset
|
175 branchname = urllib.quote(encoding.fromlocal(branch)) |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
176 branchnodes = encodelist(nodes) |
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
177 heads.append('%s %s' % (branchname, branchnodes)) |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
178 return '\n'.join(heads) |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
179 |
11583
944c23762c3c
protocol: add proto to method prototypes
Matt Mackall <mpm@selenic.com>
parents:
11581
diff
changeset
|
180 def branches(repo, proto, nodes): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
181 nodes = decodelist(nodes) |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
182 r = [] |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
183 for b in repo.branches(nodes): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
184 r.append(encodelist(b) + "\n") |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
185 return "".join(r) |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
186 |
11594
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
187 def capabilities(repo, proto): |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
188 caps = 'lookup changegroupsubset branchmap pushkey'.split() |
11627
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
189 if _allowstream(repo.ui): |
12296
d7fff529d85d
clone: only use stream when we understand the revlog format
Sune Foldager <cryo@cyanite.org>
parents:
12085
diff
changeset
|
190 requiredformats = repo.requirements & repo.supportedformats |
d7fff529d85d
clone: only use stream when we understand the revlog format
Sune Foldager <cryo@cyanite.org>
parents:
12085
diff
changeset
|
191 # if our local revlogs are just revlogv1, add 'stream' cap |
d7fff529d85d
clone: only use stream when we understand the revlog format
Sune Foldager <cryo@cyanite.org>
parents:
12085
diff
changeset
|
192 if not requiredformats - set(('revlogv1',)): |
d7fff529d85d
clone: only use stream when we understand the revlog format
Sune Foldager <cryo@cyanite.org>
parents:
12085
diff
changeset
|
193 caps.append('stream') |
d7fff529d85d
clone: only use stream when we understand the revlog format
Sune Foldager <cryo@cyanite.org>
parents:
12085
diff
changeset
|
194 # otherwise, add 'streamreqs' detailing our local revlog format |
d7fff529d85d
clone: only use stream when we understand the revlog format
Sune Foldager <cryo@cyanite.org>
parents:
12085
diff
changeset
|
195 else: |
d7fff529d85d
clone: only use stream when we understand the revlog format
Sune Foldager <cryo@cyanite.org>
parents:
12085
diff
changeset
|
196 caps.append('streamreqs=%s' % ','.join(requiredformats)) |
11594
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
197 caps.append('unbundle=%s' % ','.join(changegroupmod.bundlepriority)) |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
198 return ' '.join(caps) |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
199 |
11584
1af96b090116
protocol: unify changegroup commands
Matt Mackall <mpm@selenic.com>
parents:
11583
diff
changeset
|
200 def changegroup(repo, proto, roots): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
201 nodes = decodelist(roots) |
11584
1af96b090116
protocol: unify changegroup commands
Matt Mackall <mpm@selenic.com>
parents:
11583
diff
changeset
|
202 cg = repo.changegroup(nodes, 'serve') |
11625
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
203 return streamres(proto.groupchunks(cg)) |
11584
1af96b090116
protocol: unify changegroup commands
Matt Mackall <mpm@selenic.com>
parents:
11583
diff
changeset
|
204 |
1af96b090116
protocol: unify changegroup commands
Matt Mackall <mpm@selenic.com>
parents:
11583
diff
changeset
|
205 def changegroupsubset(repo, proto, bases, heads): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
206 bases = decodelist(bases) |
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
207 heads = decodelist(heads) |
11584
1af96b090116
protocol: unify changegroup commands
Matt Mackall <mpm@selenic.com>
parents:
11583
diff
changeset
|
208 cg = repo.changegroupsubset(bases, heads, 'serve') |
11625
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
209 return streamres(proto.groupchunks(cg)) |
11584
1af96b090116
protocol: unify changegroup commands
Matt Mackall <mpm@selenic.com>
parents:
11583
diff
changeset
|
210 |
13720
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
211 def debugwireargs(repo, proto, one, two): |
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
212 return repo.debugwireargs(one, two) |
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
213 |
11583
944c23762c3c
protocol: add proto to method prototypes
Matt Mackall <mpm@selenic.com>
parents:
11581
diff
changeset
|
214 def heads(repo, proto): |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
215 h = repo.heads() |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
216 return encodelist(h) + "\n" |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
217 |
11594
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
218 def hello(repo, proto): |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
219 '''the hello command returns a set of lines describing various |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
220 interesting things about the server, in an RFC822-like format. |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
221 Currently the only one defined is "capabilities", which |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
222 consists of a line in the form: |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
223 |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
224 capabilities: space separated list of tokens |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
225 ''' |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
226 return "capabilities: %s\n" % (capabilities(repo, proto)) |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
227 |
11583
944c23762c3c
protocol: add proto to method prototypes
Matt Mackall <mpm@selenic.com>
parents:
11581
diff
changeset
|
228 def listkeys(repo, proto, namespace): |
13050 | 229 d = pushkeymod.list(repo, encoding.tolocal(namespace)).items() |
230 t = '\n'.join(['%s\t%s' % (encoding.fromlocal(k), encoding.fromlocal(v)) | |
231 for k, v in d]) | |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
232 return t |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
233 |
11583
944c23762c3c
protocol: add proto to method prototypes
Matt Mackall <mpm@selenic.com>
parents:
11581
diff
changeset
|
234 def lookup(repo, proto, key): |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
235 try: |
13049
d588326f6321
wireproto: use proper UTF-8 handling for key lookup
Matt Mackall <mpm@selenic.com>
parents:
13047
diff
changeset
|
236 r = hex(repo.lookup(encoding.tolocal(key))) |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
237 success = 1 |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
238 except Exception, inst: |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
239 r = str(inst) |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
240 success = 0 |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
241 return "%s %s\n" % (success, r) |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
242 |
11583
944c23762c3c
protocol: add proto to method prototypes
Matt Mackall <mpm@selenic.com>
parents:
11581
diff
changeset
|
243 def pushkey(repo, proto, namespace, key, old, new): |
13050 | 244 # compatibility with pre-1.8 clients which were accidentally |
245 # sending raw binary nodes rather than utf-8-encoded hex | |
246 if len(new) == 20 and new.encode('string-escape') != new: | |
247 # looks like it could be a binary node | |
248 try: | |
249 u = new.decode('utf-8') | |
250 new = encoding.tolocal(new) # but cleanly decodes as UTF-8 | |
251 except UnicodeDecodeError: | |
252 pass # binary, leave unmodified | |
253 else: | |
254 new = encoding.tolocal(new) # normal path | |
255 | |
256 r = pushkeymod.push(repo, | |
257 encoding.tolocal(namespace), encoding.tolocal(key), | |
258 encoding.tolocal(old), new) | |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
259 return '%s\n' % int(r) |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
260 |
11627
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
261 def _allowstream(ui): |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
262 return ui.configbool('server', 'uncompressed', True, untrusted=True) |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
263 |
11585
5d907fbb9703
protocol: unify stream_out command
Matt Mackall <mpm@selenic.com>
parents:
11584
diff
changeset
|
264 def stream(repo, proto): |
11627
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
265 '''If the server supports streaming clone, it advertises the "stream" |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
266 capability with a value representing the version and flags of the repo |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
267 it is serving. Client checks to see if it understands the format. |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
268 |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
269 The format is simple: the server writes out a line with the amount |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
270 of files, then the total amount of bytes to be transfered (separated |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
271 by a space). Then, for each file, the server first writes the filename |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
272 and filesize (separated by the null character), then the file contents. |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
273 ''' |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
274 |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
275 if not _allowstream(repo.ui): |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
276 return '1\n' |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
277 |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
278 entries = [] |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
279 total_bytes = 0 |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
280 try: |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
281 # get consistent snapshot of repo, lock during scan |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
282 lock = repo.lock() |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
283 try: |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
284 repo.ui.debug('scanning\n') |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
285 for name, ename, size in repo.store.walk(): |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
286 entries.append((name, size)) |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
287 total_bytes += size |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
288 finally: |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
289 lock.release() |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
290 except error.LockError: |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
291 return '2\n' # error: 2 |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
292 |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
293 def streamer(repo, entries, total): |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
294 '''stream out all metadata files in repository.''' |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
295 yield '0\n' # success |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
296 repo.ui.debug('%d files, %d bytes to transfer\n' % |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
297 (len(entries), total_bytes)) |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
298 yield '%d %d\n' % (len(entries), total_bytes) |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
299 for name, size in entries: |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
300 repo.ui.debug('sending %s (%d bytes)\n' % (name, size)) |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
301 # partially encode name over the wire for backwards compat |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
302 yield '%s\0%d\n' % (store.encodedir(name), size) |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
303 for chunk in util.filechunkiter(repo.sopener(name), limit=size): |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
304 yield chunk |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
305 |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
306 return streamres(streamer(repo, entries, total_bytes)) |
11585
5d907fbb9703
protocol: unify stream_out command
Matt Mackall <mpm@selenic.com>
parents:
11584
diff
changeset
|
307 |
11593
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
308 def unbundle(repo, proto, heads): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
309 their_heads = decodelist(heads) |
11593
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
310 |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
311 def check_heads(): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
312 heads = repo.heads() |
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
313 return their_heads == ['force'] or their_heads == heads |
11593
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
314 |
12702
f747c085b789
wireproto: redirect the output earlier
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12701
diff
changeset
|
315 proto.redirect() |
f747c085b789
wireproto: redirect the output earlier
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12701
diff
changeset
|
316 |
11593
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
317 # fail early if possible |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
318 if not check_heads(): |
12703
40bb5853fc4b
wireproto: introduce pusherr() to deal with "unsynced changes" error
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12702
diff
changeset
|
319 return pusherr('unsynced changes') |
11593
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
320 |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
321 # write bundle data to temporary file because it can be big |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
322 fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-') |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
323 fp = os.fdopen(fd, 'wb+') |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
324 r = 0 |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
325 try: |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
326 proto.getfile(fp) |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
327 lock = repo.lock() |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
328 try: |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
329 if not check_heads(): |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
330 # someone else committed/pushed/unbundled while we |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
331 # were transferring data |
12703
40bb5853fc4b
wireproto: introduce pusherr() to deal with "unsynced changes" error
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12702
diff
changeset
|
332 return pusherr('unsynced changes') |
11593
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
333 |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
334 # push can proceed |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
335 fp.seek(0) |
12042
210049a8d16e
bundle: unify/refactor unbundle/readbundle
Matt Mackall <mpm@selenic.com>
parents:
11879
diff
changeset
|
336 gen = changegroupmod.readbundle(fp, None) |
11593
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
337 |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
338 try: |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
339 r = repo.addchangegroup(gen, 'serve', proto._client(), |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
340 lock=lock) |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
341 except util.Abort, inst: |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
342 sys.stderr.write("abort: %s\n" % inst) |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
343 finally: |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
344 lock.release() |
12701
cb9e1d1c34ea
wireproto: return in finally was messing with the return inside the block
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12337
diff
changeset
|
345 return pushres(r) |
11593
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
346 |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
347 finally: |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
348 fp.close() |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
349 os.unlink(tempname) |
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
350 |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
351 commands = { |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
352 'between': (between, 'pairs'), |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
353 'branchmap': (branchmap, ''), |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
354 'branches': (branches, 'nodes'), |
11594
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
355 'capabilities': (capabilities, ''), |
11584
1af96b090116
protocol: unify changegroup commands
Matt Mackall <mpm@selenic.com>
parents:
11583
diff
changeset
|
356 'changegroup': (changegroup, 'roots'), |
1af96b090116
protocol: unify changegroup commands
Matt Mackall <mpm@selenic.com>
parents:
11583
diff
changeset
|
357 'changegroupsubset': (changegroupsubset, 'bases heads'), |
13720
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
358 'debugwireargs': (debugwireargs, 'one two'), |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
359 'heads': (heads, ''), |
11594
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
360 'hello': (hello, ''), |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
361 'listkeys': (listkeys, 'namespace'), |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
362 'lookup': (lookup, 'key'), |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
363 'pushkey': (pushkey, 'namespace key old new'), |
11585
5d907fbb9703
protocol: unify stream_out command
Matt Mackall <mpm@selenic.com>
parents:
11584
diff
changeset
|
364 'stream_out': (stream, ''), |
11593
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
365 'unbundle': (unbundle, 'heads'), |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
366 } |