Show More
@@ -7,7 +7,7 b'' | |||
|
7 | 7 | |
|
8 | 8 | from node import bin, hex |
|
9 | 9 | from i18n import _ |
|
10 | import repo, util, error, encoding | |
|
10 | import repo, util, error, encoding, wireproto | |
|
11 | 11 | import re, urllib |
|
12 | 12 | |
|
13 | 13 | class remotelock(object): |
@@ -20,7 +20,7 b' class remotelock(object):' | |||
|
20 | 20 | if self.repo: |
|
21 | 21 | self.release() |
|
22 | 22 | |
|
23 | class sshrepository(repo.repository): | |
|
23 | class sshrepository(wireproto.wirerepository): | |
|
24 | 24 | def __init__(self, ui, path, create=0): |
|
25 | 25 | self._url = path |
|
26 | 26 | self.ui = ui |
@@ -101,6 +101,10 b' class sshrepository(repo.repository):' | |||
|
101 | 101 | self.cleanup() |
|
102 | 102 | raise exception |
|
103 | 103 | |
|
104 | def _abort(self, exception): | |
|
105 | self.cleanup() | |
|
106 | raise exception | |
|
107 | ||
|
104 | 108 | def cleanup(self): |
|
105 | 109 | try: |
|
106 | 110 | self.pipeo.close() |
@@ -128,6 +132,10 b' class sshrepository(repo.repository):' | |||
|
128 | 132 | self.do_cmd(cmd, **args) |
|
129 | 133 | return self._recv() |
|
130 | 134 | |
|
135 | def _call(self, cmd, **args): | |
|
136 | self.do_cmd(cmd, **args) | |
|
137 | return self._recv() | |
|
138 | ||
|
131 | 139 | def _recv(self): |
|
132 | 140 | l = self.pipei.readline() |
|
133 | 141 | self.readerr() |
@@ -152,60 +160,6 b' class sshrepository(repo.repository):' | |||
|
152 | 160 | def unlock(self): |
|
153 | 161 | self.call("unlock") |
|
154 | 162 | |
|
155 | def lookup(self, key): | |
|
156 | self.requirecap('lookup', _('look up remote revision')) | |
|
157 | d = self.call("lookup", key=key) | |
|
158 | success, data = d[:-1].split(" ", 1) | |
|
159 | if int(success): | |
|
160 | return bin(data) | |
|
161 | else: | |
|
162 | self.abort(error.RepoError(data)) | |
|
163 | ||
|
164 | def heads(self): | |
|
165 | d = self.call("heads") | |
|
166 | try: | |
|
167 | return map(bin, d[:-1].split(" ")) | |
|
168 | except: | |
|
169 | self.abort(error.ResponseError(_("unexpected response:"), d)) | |
|
170 | ||
|
171 | def branchmap(self): | |
|
172 | d = self.call("branchmap") | |
|
173 | try: | |
|
174 | branchmap = {} | |
|
175 | for branchpart in d.splitlines(): | |
|
176 | branchheads = branchpart.split(' ') | |
|
177 | branchname = urllib.unquote(branchheads[0]) | |
|
178 | # Earlier servers (1.3.x) send branch names in (their) local | |
|
179 | # charset. The best we can do is assume it's identical to our | |
|
180 | # own local charset, in case it's not utf-8. | |
|
181 | try: | |
|
182 | branchname.decode('utf-8') | |
|
183 | except UnicodeDecodeError: | |
|
184 | branchname = encoding.fromlocal(branchname) | |
|
185 | branchheads = [bin(x) for x in branchheads[1:]] | |
|
186 | branchmap[branchname] = branchheads | |
|
187 | return branchmap | |
|
188 | except: | |
|
189 | raise error.ResponseError(_("unexpected response:"), d) | |
|
190 | ||
|
191 | def branches(self, nodes): | |
|
192 | n = " ".join(map(hex, nodes)) | |
|
193 | d = self.call("branches", nodes=n) | |
|
194 | try: | |
|
195 | br = [tuple(map(bin, b.split(" "))) for b in d.splitlines()] | |
|
196 | return br | |
|
197 | except: | |
|
198 | self.abort(error.ResponseError(_("unexpected response:"), d)) | |
|
199 | ||
|
200 | def between(self, pairs): | |
|
201 | n = " ".join(["-".join(map(hex, p)) for p in pairs]) | |
|
202 | d = self.call("between", pairs=n) | |
|
203 | try: | |
|
204 | p = [l and map(bin, l.split(" ")) or [] for l in d.splitlines()] | |
|
205 | return p | |
|
206 | except: | |
|
207 | self.abort(error.ResponseError(_("unexpected response:"), d)) | |
|
208 | ||
|
209 | 163 | def changegroup(self, nodes, kind): |
|
210 | 164 | n = " ".join(map(hex, nodes)) |
|
211 | 165 | return self.do_cmd("changegroup", roots=n) |
@@ -273,21 +227,4 b' class sshrepository(repo.repository):' | |||
|
273 | 227 | def stream_out(self): |
|
274 | 228 | return self.do_cmd('stream_out') |
|
275 | 229 | |
|
276 | def pushkey(self, namespace, key, old, new): | |
|
277 | if not self.capable('pushkey'): | |
|
278 | return False | |
|
279 | d = self.call("pushkey", | |
|
280 | namespace=namespace, key=key, old=old, new=new) | |
|
281 | return bool(int(d)) | |
|
282 | ||
|
283 | def listkeys(self, namespace): | |
|
284 | if not self.capable('pushkey'): | |
|
285 | return {} | |
|
286 | d = self.call("listkeys", namespace=namespace) | |
|
287 | r = {} | |
|
288 | for l in d.splitlines(): | |
|
289 | k, v = l.split('\t') | |
|
290 | r[k.decode('string-escape')] = v.decode('string-escape') | |
|
291 | return r | |
|
292 | ||
|
293 | 230 | instance = sshrepository |
@@ -7,9 +7,85 b'' | |||
|
7 | 7 | |
|
8 | 8 | from i18n import _ |
|
9 | 9 | from node import bin, hex |
|
10 |
import urllib |
|
|
10 | import urllib | |
|
11 | import streamclone, repo, error, encoding | |
|
11 | 12 | import pushkey as pushkey_ |
|
12 | 13 | |
|
14 | # client side | |
|
15 | ||
|
16 | class wirerepository(repo.repository): | |
|
17 | def lookup(self, key): | |
|
18 | self.requirecap('lookup', _('look up remote revision')) | |
|
19 | d = self._call("lookup", key=key) | |
|
20 | success, data = d[:-1].split(" ", 1) | |
|
21 | if int(success): | |
|
22 | return bin(data) | |
|
23 | self._abort(error.RepoError(data)) | |
|
24 | ||
|
25 | def heads(self): | |
|
26 | d = self._call("heads") | |
|
27 | try: | |
|
28 | return map(bin, d[:-1].split(" ")) | |
|
29 | except: | |
|
30 | self.abort(error.ResponseError(_("unexpected response:"), d)) | |
|
31 | ||
|
32 | def branchmap(self): | |
|
33 | d = self._call("branchmap") | |
|
34 | try: | |
|
35 | branchmap = {} | |
|
36 | for branchpart in d.splitlines(): | |
|
37 | branchheads = branchpart.split(' ') | |
|
38 | branchname = urllib.unquote(branchheads[0]) | |
|
39 | # Earlier servers (1.3.x) send branch names in (their) local | |
|
40 | # charset. The best we can do is assume it's identical to our | |
|
41 | # own local charset, in case it's not utf-8. | |
|
42 | try: | |
|
43 | branchname.decode('utf-8') | |
|
44 | except UnicodeDecodeError: | |
|
45 | branchname = encoding.fromlocal(branchname) | |
|
46 | branchheads = [bin(x) for x in branchheads[1:]] | |
|
47 | branchmap[branchname] = branchheads | |
|
48 | return branchmap | |
|
49 | except TypeError: | |
|
50 | self._abort(error.ResponseError(_("unexpected response:"), d)) | |
|
51 | ||
|
52 | def branches(self, nodes): | |
|
53 | n = " ".join(map(hex, nodes)) | |
|
54 | d = self._call("branches", nodes=n) | |
|
55 | try: | |
|
56 | br = [tuple(map(bin, b.split(" "))) for b in d.splitlines()] | |
|
57 | return br | |
|
58 | except: | |
|
59 | self._abort(error.ResponseError(_("unexpected response:"), d)) | |
|
60 | ||
|
61 | def between(self, pairs): | |
|
62 | n = " ".join(["-".join(map(hex, p)) for p in pairs]) | |
|
63 | d = self._call("between", pairs=n) | |
|
64 | try: | |
|
65 | p = [l and map(bin, l.split(" ")) or [] for l in d.splitlines()] | |
|
66 | return p | |
|
67 | except: | |
|
68 | self._abort(error.ResponseError(_("unexpected response:"), d)) | |
|
69 | ||
|
70 | def pushkey(self, namespace, key, old, new): | |
|
71 | if not self.capable('pushkey'): | |
|
72 | return False | |
|
73 | d = self._call("pushkey", | |
|
74 | namespace=namespace, key=key, old=old, new=new) | |
|
75 | return bool(int(d)) | |
|
76 | ||
|
77 | def listkeys(self, namespace): | |
|
78 | if not self.capable('pushkey'): | |
|
79 | return {} | |
|
80 | d = self._call("listkeys", namespace=namespace) | |
|
81 | r = {} | |
|
82 | for l in d.splitlines(): | |
|
83 | k, v = l.split('\t') | |
|
84 | r[k.decode('string-escape')] = v.decode('string-escape') | |
|
85 | return r | |
|
86 | ||
|
87 | # server side | |
|
88 | ||
|
13 | 89 | def dispatch(repo, proto, command): |
|
14 | 90 | if command not in commands: |
|
15 | 91 | return False |
General Comments 0
You need to be logged in to leave comments.
Login now