##// END OF EJS Templates
sshrepo: adjust file comment
mpm@selenic.com -
r1096:ae4f1f48 default
parent child Browse files
Show More
@@ -1,127 +1,127
1 # hg.py - repository classes 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 import os, re, select
8 import os, re, select
9
9
10 class sshrepository(remoterepository):
10 class sshrepository(remoterepository):
11 def __init__(self, ui, path):
11 def __init__(self, ui, path):
12 self.url = path
12 self.url = path
13 self.ui = ui
13 self.ui = ui
14
14
15 m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', path)
15 m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', path)
16 if not m:
16 if not m:
17 raise RepoError("couldn't parse destination %s" % path)
17 raise RepoError("couldn't parse destination %s" % path)
18
18
19 self.user = m.group(2)
19 self.user = m.group(2)
20 self.host = m.group(3)
20 self.host = m.group(3)
21 self.port = m.group(5)
21 self.port = m.group(5)
22 self.path = m.group(7) or "."
22 self.path = m.group(7) or "."
23
23
24 args = self.user and ("%s@%s" % (self.user, self.host)) or self.host
24 args = self.user and ("%s@%s" % (self.user, self.host)) or self.host
25 args = self.port and ("%s -p %s") % (args, self.port) or args
25 args = self.port and ("%s -p %s") % (args, self.port) or args
26
26
27 sshcmd = self.ui.config("ui", "ssh", "ssh")
27 sshcmd = self.ui.config("ui", "ssh", "ssh")
28 remotecmd = self.ui.config("ui", "remotecmd", "hg")
28 remotecmd = self.ui.config("ui", "remotecmd", "hg")
29 cmd = "%s %s '%s -R %s serve --stdio'"
29 cmd = "%s %s '%s -R %s serve --stdio'"
30 cmd = cmd % (sshcmd, args, remotecmd, self.path)
30 cmd = cmd % (sshcmd, args, remotecmd, self.path)
31
31
32 self.pipeo, self.pipei, self.pipee = os.popen3(cmd)
32 self.pipeo, self.pipei, self.pipee = os.popen3(cmd)
33
33
34 def readerr(self):
34 def readerr(self):
35 while 1:
35 while 1:
36 r,w,x = select.select([self.pipee], [], [], 0)
36 r,w,x = select.select([self.pipee], [], [], 0)
37 if not r: break
37 if not r: break
38 l = self.pipee.readline()
38 l = self.pipee.readline()
39 if not l: break
39 if not l: break
40 self.ui.status("remote: ", l)
40 self.ui.status("remote: ", l)
41
41
42 def __del__(self):
42 def __del__(self):
43 try:
43 try:
44 self.pipeo.close()
44 self.pipeo.close()
45 self.pipei.close()
45 self.pipei.close()
46 for l in self.pipee:
46 for l in self.pipee:
47 self.ui.status("remote: ", l)
47 self.ui.status("remote: ", l)
48 self.pipee.close()
48 self.pipee.close()
49 except:
49 except:
50 pass
50 pass
51
51
52 def dev(self):
52 def dev(self):
53 return -1
53 return -1
54
54
55 def do_cmd(self, cmd, **args):
55 def do_cmd(self, cmd, **args):
56 self.ui.debug("sending %s command\n" % cmd)
56 self.ui.debug("sending %s command\n" % cmd)
57 self.pipeo.write("%s\n" % cmd)
57 self.pipeo.write("%s\n" % cmd)
58 for k, v in args.items():
58 for k, v in args.items():
59 self.pipeo.write("%s %d\n" % (k, len(v)))
59 self.pipeo.write("%s %d\n" % (k, len(v)))
60 self.pipeo.write(v)
60 self.pipeo.write(v)
61 self.pipeo.flush()
61 self.pipeo.flush()
62
62
63 return self.pipei
63 return self.pipei
64
64
65 def call(self, cmd, **args):
65 def call(self, cmd, **args):
66 r = self.do_cmd(cmd, **args)
66 r = self.do_cmd(cmd, **args)
67 l = r.readline()
67 l = r.readline()
68 self.readerr()
68 self.readerr()
69 try:
69 try:
70 l = int(l)
70 l = int(l)
71 except:
71 except:
72 raise RepoError("unexpected response '%s'" % l)
72 raise RepoError("unexpected response '%s'" % l)
73 return r.read(l)
73 return r.read(l)
74
74
75 def lock(self):
75 def lock(self):
76 self.call("lock")
76 self.call("lock")
77 return remotelock(self)
77 return remotelock(self)
78
78
79 def unlock(self):
79 def unlock(self):
80 self.call("unlock")
80 self.call("unlock")
81
81
82 def heads(self):
82 def heads(self):
83 d = self.call("heads")
83 d = self.call("heads")
84 try:
84 try:
85 return map(bin, d[:-1].split(" "))
85 return map(bin, d[:-1].split(" "))
86 except:
86 except:
87 raise RepoError("unexpected response '%s'" % (d[:400] + "..."))
87 raise RepoError("unexpected response '%s'" % (d[:400] + "..."))
88
88
89 def branches(self, nodes):
89 def branches(self, nodes):
90 n = " ".join(map(hex, nodes))
90 n = " ".join(map(hex, nodes))
91 d = self.call("branches", nodes=n)
91 d = self.call("branches", nodes=n)
92 try:
92 try:
93 br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ]
93 br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ]
94 return br
94 return br
95 except:
95 except:
96 raise RepoError("unexpected response '%s'" % (d[:400] + "..."))
96 raise RepoError("unexpected response '%s'" % (d[:400] + "..."))
97
97
98 def between(self, pairs):
98 def between(self, pairs):
99 n = "\n".join(["-".join(map(hex, p)) for p in pairs])
99 n = "\n".join(["-".join(map(hex, p)) for p in pairs])
100 d = self.call("between", pairs=n)
100 d = self.call("between", pairs=n)
101 try:
101 try:
102 p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ]
102 p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ]
103 return p
103 return p
104 except:
104 except:
105 raise RepoError("unexpected response '%s'" % (d[:400] + "..."))
105 raise RepoError("unexpected response '%s'" % (d[:400] + "..."))
106
106
107 def changegroup(self, nodes):
107 def changegroup(self, nodes):
108 n = " ".join(map(hex, nodes))
108 n = " ".join(map(hex, nodes))
109 f = self.do_cmd("changegroup", roots=n)
109 f = self.do_cmd("changegroup", roots=n)
110 return self.pipei
110 return self.pipei
111
111
112 def addchangegroup(self, cg):
112 def addchangegroup(self, cg):
113 d = self.call("addchangegroup")
113 d = self.call("addchangegroup")
114 if d:
114 if d:
115 raise RepoError("push refused: %s", d)
115 raise RepoError("push refused: %s", d)
116
116
117 while 1:
117 while 1:
118 d = cg.read(4096)
118 d = cg.read(4096)
119 if not d: break
119 if not d: break
120 self.pipeo.write(d)
120 self.pipeo.write(d)
121 self.readerr()
121 self.readerr()
122
122
123 self.pipeo.flush()
123 self.pipeo.flush()
124
124
125 self.readerr()
125 self.readerr()
126 l = int(self.pipei.readline())
126 l = int(self.pipei.readline())
127 return self.pipei.read(l) != ""
127 return self.pipei.read(l) != ""
General Comments 0
You need to be logged in to leave comments. Login now