64 capabilities = property(get_caps) |
64 capabilities = property(get_caps) |
65 |
65 |
66 def lock(self): |
66 def lock(self): |
67 raise util.Abort(_('operation not supported over http')) |
67 raise util.Abort(_('operation not supported over http')) |
68 |
68 |
69 def do_cmd(self, cmd, **args): |
69 def _callstream(self, cmd, **args): |
70 data = args.pop('data', None) |
70 data = args.pop('data', None) |
71 headers = args.pop('headers', {}) |
71 headers = args.pop('headers', {}) |
72 self.ui.debug("sending %s command\n" % cmd) |
72 self.ui.debug("sending %s command\n" % cmd) |
73 q = {"cmd": cmd} |
73 q = {"cmd": cmd} |
74 q.update(args) |
74 q.update(args) |
128 raise error.RepoError(_("'%s' uses newer protocol %s") % |
128 raise error.RepoError(_("'%s' uses newer protocol %s") % |
129 (safeurl, version)) |
129 (safeurl, version)) |
130 |
130 |
131 return resp |
131 return resp |
132 |
132 |
133 def do_read(self, cmd, **args): |
133 def _call(self, cmd, **args): |
134 fp = self.do_cmd(cmd, **args) |
134 fp = self._callstream(cmd, **args) |
135 try: |
135 try: |
136 return fp.read() |
136 return fp.read() |
137 finally: |
137 finally: |
138 # if using keepalive, allow connection to be reused |
138 # if using keepalive, allow connection to be reused |
139 fp.close() |
139 fp.close() |
140 |
140 |
141 def _call(self, cmd, **args): |
|
142 return self.do_read(cmd, **args) |
|
143 |
|
144 def _callstream(self, cmd, **args): |
|
145 return self.do_cmd(cmd, **args) |
|
146 |
|
147 def _abort(self, exception): |
141 def _abort(self, exception): |
148 raise exception |
142 raise exception |
149 |
143 |
150 def changegroup(self, nodes, kind): |
144 def changegroup(self, nodes, kind): |
151 n = " ".join(map(hex, nodes)) |
145 n = " ".join(map(hex, nodes)) |
152 f = self.do_cmd("changegroup", roots=n) |
146 f = self._callstream("changegroup", roots=n) |
153 return util.chunkbuffer(zgenerator(f)) |
147 return util.chunkbuffer(zgenerator(f)) |
154 |
148 |
155 def changegroupsubset(self, bases, heads, source): |
149 def changegroupsubset(self, bases, heads, source): |
156 self.requirecap('changegroupsubset', _('look up remote changes')) |
150 self.requirecap('changegroupsubset', _('look up remote changes')) |
157 baselst = " ".join([hex(n) for n in bases]) |
151 baselst = " ".join([hex(n) for n in bases]) |
158 headlst = " ".join([hex(n) for n in heads]) |
152 headlst = " ".join([hex(n) for n in heads]) |
159 f = self.do_cmd("changegroupsubset", bases=baselst, heads=headlst) |
153 f = self._callstream("changegroupsubset", bases=baselst, heads=headlst) |
160 return util.chunkbuffer(zgenerator(f)) |
154 return util.chunkbuffer(zgenerator(f)) |
161 |
155 |
162 def unbundle(self, cg, heads, source): |
156 def unbundle(self, cg, heads, source): |
163 '''Send cg (a readable file-like object representing the |
157 '''Send cg (a readable file-like object representing the |
164 changegroup to push, typically a chunkbuffer object) to the |
158 changegroup to push, typically a chunkbuffer object) to the |
185 |
179 |
186 tempname = changegroup.writebundle(cg, None, type) |
180 tempname = changegroup.writebundle(cg, None, type) |
187 fp = url.httpsendfile(tempname, "rb") |
181 fp = url.httpsendfile(tempname, "rb") |
188 try: |
182 try: |
189 try: |
183 try: |
190 resp = self.do_read( |
184 resp = self._call( |
191 'unbundle', data=fp, |
185 'unbundle', data=fp, |
192 headers={'Content-Type': 'application/mercurial-0.1'}, |
186 headers={'Content-Type': 'application/mercurial-0.1'}, |
193 heads=' '.join(map(hex, heads))) |
187 heads=' '.join(map(hex, heads))) |
194 resp_code, output = resp.split('\n', 1) |
188 resp_code, output = resp.split('\n', 1) |
195 try: |
189 try: |