mercurial/wireproto.py
changeset 14623 e7c9fdbbb902
parent 14622 bd88561afb4b
child 14970 592e45b7d43e
equal deleted inserted replaced
14622:bd88561afb4b 14623:e7c9fdbbb902
   159         rsp = self._call("batch", cmds=';'.join(cmds))
   159         rsp = self._call("batch", cmds=';'.join(cmds))
   160         return rsp.split(';')
   160         return rsp.split(';')
   161     def _submitone(self, op, args):
   161     def _submitone(self, op, args):
   162         return self._call(op, **args)
   162         return self._call(op, **args)
   163 
   163 
       
   164     @batchable
   164     def lookup(self, key):
   165     def lookup(self, key):
   165         self.requirecap('lookup', _('look up remote revision'))
   166         self.requirecap('lookup', _('look up remote revision'))
   166         d = self._call("lookup", key=encoding.fromlocal(key))
   167         f = future()
       
   168         yield todict(key=encoding.fromlocal(key)), f
       
   169         d = f.value
   167         success, data = d[:-1].split(" ", 1)
   170         success, data = d[:-1].split(" ", 1)
   168         if int(success):
   171         if int(success):
   169             return bin(data)
   172             yield bin(data)
   170         self._abort(error.RepoError(data))
   173         self._abort(error.RepoError(data))
   171 
   174 
       
   175     @batchable
   172     def heads(self):
   176     def heads(self):
   173         d = self._call("heads")
   177         f = future()
   174         try:
   178         yield {}, f
   175             return decodelist(d[:-1])
   179         d = f.value
       
   180         try:
       
   181             yield decodelist(d[:-1])
   176         except ValueError:
   182         except ValueError:
   177             self._abort(error.ResponseError(_("unexpected response:"), d))
   183             self._abort(error.ResponseError(_("unexpected response:"), d))
   178 
   184 
       
   185     @batchable
   179     def known(self, nodes):
   186     def known(self, nodes):
   180         n = encodelist(nodes)
   187         f = future()
   181         d = self._call("known", nodes=n)
   188         yield todict(nodes=encodelist(nodes)), f
   182         try:
   189         d = f.value
   183             return [bool(int(f)) for f in d]
   190         try:
       
   191             yield [bool(int(f)) for f in d]
   184         except ValueError:
   192         except ValueError:
   185             self._abort(error.ResponseError(_("unexpected response:"), d))
   193             self._abort(error.ResponseError(_("unexpected response:"), d))
   186 
   194 
       
   195     @batchable
   187     def branchmap(self):
   196     def branchmap(self):
   188         d = self._call("branchmap")
   197         f = future()
       
   198         yield {}, f
       
   199         d = f.value
   189         try:
   200         try:
   190             branchmap = {}
   201             branchmap = {}
   191             for branchpart in d.splitlines():
   202             for branchpart in d.splitlines():
   192                 branchname, branchheads = branchpart.split(' ', 1)
   203                 branchname, branchheads = branchpart.split(' ', 1)
   193                 branchname = encoding.tolocal(urllib.unquote(branchname))
   204                 branchname = encoding.tolocal(urllib.unquote(branchname))
   194                 branchheads = decodelist(branchheads)
   205                 branchheads = decodelist(branchheads)
   195                 branchmap[branchname] = branchheads
   206                 branchmap[branchname] = branchheads
   196             return branchmap
   207             yield branchmap
   197         except TypeError:
   208         except TypeError:
   198             self._abort(error.ResponseError(_("unexpected response:"), d))
   209             self._abort(error.ResponseError(_("unexpected response:"), d))
   199 
   210 
   200     def branches(self, nodes):
   211     def branches(self, nodes):
   201         n = encodelist(nodes)
   212         n = encodelist(nodes)
   216                 r.extend(l and decodelist(l) or [] for l in d.splitlines())
   227                 r.extend(l and decodelist(l) or [] for l in d.splitlines())
   217             except ValueError:
   228             except ValueError:
   218                 self._abort(error.ResponseError(_("unexpected response:"), d))
   229                 self._abort(error.ResponseError(_("unexpected response:"), d))
   219         return r
   230         return r
   220 
   231 
       
   232     @batchable
   221     def pushkey(self, namespace, key, old, new):
   233     def pushkey(self, namespace, key, old, new):
   222         if not self.capable('pushkey'):
   234         if not self.capable('pushkey'):
   223             return False
   235             yield False, None
   224         d = self._call("pushkey",
   236         f = future()
   225                        namespace=encoding.fromlocal(namespace),
   237         yield todict(namespace=encoding.fromlocal(namespace),
   226                        key=encoding.fromlocal(key),
   238                      key=encoding.fromlocal(key),
   227                        old=encoding.fromlocal(old),
   239                      old=encoding.fromlocal(old),
   228                        new=encoding.fromlocal(new))
   240                      new=encoding.fromlocal(new)), f
       
   241         d = f.value
   229         try:
   242         try:
   230             d = bool(int(d))
   243             d = bool(int(d))
   231         except ValueError:
   244         except ValueError:
   232             raise error.ResponseError(
   245             raise error.ResponseError(
   233                 _('push failed (unexpected response):'), d)
   246                 _('push failed (unexpected response):'), d)
   234         return d
   247         yield d
   235 
   248 
       
   249     @batchable
   236     def listkeys(self, namespace):
   250     def listkeys(self, namespace):
   237         if not self.capable('pushkey'):
   251         if not self.capable('pushkey'):
   238             return {}
   252             yield {}, None
   239         d = self._call("listkeys", namespace=encoding.fromlocal(namespace))
   253         f = future()
       
   254         yield todict(namespace=encoding.fromlocal(namespace)), f
       
   255         d = f.value
   240         r = {}
   256         r = {}
   241         for l in d.splitlines():
   257         for l in d.splitlines():
   242             k, v = l.split('\t')
   258             k, v = l.split('\t')
   243             r[encoding.tolocal(k)] = encoding.tolocal(v)
   259             r[encoding.tolocal(k)] = encoding.tolocal(v)
   244         return r
   260         yield r
   245 
   261 
   246     def stream_out(self):
   262     def stream_out(self):
   247         return self._callstream('stream_out')
   263         return self._callstream('stream_out')
   248 
   264 
   249     def changegroup(self, nodes, kind):
   265     def changegroup(self, nodes, kind):