Show More
@@ -1,207 +1,211 | |||
|
1 | 1 | # sshrepo.py - ssh repository proxy class for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms |
|
6 | 6 | # of the GNU General Public License, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | from node import * |
|
9 | 9 | from remoterepo import * |
|
10 | 10 | from i18n import gettext as _ |
|
11 | 11 | from demandload import * |
|
12 | 12 | demandload(globals(), "hg os re stat util") |
|
13 | 13 | |
|
14 | 14 | class sshrepository(remoterepository): |
|
15 | 15 | def __init__(self, ui, path, create=0): |
|
16 | 16 | self._url = path |
|
17 | 17 | self.ui = ui |
|
18 | 18 | |
|
19 | 19 | m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', path) |
|
20 | 20 | if not m: |
|
21 |
|
|
|
21 | self.repoerror(_("couldn't parse location %s") % path) | |
|
22 | 22 | |
|
23 | 23 | self.user = m.group(2) |
|
24 | 24 | self.host = m.group(3) |
|
25 | 25 | self.port = m.group(5) |
|
26 | 26 | self.path = m.group(7) or "." |
|
27 | 27 | |
|
28 | 28 | args = self.user and ("%s@%s" % (self.user, self.host)) or self.host |
|
29 | 29 | args = self.port and ("%s -p %s") % (args, self.port) or args |
|
30 | 30 | |
|
31 | 31 | sshcmd = self.ui.config("ui", "ssh", "ssh") |
|
32 | 32 | remotecmd = self.ui.config("ui", "remotecmd", "hg") |
|
33 | 33 | |
|
34 | 34 | if create: |
|
35 | 35 | cmd = '%s %s "%s init %s"' |
|
36 | 36 | cmd = cmd % (sshcmd, args, remotecmd, self.path) |
|
37 | 37 | |
|
38 | 38 | ui.note('running %s\n' % cmd) |
|
39 | 39 | res = os.system(cmd) |
|
40 | 40 | if res != 0: |
|
41 |
|
|
|
41 | self.repoerror(_("could not create remote repo")) | |
|
42 | 42 | |
|
43 | 43 | self.validate_repo(ui, sshcmd, args, remotecmd) |
|
44 | 44 | |
|
45 | 45 | def url(self): |
|
46 | 46 | return self._url |
|
47 | 47 | |
|
48 | 48 | def validate_repo(self, ui, sshcmd, args, remotecmd): |
|
49 | 49 | # cleanup up previous run |
|
50 | 50 | self.cleanup() |
|
51 | 51 | |
|
52 | 52 | cmd = '%s %s "%s -R %s serve --stdio"' |
|
53 | 53 | cmd = cmd % (sshcmd, args, remotecmd, self.path) |
|
54 | 54 | |
|
55 | 55 | ui.note('running %s\n' % cmd) |
|
56 | 56 | self.pipeo, self.pipei, self.pipee = os.popen3(cmd, 'b') |
|
57 | 57 | |
|
58 | 58 | # skip any noise generated by remote shell |
|
59 | 59 | self.do_cmd("hello") |
|
60 | 60 | r = self.do_cmd("between", pairs=("%s-%s" % ("0"*40, "0"*40))) |
|
61 | 61 | lines = ["", "dummy"] |
|
62 | 62 | max_noise = 500 |
|
63 | 63 | while lines[-1] and max_noise: |
|
64 | 64 | l = r.readline() |
|
65 | 65 | self.readerr() |
|
66 | 66 | if lines[-1] == "1\n" and l == "\n": |
|
67 | 67 | break |
|
68 | 68 | if l: |
|
69 | 69 | ui.debug(_("remote: "), l) |
|
70 | 70 | lines.append(l) |
|
71 | 71 | max_noise -= 1 |
|
72 | 72 | else: |
|
73 |
|
|
|
73 | self.repoerror(_("no suitable response from remote hg")) | |
|
74 | 74 | |
|
75 | 75 | self.capabilities = () |
|
76 | 76 | lines.reverse() |
|
77 | 77 | for l in lines: |
|
78 | 78 | if l.startswith("capabilities:"): |
|
79 | 79 | self.capabilities = l[:-1].split(":")[1].split() |
|
80 | 80 | break |
|
81 | 81 | |
|
82 | 82 | def readerr(self): |
|
83 | 83 | while 1: |
|
84 | 84 | size = util.fstat(self.pipee).st_size |
|
85 | 85 | if size == 0: break |
|
86 | 86 | l = self.pipee.readline() |
|
87 | 87 | if not l: break |
|
88 | 88 | self.ui.status(_("remote: "), l) |
|
89 | 89 | |
|
90 | def repoerror(self, msg): | |
|
91 | self.cleanup() | |
|
92 | raise hg.RepoError(msg) | |
|
93 | ||
|
90 | 94 | def cleanup(self): |
|
91 | 95 | try: |
|
92 | 96 | self.pipeo.close() |
|
93 | 97 | self.pipei.close() |
|
94 | 98 | # read the error descriptor until EOF |
|
95 | 99 | for l in self.pipee: |
|
96 | 100 | self.ui.status(_("remote: "), l) |
|
97 | 101 | self.pipee.close() |
|
98 | 102 | except: |
|
99 | 103 | pass |
|
100 | 104 | |
|
101 | 105 | __del__ = cleanup |
|
102 | 106 | |
|
103 | 107 | def do_cmd(self, cmd, **args): |
|
104 | 108 | self.ui.debug(_("sending %s command\n") % cmd) |
|
105 | 109 | self.pipeo.write("%s\n" % cmd) |
|
106 | 110 | for k, v in args.items(): |
|
107 | 111 | self.pipeo.write("%s %d\n" % (k, len(v))) |
|
108 | 112 | self.pipeo.write(v) |
|
109 | 113 | self.pipeo.flush() |
|
110 | 114 | |
|
111 | 115 | return self.pipei |
|
112 | 116 | |
|
113 | 117 | def call(self, cmd, **args): |
|
114 | 118 | r = self.do_cmd(cmd, **args) |
|
115 | 119 | l = r.readline() |
|
116 | 120 | self.readerr() |
|
117 | 121 | try: |
|
118 | 122 | l = int(l) |
|
119 | 123 | except: |
|
120 |
|
|
|
124 | self.repoerror(_("unexpected response '%s'") % l) | |
|
121 | 125 | return r.read(l) |
|
122 | 126 | |
|
123 | 127 | def lock(self): |
|
124 | 128 | self.call("lock") |
|
125 | 129 | return remotelock(self) |
|
126 | 130 | |
|
127 | 131 | def unlock(self): |
|
128 | 132 | self.call("unlock") |
|
129 | 133 | |
|
130 | 134 | def heads(self): |
|
131 | 135 | d = self.call("heads") |
|
132 | 136 | try: |
|
133 | 137 | return map(bin, d[:-1].split(" ")) |
|
134 | 138 | except: |
|
135 |
|
|
|
139 | self.repoerror(_("unexpected response '%s'") % (d[:400] + "...")) | |
|
136 | 140 | |
|
137 | 141 | def branches(self, nodes): |
|
138 | 142 | n = " ".join(map(hex, nodes)) |
|
139 | 143 | d = self.call("branches", nodes=n) |
|
140 | 144 | try: |
|
141 | 145 | br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ] |
|
142 | 146 | return br |
|
143 | 147 | except: |
|
144 |
|
|
|
148 | self.repoerror(_("unexpected response '%s'") % (d[:400] + "...")) | |
|
145 | 149 | |
|
146 | 150 | def between(self, pairs): |
|
147 | 151 | n = "\n".join(["-".join(map(hex, p)) for p in pairs]) |
|
148 | 152 | d = self.call("between", pairs=n) |
|
149 | 153 | try: |
|
150 | 154 | p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ] |
|
151 | 155 | return p |
|
152 | 156 | except: |
|
153 |
|
|
|
157 | self.repoerror(_("unexpected response '%s'") % (d[:400] + "...")) | |
|
154 | 158 | |
|
155 | 159 | def changegroup(self, nodes, kind): |
|
156 | 160 | n = " ".join(map(hex, nodes)) |
|
157 | 161 | return self.do_cmd("changegroup", roots=n) |
|
158 | 162 | |
|
159 | 163 | def unbundle(self, cg, heads, source): |
|
160 | 164 | d = self.call("unbundle", heads=' '.join(map(hex, heads))) |
|
161 | 165 | if d: |
|
162 |
|
|
|
166 | self.repoerror(_("push refused: %s") % d) | |
|
163 | 167 | |
|
164 | 168 | while 1: |
|
165 | 169 | d = cg.read(4096) |
|
166 | 170 | if not d: break |
|
167 | 171 | self.pipeo.write(str(len(d)) + '\n') |
|
168 | 172 | self.pipeo.write(d) |
|
169 | 173 | self.readerr() |
|
170 | 174 | |
|
171 | 175 | self.pipeo.write('0\n') |
|
172 | 176 | self.pipeo.flush() |
|
173 | 177 | |
|
174 | 178 | self.readerr() |
|
175 | 179 | d = self.pipei.readline() |
|
176 | 180 | if d != '\n': |
|
177 | 181 | return 1 |
|
178 | 182 | |
|
179 | 183 | l = int(self.pipei.readline()) |
|
180 | 184 | r = self.pipei.read(l) |
|
181 | 185 | if not r: |
|
182 | 186 | return 1 |
|
183 | 187 | return int(r) |
|
184 | 188 | |
|
185 | 189 | def addchangegroup(self, cg, source, url): |
|
186 | 190 | d = self.call("addchangegroup") |
|
187 | 191 | if d: |
|
188 |
|
|
|
192 | self.repoerror(_("push refused: %s") % d) | |
|
189 | 193 | while 1: |
|
190 | 194 | d = cg.read(4096) |
|
191 | 195 | if not d: break |
|
192 | 196 | self.pipeo.write(d) |
|
193 | 197 | self.readerr() |
|
194 | 198 | |
|
195 | 199 | self.pipeo.flush() |
|
196 | 200 | |
|
197 | 201 | self.readerr() |
|
198 | 202 | l = int(self.pipei.readline()) |
|
199 | 203 | r = self.pipei.read(l) |
|
200 | 204 | if not r: |
|
201 | 205 | return 1 |
|
202 | 206 | return int(r) |
|
203 | 207 | |
|
204 | 208 | def stream_out(self): |
|
205 | 209 | return self.do_cmd('stream_out') |
|
206 | 210 | |
|
207 | 211 | instance = sshrepository |
@@ -1,93 +1,93 | |||
|
1 | 1 | # creating 'remote' |
|
2 | 2 | # repo not found error |
|
3 | remote: abort: repository nonexistent not found! | |
|
3 | 4 | abort: no suitable response from remote hg! |
|
4 | remote: abort: repository nonexistent not found! | |
|
5 | 5 | # clone remote via stream |
|
6 | 6 | streaming all changes |
|
7 | 7 | XXX files to transfer, XXX bytes of data |
|
8 | 8 | transferred XXX bytes in XXX seconds (XXX XB/sec) |
|
9 | 9 | XXX files updated, XXX files merged, XXX files removed, XXX files unresolved |
|
10 | 10 | checking changesets |
|
11 | 11 | checking manifests |
|
12 | 12 | crosschecking files in changesets and manifests |
|
13 | 13 | checking files |
|
14 | 14 | 1 files, 1 changesets, 1 total revisions |
|
15 | 15 | # clone remote via pull |
|
16 | 16 | requesting all changes |
|
17 | 17 | adding changesets |
|
18 | 18 | adding manifests |
|
19 | 19 | adding file changes |
|
20 | 20 | added 1 changesets with 1 changes to 1 files |
|
21 | 21 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
22 | 22 | # verify |
|
23 | 23 | checking changesets |
|
24 | 24 | checking manifests |
|
25 | 25 | crosschecking files in changesets and manifests |
|
26 | 26 | checking files |
|
27 | 27 | 1 files, 1 changesets, 1 total revisions |
|
28 | 28 | # empty default pull |
|
29 | 29 | default = ssh://user@dummy/remote |
|
30 | 30 | pulling from ssh://user@dummy/remote |
|
31 | 31 | searching for changes |
|
32 | 32 | no changes found |
|
33 | 33 | # local change |
|
34 | 34 | # updating rc |
|
35 | 35 | # find outgoing |
|
36 | 36 | searching for changes |
|
37 | 37 | changeset: 1:c54836a570be |
|
38 | 38 | tag: tip |
|
39 | 39 | user: test |
|
40 | 40 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
41 | 41 | summary: add |
|
42 | 42 | |
|
43 | 43 | # find incoming on the remote side |
|
44 | 44 | searching for changes |
|
45 | 45 | changeset: 1:c54836a570be |
|
46 | 46 | tag: tip |
|
47 | 47 | user: test |
|
48 | 48 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
49 | 49 | summary: add |
|
50 | 50 | |
|
51 | 51 | # push |
|
52 | 52 | pushing to ssh://user@dummy/remote |
|
53 | 53 | searching for changes |
|
54 | 54 | remote: adding changesets |
|
55 | 55 | remote: adding manifests |
|
56 | 56 | remote: adding file changes |
|
57 | 57 | remote: added 1 changesets with 1 changes to 1 files |
|
58 | 58 | # check remote tip |
|
59 | 59 | changeset: 1:c54836a570be |
|
60 | 60 | tag: tip |
|
61 | 61 | user: test |
|
62 | 62 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
63 | 63 | summary: add |
|
64 | 64 | |
|
65 | 65 | checking changesets |
|
66 | 66 | checking manifests |
|
67 | 67 | crosschecking files in changesets and manifests |
|
68 | 68 | checking files |
|
69 | 69 | 1 files, 2 changesets, 2 total revisions |
|
70 | 70 | bleah |
|
71 | 71 | # push should fail |
|
72 | 72 | pushing to ssh://user@dummy/remote |
|
73 | 73 | searching for changes |
|
74 | 74 | abort: unsynced remote changes! |
|
75 | 75 | (did you forget to sync? use push -f to force) |
|
76 | 76 | # push should succeed |
|
77 | 77 | pushing to ssh://user@dummy/remote |
|
78 | 78 | searching for changes |
|
79 | 79 | remote: adding changesets |
|
80 | 80 | remote: adding manifests |
|
81 | 81 | remote: adding file changes |
|
82 | 82 | remote: added 1 changesets with 1 changes to 1 files |
|
83 | 83 | Got arguments 1:user@dummy 2:hg -R nonexistent serve --stdio 3: 4: 5: |
|
84 | 84 | Got arguments 1:user@dummy 2:hg -R remote serve --stdio 3: 4: 5: |
|
85 | 85 | Got arguments 1:user@dummy 2:hg -R remote serve --stdio 3: 4: 5: |
|
86 | 86 | Got arguments 1:user@dummy 2:hg -R remote serve --stdio 3: 4: 5: |
|
87 | 87 | Got arguments 1:user@dummy 2:hg -R remote serve --stdio 3: 4: 5: |
|
88 | 88 | Got arguments 1:user@dummy 2:hg -R local serve --stdio 3: 4: 5: |
|
89 | 89 | Got arguments 1:user@dummy 2:hg -R remote serve --stdio 3: 4: 5: |
|
90 | 90 | changegroup in remote: u=remote:ssh:127.0.0.1 |
|
91 | 91 | Got arguments 1:user@dummy 2:hg -R remote serve --stdio 3: 4: 5: |
|
92 | 92 | Got arguments 1:user@dummy 2:hg -R remote serve --stdio 3: 4: 5: |
|
93 | 93 | changegroup in remote: u=remote:ssh:127.0.0.1 |
General Comments 0
You need to be logged in to leave comments.
Login now