28
28
from cStringIO import StringIO
33
from bzrlib.errors import BzrError, BzrCheckError
34
from bzrlib.branch import Branch, BZR_BRANCH_FORMAT
35
from bzrlib.trace import mutter
36
from bzrlib.xml import serializer_v4
39
ENABLE_URLGRABBER = False
41
from bzrlib.errors import BzrError, NoSuchRevision
43
class GetFailed(BzrError):
44
def __init__(self, url, status):
45
BzrError.__init__(self, "Get %s failed with status %s" % (url, status))
31
from errors import BzrError, BzrCheckError
32
from branch import Branch, BZR_BRANCH_FORMAT
33
from trace import mutter
35
# velocitynet.com.au transparently proxies connections and thereby
36
# breaks keep-alive -- sucks!
39
ENABLE_URLGRABBER = True
49
42
if ENABLE_URLGRABBER:
50
import util.urlgrabber
51
import util.urlgrabber.keepalive
52
util.urlgrabber.keepalive.DEBUG = 0
44
import urlgrabber.keepalive
45
urlgrabber.keepalive.DEBUG = 0
53
46
def get_url(path, compressed=False):
58
51
mutter("grab url %s" % url)
59
url_f = util.urlgrabber.urlopen(url, keepalive=1, close_connection=0)
60
if url_f.status != 200:
61
raise GetFailed(url, url_f.status)
52
url_f = urlgrabber.urlopen(url, keepalive=1, close_connection=0)
98
89
except urllib2.URLError:
101
scheme, host, path = list(urlparse.urlparse(url))[:3]
102
# discard params, query, fragment
104
# strip off one component of the path component
105
idx = path.rfind('/')
106
if idx == -1 or path == '/':
107
raise BzrError('no branch root found for URL %s'
108
' or enclosing directories'
111
url = urlparse.urlunparse((scheme, host, path, '', '', ''))
95
raise BzrError('no branch root found for URL %s' % orig_url)
116
102
def __init__(self, baseurl, find_root=True):
117
103
"""Create new proxy for a remote branch."""
119
self.base = _find_remote_root(baseurl)
105
self.baseurl = _find_remote_root(baseurl)
107
self.baseurl = baseurl
122
108
self._check_format()
124
110
self.inventory_store = RemoteStore(baseurl + '/.bzr/inventory-store/')
134
120
def controlfile(self, filename, mode):
135
121
if mode not in ('rb', 'rt', 'r'):
136
122
raise BzrError("file mode %r not supported for remote branches" % mode)
137
return get_url(self.base + '/.bzr/' + filename, False)
123
return get_url(self.baseurl + '/.bzr/' + filename, False)
140
126
def lock_read(self):
144
130
def lock_write(self):
145
131
from errors import LockError
146
132
raise LockError("write lock not supported for remote branch %s"
149
135
def unlock(self):
153
139
def relpath(self, path):
154
if not path.startswith(self.base):
140
if not path.startswith(self.baseurl):
155
141
raise BzrError('path %r is not under base URL %r'
142
% (path, self.baseurl))
143
pl = len(self.baseurl)
158
144
return path[pl:].lstrip('/')
161
147
def get_revision(self, revision_id):
163
revf = self.revision_store[revision_id]
165
raise NoSuchRevision(self, revision_id)
166
r = serializer_v4.read_revision(revf)
148
from bzrlib.revision import Revision
149
from bzrlib.xml import unpack_xml
150
revf = self.revision_store[revision_id]
151
r = unpack_xml(Revision, revf)
167
152
if r.revision_id != revision_id:
168
153
raise BzrCheckError('revision stored as {%s} actually contains {%s}'
169
154
% (revision_id, r.revision_id))