##// END OF EJS Templates
sshrepo: fix bug in error formatting.
Vadim Gelfer -
r2437:2f5dbc24 default
parent child Browse files
Show More
@@ -1,162 +1,162 b''
1 # sshrepo.py - ssh repository proxy class for mercurial
1 # sshrepo.py - ssh repository proxy class for mercurial
2 #
2 #
3 # Copyright 2005 Matt Mackall <mpm@selenic.com>
3 # Copyright 2005 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms
5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference.
6 # of the GNU General Public License, incorporated herein by reference.
7
7
8 from node import *
8 from node import *
9 from remoterepo import *
9 from remoterepo import *
10 from i18n import gettext as _
10 from i18n import gettext as _
11 from demandload import *
11 from demandload import *
12 demandload(globals(), "hg os re stat util")
12 demandload(globals(), "hg os re stat util")
13
13
14 class sshrepository(remoterepository):
14 class sshrepository(remoterepository):
15 def __init__(self, ui, path):
15 def __init__(self, ui, path):
16 self.url = path
16 self.url = path
17 self.ui = ui
17 self.ui = ui
18
18
19 m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', path)
19 m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', path)
20 if not m:
20 if not m:
21 raise hg.RepoError(_("couldn't parse destination %s") % path)
21 raise hg.RepoError(_("couldn't parse destination %s") % path)
22
22
23 self.user = m.group(2)
23 self.user = m.group(2)
24 self.host = m.group(3)
24 self.host = m.group(3)
25 self.port = m.group(5)
25 self.port = m.group(5)
26 self.path = m.group(7) or "."
26 self.path = m.group(7) or "."
27
27
28 args = self.user and ("%s@%s" % (self.user, self.host)) or self.host
28 args = self.user and ("%s@%s" % (self.user, self.host)) or self.host
29 args = self.port and ("%s -p %s") % (args, self.port) or args
29 args = self.port and ("%s -p %s") % (args, self.port) or args
30
30
31 sshcmd = self.ui.config("ui", "ssh", "ssh")
31 sshcmd = self.ui.config("ui", "ssh", "ssh")
32 remotecmd = self.ui.config("ui", "remotecmd", "hg")
32 remotecmd = self.ui.config("ui", "remotecmd", "hg")
33 cmd = '%s %s "%s -R %s serve --stdio"'
33 cmd = '%s %s "%s -R %s serve --stdio"'
34 cmd = cmd % (sshcmd, args, remotecmd, self.path)
34 cmd = cmd % (sshcmd, args, remotecmd, self.path)
35
35
36 ui.note('running %s\n' % cmd)
36 ui.note('running %s\n' % cmd)
37 self.pipeo, self.pipei, self.pipee = os.popen3(cmd, 'b')
37 self.pipeo, self.pipei, self.pipee = os.popen3(cmd, 'b')
38
38
39 # skip any noise generated by remote shell
39 # skip any noise generated by remote shell
40 self.do_cmd("hello")
40 self.do_cmd("hello")
41 r = self.do_cmd("between", pairs=("%s-%s" % ("0"*40, "0"*40)))
41 r = self.do_cmd("between", pairs=("%s-%s" % ("0"*40, "0"*40)))
42 lines = ["", "dummy"]
42 lines = ["", "dummy"]
43 max_noise = 500
43 max_noise = 500
44 while lines[-1] and max_noise:
44 while lines[-1] and max_noise:
45 l = r.readline()
45 l = r.readline()
46 self.readerr()
46 self.readerr()
47 if lines[-1] == "1\n" and l == "\n":
47 if lines[-1] == "1\n" and l == "\n":
48 break
48 break
49 if l:
49 if l:
50 ui.debug(_("remote: "), l)
50 ui.debug(_("remote: "), l)
51 lines.append(l)
51 lines.append(l)
52 max_noise -= 1
52 max_noise -= 1
53 else:
53 else:
54 if l1:
54 if l1:
55 ui.debug(_("remote: "), l1)
55 ui.debug(_("remote: "), l1)
56 raise hg.RepoError(_("no response from remote hg"))
56 raise hg.RepoError(_("no response from remote hg"))
57
57
58 self.capabilities = ()
58 self.capabilities = ()
59 lines.reverse()
59 lines.reverse()
60 for l in lines:
60 for l in lines:
61 if l.startswith("capabilities:"):
61 if l.startswith("capabilities:"):
62 self.capabilities = l[:-1].split(":")[1].split()
62 self.capabilities = l[:-1].split(":")[1].split()
63 break
63 break
64
64
65 def readerr(self):
65 def readerr(self):
66 while 1:
66 while 1:
67 size = util.fstat(self.pipee).st_size
67 size = util.fstat(self.pipee).st_size
68 if size == 0: break
68 if size == 0: break
69 l = self.pipee.readline()
69 l = self.pipee.readline()
70 if not l: break
70 if not l: break
71 self.ui.status(_("remote: "), l)
71 self.ui.status(_("remote: "), l)
72
72
73 def __del__(self):
73 def __del__(self):
74 try:
74 try:
75 self.pipeo.close()
75 self.pipeo.close()
76 self.pipei.close()
76 self.pipei.close()
77 # read the error descriptor until EOF
77 # read the error descriptor until EOF
78 for l in self.pipee:
78 for l in self.pipee:
79 self.ui.status(_("remote: "), l)
79 self.ui.status(_("remote: "), l)
80 self.pipee.close()
80 self.pipee.close()
81 except:
81 except:
82 pass
82 pass
83
83
84 def dev(self):
84 def dev(self):
85 return -1
85 return -1
86
86
87 def do_cmd(self, cmd, **args):
87 def do_cmd(self, cmd, **args):
88 self.ui.debug(_("sending %s command\n") % cmd)
88 self.ui.debug(_("sending %s command\n") % cmd)
89 self.pipeo.write("%s\n" % cmd)
89 self.pipeo.write("%s\n" % cmd)
90 for k, v in args.items():
90 for k, v in args.items():
91 self.pipeo.write("%s %d\n" % (k, len(v)))
91 self.pipeo.write("%s %d\n" % (k, len(v)))
92 self.pipeo.write(v)
92 self.pipeo.write(v)
93 self.pipeo.flush()
93 self.pipeo.flush()
94
94
95 return self.pipei
95 return self.pipei
96
96
97 def call(self, cmd, **args):
97 def call(self, cmd, **args):
98 r = self.do_cmd(cmd, **args)
98 r = self.do_cmd(cmd, **args)
99 l = r.readline()
99 l = r.readline()
100 self.readerr()
100 self.readerr()
101 try:
101 try:
102 l = int(l)
102 l = int(l)
103 except:
103 except:
104 raise hg.RepoError(_("unexpected response '%s'") % l)
104 raise hg.RepoError(_("unexpected response '%s'") % l)
105 return r.read(l)
105 return r.read(l)
106
106
107 def lock(self):
107 def lock(self):
108 self.call("lock")
108 self.call("lock")
109 return remotelock(self)
109 return remotelock(self)
110
110
111 def unlock(self):
111 def unlock(self):
112 self.call("unlock")
112 self.call("unlock")
113
113
114 def heads(self):
114 def heads(self):
115 d = self.call("heads")
115 d = self.call("heads")
116 try:
116 try:
117 return map(bin, d[:-1].split(" "))
117 return map(bin, d[:-1].split(" "))
118 except:
118 except:
119 raise hg.RepoError(_("unexpected response '%s'") % (d[:400] + "..."))
119 raise hg.RepoError(_("unexpected response '%s'") % (d[:400] + "..."))
120
120
121 def branches(self, nodes):
121 def branches(self, nodes):
122 n = " ".join(map(hex, nodes))
122 n = " ".join(map(hex, nodes))
123 d = self.call("branches", nodes=n)
123 d = self.call("branches", nodes=n)
124 try:
124 try:
125 br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ]
125 br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ]
126 return br
126 return br
127 except:
127 except:
128 raise hg.RepoError(_("unexpected response '%s'") % (d[:400] + "..."))
128 raise hg.RepoError(_("unexpected response '%s'") % (d[:400] + "..."))
129
129
130 def between(self, pairs):
130 def between(self, pairs):
131 n = "\n".join(["-".join(map(hex, p)) for p in pairs])
131 n = "\n".join(["-".join(map(hex, p)) for p in pairs])
132 d = self.call("between", pairs=n)
132 d = self.call("between", pairs=n)
133 try:
133 try:
134 p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ]
134 p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ]
135 return p
135 return p
136 except:
136 except:
137 raise hg.RepoError(_("unexpected response '%s'") % (d[:400] + "..."))
137 raise hg.RepoError(_("unexpected response '%s'") % (d[:400] + "..."))
138
138
139 def changegroup(self, nodes, kind):
139 def changegroup(self, nodes, kind):
140 n = " ".join(map(hex, nodes))
140 n = " ".join(map(hex, nodes))
141 f = self.do_cmd("changegroup", roots=n)
141 f = self.do_cmd("changegroup", roots=n)
142 return self.pipei
142 return self.pipei
143
143
144 def addchangegroup(self, cg, source):
144 def addchangegroup(self, cg, source):
145 d = self.call("addchangegroup")
145 d = self.call("addchangegroup")
146 if d:
146 if d:
147 raise hg.RepoError(_("push refused: %s"), d)
147 raise hg.RepoError(_("push refused: %s") % d)
148
148
149 while 1:
149 while 1:
150 d = cg.read(4096)
150 d = cg.read(4096)
151 if not d: break
151 if not d: break
152 self.pipeo.write(d)
152 self.pipeo.write(d)
153 self.readerr()
153 self.readerr()
154
154
155 self.pipeo.flush()
155 self.pipeo.flush()
156
156
157 self.readerr()
157 self.readerr()
158 l = int(self.pipei.readline())
158 l = int(self.pipei.readline())
159 r = self.pipei.read(l)
159 r = self.pipei.read(l)
160 if not r:
160 if not r:
161 return 1
161 return 1
162 return int(r)
162 return int(r)
General Comments 0
You need to be logged in to leave comments. Login now