comparison mercurial/sshrepo.py @ 1251:84cf8834efb5

Fix lots of exception-related problems. These have been around since the Big Code Split.
author Bryan O'Sullivan <bos@serpentine.com>
date Wed, 14 Sep 2005 15:41:22 -0700
parents 808a9f0e7af0
children 0fcde73dc3ca
comparison
equal deleted inserted replaced
1250:0ad3f9b27260 1251:84cf8834efb5
3 # Copyright 2005 Matt Mackall <mpm@selenic.com> 3 # Copyright 2005 Matt Mackall <mpm@selenic.com>
4 # 4 #
5 # This software may be used and distributed according to the terms 5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference. 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 import os, re, select
9 from node import * 8 from node import *
10 from remoterepo import * 9 from remoterepo import *
10 from demandload import *
11 demandload(globals(), "hg os re select")
11 12
12 class sshrepository(remoterepository): 13 class sshrepository(remoterepository):
13 def __init__(self, ui, path): 14 def __init__(self, ui, path):
14 self.url = path 15 self.url = path
15 self.ui = ui 16 self.ui = ui
16 17
17 m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', path) 18 m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', path)
18 if not m: 19 if not m:
19 raise RepoError("couldn't parse destination %s" % path) 20 raise hg.RepoError("couldn't parse destination %s" % path)
20 21
21 self.user = m.group(2) 22 self.user = m.group(2)
22 self.host = m.group(3) 23 self.host = m.group(3)
23 self.port = m.group(5) 24 self.port = m.group(5)
24 self.path = m.group(7) or "." 25 self.path = m.group(7) or "."
69 l = r.readline() 70 l = r.readline()
70 self.readerr() 71 self.readerr()
71 try: 72 try:
72 l = int(l) 73 l = int(l)
73 except: 74 except:
74 raise RepoError("unexpected response '%s'" % l) 75 raise hg.RepoError("unexpected response '%s'" % l)
75 return r.read(l) 76 return r.read(l)
76 77
77 def lock(self): 78 def lock(self):
78 self.call("lock") 79 self.call("lock")
79 return remotelock(self) 80 return remotelock(self)
84 def heads(self): 85 def heads(self):
85 d = self.call("heads") 86 d = self.call("heads")
86 try: 87 try:
87 return map(bin, d[:-1].split(" ")) 88 return map(bin, d[:-1].split(" "))
88 except: 89 except:
89 raise RepoError("unexpected response '%s'" % (d[:400] + "...")) 90 raise hg.RepoError("unexpected response '%s'" % (d[:400] + "..."))
90 91
91 def branches(self, nodes): 92 def branches(self, nodes):
92 n = " ".join(map(hex, nodes)) 93 n = " ".join(map(hex, nodes))
93 d = self.call("branches", nodes=n) 94 d = self.call("branches", nodes=n)
94 try: 95 try:
95 br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ] 96 br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ]
96 return br 97 return br
97 except: 98 except:
98 raise RepoError("unexpected response '%s'" % (d[:400] + "...")) 99 raise hg.RepoError("unexpected response '%s'" % (d[:400] + "..."))
99 100
100 def between(self, pairs): 101 def between(self, pairs):
101 n = "\n".join(["-".join(map(hex, p)) for p in pairs]) 102 n = "\n".join(["-".join(map(hex, p)) for p in pairs])
102 d = self.call("between", pairs=n) 103 d = self.call("between", pairs=n)
103 try: 104 try:
104 p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ] 105 p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ]
105 return p 106 return p
106 except: 107 except:
107 raise RepoError("unexpected response '%s'" % (d[:400] + "...")) 108 raise hg.RepoError("unexpected response '%s'" % (d[:400] + "..."))
108 109
109 def changegroup(self, nodes): 110 def changegroup(self, nodes):
110 n = " ".join(map(hex, nodes)) 111 n = " ".join(map(hex, nodes))
111 f = self.do_cmd("changegroup", roots=n) 112 f = self.do_cmd("changegroup", roots=n)
112 return self.pipei 113 return self.pipei
113 114
114 def addchangegroup(self, cg): 115 def addchangegroup(self, cg):
115 d = self.call("addchangegroup") 116 d = self.call("addchangegroup")
116 if d: 117 if d:
117 raise RepoError("push refused: %s", d) 118 raise hg.RepoError("push refused: %s", d)
118 119
119 while 1: 120 while 1:
120 d = cg.read(4096) 121 d = cg.read(4096)
121 if not d: break 122 if not d: break
122 self.pipeo.write(d) 123 self.pipeo.write(d)