Show More
@@ -12,6 +12,14 b' import changegroup as changegroupmod' | |||
|
12 | 12 | import streamclone, repo, error, encoding, util |
|
13 | 13 | import pushkey as pushkey_ |
|
14 | 14 | |
|
15 | # list of nodes encoding / decoding | |
|
16 | ||
|
17 | def decodelist(l, sep=' '): | |
|
18 | return map(bin, l.split(sep)) | |
|
19 | ||
|
20 | def encodelist(l, sep=' '): | |
|
21 | return sep.join(map(hex, l)) | |
|
22 | ||
|
15 | 23 | # client side |
|
16 | 24 | |
|
17 | 25 | class wirerepository(repo.repository): |
@@ -26,7 +34,7 b' class wirerepository(repo.repository):' | |||
|
26 | 34 | def heads(self): |
|
27 | 35 | d = self._call("heads") |
|
28 | 36 | try: |
|
29 |
return |
|
|
37 | return decodelist(d[:-1]) | |
|
30 | 38 | except: |
|
31 | 39 | self.abort(error.ResponseError(_("unexpected response:"), d)) |
|
32 | 40 | |
@@ -35,8 +43,8 b' class wirerepository(repo.repository):' | |||
|
35 | 43 | try: |
|
36 | 44 | branchmap = {} |
|
37 | 45 | for branchpart in d.splitlines(): |
|
38 | branchheads = branchpart.split(' ') | |
|
39 |
branchname = urllib.unquote(branch |
|
|
46 | branchname, branchheads = branchpart.split(' ', 1) | |
|
47 | branchname = urllib.unquote(branchname) | |
|
40 | 48 | # Earlier servers (1.3.x) send branch names in (their) local |
|
41 | 49 | # charset. The best we can do is assume it's identical to our |
|
42 | 50 | # own local charset, in case it's not utf-8. |
@@ -44,17 +52,17 b' class wirerepository(repo.repository):' | |||
|
44 | 52 | branchname.decode('utf-8') |
|
45 | 53 | except UnicodeDecodeError: |
|
46 | 54 | branchname = encoding.fromlocal(branchname) |
|
47 |
branchheads = |
|
|
55 | branchheads = decodelist(branchheads) | |
|
48 | 56 | branchmap[branchname] = branchheads |
|
49 | 57 | return branchmap |
|
50 | 58 | except TypeError: |
|
51 | 59 | self._abort(error.ResponseError(_("unexpected response:"), d)) |
|
52 | 60 | |
|
53 | 61 | def branches(self, nodes): |
|
54 |
n = |
|
|
62 | n = encodelist(nodes) | |
|
55 | 63 | d = self._call("branches", nodes=n) |
|
56 | 64 | try: |
|
57 |
br = [tuple( |
|
|
65 | br = [tuple(decodelist(b)) for b in d.splitlines()] | |
|
58 | 66 | return br |
|
59 | 67 | except: |
|
60 | 68 | self._abort(error.ResponseError(_("unexpected response:"), d)) |
@@ -63,11 +71,10 b' class wirerepository(repo.repository):' | |||
|
63 | 71 | batch = 8 # avoid giant requests |
|
64 | 72 | r = [] |
|
65 | 73 | for i in xrange(0, len(pairs), batch): |
|
66 |
n = " ".join([ |
|
|
74 | n = " ".join([encodelist(p, '-') for p in pairs[i:i + batch]]) | |
|
67 | 75 | d = self._call("between", pairs=n) |
|
68 | 76 | try: |
|
69 | r += [l and map(bin, l.split(" ")) or [] | |
|
70 | for l in d.splitlines()] | |
|
77 | r.extend(l and decodelist(l) or [] for l in d.splitlines()) | |
|
71 | 78 | except: |
|
72 | 79 | self._abort(error.ResponseError(_("unexpected response:"), d)) |
|
73 | 80 | return r |
@@ -93,14 +100,14 b' class wirerepository(repo.repository):' | |||
|
93 | 100 | return self._callstream('stream_out') |
|
94 | 101 | |
|
95 | 102 | def changegroup(self, nodes, kind): |
|
96 |
n = |
|
|
103 | n = encodelist(nodes) | |
|
97 | 104 | f = self._callstream("changegroup", roots=n) |
|
98 | 105 | return self._decompress(f) |
|
99 | 106 | |
|
100 | 107 | def changegroupsubset(self, bases, heads, kind): |
|
101 | 108 | self.requirecap('changegroupsubset', _('look up remote changes')) |
|
102 |
bases = |
|
|
103 |
heads = |
|
|
109 | bases = encodelist(bases) | |
|
110 | heads = encodelist(heads) | |
|
104 | 111 | return self._decompress(self._callstream("changegroupsubset", |
|
105 | 112 | bases=bases, heads=heads)) |
|
106 | 113 | |
@@ -110,7 +117,7 b' class wirerepository(repo.repository):' | |||
|
110 | 117 | remote server as a bundle. Return an integer indicating the |
|
111 | 118 | result of the push (see localrepository.addchangegroup()).''' |
|
112 | 119 | |
|
113 |
ret, output = self._callpush("unbundle", cg, heads= |
|
|
120 | ret, output = self._callpush("unbundle", cg, heads=encodelist(heads)) | |
|
114 | 121 | if ret == "": |
|
115 | 122 | raise error.ResponseError( |
|
116 | 123 | _('push failed:'), output) |
@@ -137,10 +144,10 b' def dispatch(repo, proto, command):' | |||
|
137 | 144 | return True |
|
138 | 145 | |
|
139 | 146 | def between(repo, proto, pairs): |
|
140 |
pairs = [ |
|
|
147 | pairs = [decodelist(p, '-') for p in pairs.split(" ")] | |
|
141 | 148 | r = [] |
|
142 | 149 | for b in repo.between(pairs): |
|
143 |
r.append( |
|
|
150 | r.append(encodelist(b) + "\n") | |
|
144 | 151 | return "".join(r) |
|
145 | 152 | |
|
146 | 153 | def branchmap(repo, proto): |
@@ -148,15 +155,15 b' def branchmap(repo, proto):' | |||
|
148 | 155 | heads = [] |
|
149 | 156 | for branch, nodes in branchmap.iteritems(): |
|
150 | 157 | branchname = urllib.quote(branch) |
|
151 |
branchnodes = |
|
|
152 |
heads.append('%s %s' % (branchname, |
|
|
158 | branchnodes = encodelist(nodes) | |
|
159 | heads.append('%s %s' % (branchname, branchnodes)) | |
|
153 | 160 | return '\n'.join(heads) |
|
154 | 161 | |
|
155 | 162 | def branches(repo, proto, nodes): |
|
156 | nodes = map(bin, nodes.split(" ")) | |
|
163 | nodes = decodelist(nodes) | |
|
157 | 164 | r = [] |
|
158 | 165 | for b in repo.branches(nodes): |
|
159 |
r.append( |
|
|
166 | r.append(encodelist(b) + "\n") | |
|
160 | 167 | return "".join(r) |
|
161 | 168 | |
|
162 | 169 | def capabilities(repo, proto): |
@@ -167,19 +174,19 b' def capabilities(repo, proto):' | |||
|
167 | 174 | return ' '.join(caps) |
|
168 | 175 | |
|
169 | 176 | def changegroup(repo, proto, roots): |
|
170 | nodes = map(bin, roots.split(" ")) | |
|
177 | nodes = decodelist(roots) | |
|
171 | 178 | cg = repo.changegroup(nodes, 'serve') |
|
172 | 179 | proto.sendchangegroup(cg) |
|
173 | 180 | |
|
174 | 181 | def changegroupsubset(repo, proto, bases, heads): |
|
175 | bases = [bin(n) for n in bases.split(' ')] | |
|
176 | heads = [bin(n) for n in heads.split(' ')] | |
|
182 | bases = decodelist(bases) | |
|
183 | heads = decodelist(heads) | |
|
177 | 184 | cg = repo.changegroupsubset(bases, heads, 'serve') |
|
178 | 185 | proto.sendchangegroup(cg) |
|
179 | 186 | |
|
180 | 187 | def heads(repo, proto): |
|
181 | 188 | h = repo.heads() |
|
182 |
return |
|
|
189 | return encodelist(h) + "\n" | |
|
183 | 190 | |
|
184 | 191 | def hello(repo, proto): |
|
185 | 192 | '''the hello command returns a set of lines describing various |
@@ -217,11 +224,11 b' def stream(repo, proto):' | |||
|
217 | 224 | return str(inst) |
|
218 | 225 | |
|
219 | 226 | def unbundle(repo, proto, heads): |
|
220 |
their_heads = heads |
|
|
227 | their_heads = decodelist(heads) | |
|
221 | 228 | |
|
222 | 229 | def check_heads(): |
|
223 |
heads = |
|
|
224 |
return their_heads == [ |
|
|
230 | heads = repo.heads() | |
|
231 | return their_heads == ['force'] or their_heads == heads | |
|
225 | 232 | |
|
226 | 233 | # fail early if possible |
|
227 | 234 | if not check_heads(): |
General Comments 0
You need to be logged in to leave comments.
Login now