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