Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/sshrepo.py @ 11589:e8d22fe2ddab
protocol: clean up call-like functions in http and ssh clients
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 14 Jul 2010 17:07:10 -0500 |
parents | 8a1f625e971d |
children | 0b15aee0a306 |
comparison
equal
deleted
inserted
replaced
11588:8a1f625e971d | 11589:e8d22fe2ddab |
---|---|
63 cmd = util.quotecommand(cmd) | 63 cmd = util.quotecommand(cmd) |
64 ui.note(_('running %s\n') % cmd) | 64 ui.note(_('running %s\n') % cmd) |
65 self.pipeo, self.pipei, self.pipee = util.popen3(cmd) | 65 self.pipeo, self.pipei, self.pipee = util.popen3(cmd) |
66 | 66 |
67 # skip any noise generated by remote shell | 67 # skip any noise generated by remote shell |
68 self.do_cmd("hello") | 68 self._callstream("hello") |
69 r = self.do_cmd("between", pairs=("%s-%s" % ("0"*40, "0"*40))) | 69 r = self._callstream("between", pairs=("%s-%s" % ("0"*40, "0"*40))) |
70 lines = ["", "dummy"] | 70 lines = ["", "dummy"] |
71 max_noise = 500 | 71 max_noise = 500 |
72 while lines[-1] and max_noise: | 72 while lines[-1] and max_noise: |
73 l = r.readline() | 73 l = r.readline() |
74 self.readerr() | 74 self.readerr() |
116 except: | 116 except: |
117 pass | 117 pass |
118 | 118 |
119 __del__ = cleanup | 119 __del__ = cleanup |
120 | 120 |
121 def do_cmd(self, cmd, **args): | 121 def _callstream(self, cmd, **args): |
122 self.ui.debug("sending %s command\n" % cmd) | 122 self.ui.debug("sending %s command\n" % cmd) |
123 self.pipeo.write("%s\n" % cmd) | 123 self.pipeo.write("%s\n" % cmd) |
124 for k, v in sorted(args.iteritems()): | 124 for k, v in sorted(args.iteritems()): |
125 self.pipeo.write("%s %d\n" % (k, len(v))) | 125 self.pipeo.write("%s %d\n" % (k, len(v))) |
126 self.pipeo.write(v) | 126 self.pipeo.write(v) |
127 self.pipeo.flush() | 127 self.pipeo.flush() |
128 | 128 |
129 return self.pipei | 129 return self.pipei |
130 | 130 |
131 def call(self, cmd, **args): | 131 def _call(self, cmd, **args): |
132 self.do_cmd(cmd, **args) | 132 self._callstream(cmd, **args) |
133 return self._recv() | 133 return self._recv() |
134 | |
135 def _call(self, cmd, **args): | |
136 self.do_cmd(cmd, **args) | |
137 return self._recv() | |
138 | |
139 def _callstream(self, cmd, **args): | |
140 return self.do_cmd(cmd, **args) | |
141 | 134 |
142 def _recv(self): | 135 def _recv(self): |
143 l = self.pipei.readline() | 136 l = self.pipei.readline() |
144 self.readerr() | 137 self.readerr() |
145 try: | 138 try: |
155 if flush: | 148 if flush: |
156 self.pipeo.flush() | 149 self.pipeo.flush() |
157 self.readerr() | 150 self.readerr() |
158 | 151 |
159 def lock(self): | 152 def lock(self): |
160 self.call("lock") | 153 self._call("lock") |
161 return remotelock(self) | 154 return remotelock(self) |
162 | 155 |
163 def unlock(self): | 156 def unlock(self): |
164 self.call("unlock") | 157 self._call("unlock") |
165 | 158 |
166 def changegroup(self, nodes, kind): | 159 def changegroup(self, nodes, kind): |
167 n = " ".join(map(hex, nodes)) | 160 n = " ".join(map(hex, nodes)) |
168 return self.do_cmd("changegroup", roots=n) | 161 return self._callstream("changegroup", roots=n) |
169 | 162 |
170 def changegroupsubset(self, bases, heads, kind): | 163 def changegroupsubset(self, bases, heads, kind): |
171 self.requirecap('changegroupsubset', _('look up remote changes')) | 164 self.requirecap('changegroupsubset', _('look up remote changes')) |
172 bases = " ".join(map(hex, bases)) | 165 bases = " ".join(map(hex, bases)) |
173 heads = " ".join(map(hex, heads)) | 166 heads = " ".join(map(hex, heads)) |
174 return self.do_cmd("changegroupsubset", bases=bases, heads=heads) | 167 return self._callstream("changegroupsubset", bases=bases, heads=heads) |
175 | 168 |
176 def unbundle(self, cg, heads, source): | 169 def unbundle(self, cg, heads, source): |
177 '''Send cg (a readable file-like object representing the | 170 '''Send cg (a readable file-like object representing the |
178 changegroup to push, typically a chunkbuffer object) to the | 171 changegroup to push, typically a chunkbuffer object) to the |
179 remote server as a bundle. Return an integer indicating the | 172 remote server as a bundle. Return an integer indicating the |
180 result of the push (see localrepository.addchangegroup()).''' | 173 result of the push (see localrepository.addchangegroup()).''' |
181 d = self.call("unbundle", heads=' '.join(map(hex, heads))) | 174 d = self._call("unbundle", heads=' '.join(map(hex, heads))) |
182 if d: | 175 if d: |
183 # remote may send "unsynced changes" | 176 # remote may send "unsynced changes" |
184 self.abort(error.RepoError(_("push refused: %s") % d)) | 177 self.abort(error.RepoError(_("push refused: %s") % d)) |
185 | 178 |
186 while 1: | 179 while 1: |
204 | 197 |
205 def addchangegroup(self, cg, source, url): | 198 def addchangegroup(self, cg, source, url): |
206 '''Send a changegroup to the remote server. Return an integer | 199 '''Send a changegroup to the remote server. Return an integer |
207 similar to unbundle(). DEPRECATED, since it requires locking the | 200 similar to unbundle(). DEPRECATED, since it requires locking the |
208 remote.''' | 201 remote.''' |
209 d = self.call("addchangegroup") | 202 d = self._call("addchangegroup") |
210 if d: | 203 if d: |
211 self.abort(error.RepoError(_("push refused: %s") % d)) | 204 self.abort(error.RepoError(_("push refused: %s") % d)) |
212 while 1: | 205 while 1: |
213 d = cg.read(4096) | 206 d = cg.read(4096) |
214 if not d: | 207 if not d: |