mercurial/sshrepo.py
changeset 3765 768ba23c948e
parent 3764 6652209d104d
child 3766 581665242c07
equal deleted inserted replaced
3764:6652209d104d 3765:768ba23c948e
    16         self._url = path
    16         self._url = path
    17         self.ui = ui
    17         self.ui = ui
    18 
    18 
    19         m = re.match(r'^ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?$', path)
    19         m = re.match(r'^ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?$', path)
    20         if not m:
    20         if not m:
    21             self.repoerror(_("couldn't parse location %s") % path)
    21             self.raise_(hg.RepoError(_("couldn't parse location %s") % path))
    22 
    22 
    23         self.user = m.group(2)
    23         self.user = m.group(2)
    24         self.host = m.group(3)
    24         self.host = m.group(3)
    25         self.port = m.group(5)
    25         self.port = m.group(5)
    26         self.path = m.group(7) or "."
    26         self.path = m.group(7) or "."
    36             cmd = cmd % (sshcmd, args, remotecmd, self.path)
    36             cmd = cmd % (sshcmd, args, remotecmd, self.path)
    37 
    37 
    38             ui.note('running %s\n' % cmd)
    38             ui.note('running %s\n' % cmd)
    39             res = os.system(cmd)
    39             res = os.system(cmd)
    40             if res != 0:
    40             if res != 0:
    41                 self.repoerror(_("could not create remote repo"))
    41                 self.raise_(hg.RepoError(_("could not create remote repo")))
    42 
    42 
    43         self.validate_repo(ui, sshcmd, args, remotecmd)
    43         self.validate_repo(ui, sshcmd, args, remotecmd)
    44 
    44 
    45     def url(self):
    45     def url(self):
    46         return self._url
    46         return self._url
    68             if l:
    68             if l:
    69                 ui.debug(_("remote: "), l)
    69                 ui.debug(_("remote: "), l)
    70             lines.append(l)
    70             lines.append(l)
    71             max_noise -= 1
    71             max_noise -= 1
    72         else:
    72         else:
    73             self.repoerror(_("no suitable response from remote hg"))
    73             self.raise_(hg.RepoError(_("no suitable response from remote hg")))
    74 
    74 
    75         self.capabilities = ()
    75         self.capabilities = ()
    76         lines.reverse()
    76         lines.reverse()
    77         for l in lines:
    77         for l in lines:
    78             if l.startswith("capabilities:"):
    78             if l.startswith("capabilities:"):
    85             if size == 0: break
    85             if size == 0: break
    86             l = self.pipee.readline()
    86             l = self.pipee.readline()
    87             if not l: break
    87             if not l: break
    88             self.ui.status(_("remote: "), l)
    88             self.ui.status(_("remote: "), l)
    89 
    89 
    90     def repoerror(self, msg):
    90     def raise_(self, exception):
    91         self.cleanup()
    91         self.cleanup()
    92         raise hg.RepoError(msg)
    92         raise exception
    93 
    93 
    94     def cleanup(self):
    94     def cleanup(self):
    95         try:
    95         try:
    96             self.pipeo.close()
    96             self.pipeo.close()
    97             self.pipei.close()
    97             self.pipei.close()
   119         l = r.readline()
   119         l = r.readline()
   120         self.readerr()
   120         self.readerr()
   121         try:
   121         try:
   122             l = int(l)
   122             l = int(l)
   123         except:
   123         except:
   124             self.repoerror(_("unexpected response '%s'") % l)
   124             self.raise_(hg.RepoError(_("unexpected response '%s'") % l))
   125         return r.read(l)
   125         return r.read(l)
   126 
   126 
   127     def lock(self):
   127     def lock(self):
   128         self.call("lock")
   128         self.call("lock")
   129         return remotelock(self)
   129         return remotelock(self)
   135         d = self.call("lookup", key=key)
   135         d = self.call("lookup", key=key)
   136         success, data = d[:-1].split(" ", 1)
   136         success, data = d[:-1].split(" ", 1)
   137         if int(success):
   137         if int(success):
   138             return bin(data)
   138             return bin(data)
   139         else:
   139         else:
   140             self.repoerror(data)
   140             self.raise_(hg.RepoError(data))
   141 
   141 
   142     def heads(self):
   142     def heads(self):
   143         d = self.call("heads")
   143         d = self.call("heads")
   144         try:
   144         try:
   145             return map(bin, d[:-1].split(" "))
   145             return map(bin, d[:-1].split(" "))
   146         except:
   146         except:
   147             self.repoerror(_("unexpected response '%s'") % (d[:400] + "..."))
   147             self.raise_(hg.RepoError(_("unexpected response '%s'") % (d[:400] + "...")))
   148 
   148 
   149     def branches(self, nodes):
   149     def branches(self, nodes):
   150         n = " ".join(map(hex, nodes))
   150         n = " ".join(map(hex, nodes))
   151         d = self.call("branches", nodes=n)
   151         d = self.call("branches", nodes=n)
   152         try:
   152         try:
   153             br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ]
   153             br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ]
   154             return br
   154             return br
   155         except:
   155         except:
   156             self.repoerror(_("unexpected response '%s'") % (d[:400] + "..."))
   156             self.raise_(hg.RepoError(_("unexpected response '%s'") % (d[:400] + "...")))
   157 
   157 
   158     def between(self, pairs):
   158     def between(self, pairs):
   159         n = "\n".join(["-".join(map(hex, p)) for p in pairs])
   159         n = "\n".join(["-".join(map(hex, p)) for p in pairs])
   160         d = self.call("between", pairs=n)
   160         d = self.call("between", pairs=n)
   161         try:
   161         try:
   162             p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ]
   162             p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ]
   163             return p
   163             return p
   164         except:
   164         except:
   165             self.repoerror(_("unexpected response '%s'") % (d[:400] + "..."))
   165             self.raise_(hg.RepoError(_("unexpected response '%s'") % (d[:400] + "...")))
   166 
   166 
   167     def changegroup(self, nodes, kind):
   167     def changegroup(self, nodes, kind):
   168         n = " ".join(map(hex, nodes))
   168         n = " ".join(map(hex, nodes))
   169         return self.do_cmd("changegroup", roots=n)
   169         return self.do_cmd("changegroup", roots=n)
   170 
   170 
   174         return self.do_cmd("changegroupsubset", bases=bases, heads=heads)
   174         return self.do_cmd("changegroupsubset", bases=bases, heads=heads)
   175 
   175 
   176     def unbundle(self, cg, heads, source):
   176     def unbundle(self, cg, heads, source):
   177         d = self.call("unbundle", heads=' '.join(map(hex, heads)))
   177         d = self.call("unbundle", heads=' '.join(map(hex, heads)))
   178         if d:
   178         if d:
   179             self.repoerror(_("push refused: %s") % d)
   179             self.raise_(hg.RepoError(_("push refused: %s") % d))
   180 
   180 
   181         while 1:
   181         while 1:
   182             d = cg.read(4096)
   182             d = cg.read(4096)
   183             if not d: break
   183             if not d: break
   184             self.pipeo.write(str(len(d)) + '\n')
   184             self.pipeo.write(str(len(d)) + '\n')
   200         return int(r)
   200         return int(r)
   201 
   201 
   202     def addchangegroup(self, cg, source, url):
   202     def addchangegroup(self, cg, source, url):
   203         d = self.call("addchangegroup")
   203         d = self.call("addchangegroup")
   204         if d:
   204         if d:
   205             self.repoerror(_("push refused: %s") % d)
   205             self.raise_(hg.RepoError(_("push refused: %s") % d))
   206         while 1:
   206         while 1:
   207             d = cg.read(4096)
   207             d = cg.read(4096)
   208             if not d: break
   208             if not d: break
   209             self.pipeo.write(d)
   209             self.pipeo.write(d)
   210             self.readerr()
   210             self.readerr()