101
102
class RemoteBranch(Branch):
102
def __init__(self, baseurl, find_root=True):
103
def __init__(self, baseurl, find_root=True, lock_mode='r'):
103
104
"""Create new proxy for a remote branch."""
105
if lock_mode not in ('', 'r'):
106
raise BzrError('lock mode %r is not supported for remote branches'
105
110
self.baseurl = _find_remote_root(baseurl)
107
112
self.baseurl = baseurl
108
113
self._check_format()
110
self.inventory_store = RemoteStore(baseurl + '/.bzr/inventory-store/')
111
self.text_store = RemoteStore(baseurl + '/.bzr/text-store/')
112
self.revision_store = RemoteStore(baseurl + '/.bzr/revision-store/')
114
115
def __str__(self):
115
b = getattr(self, 'baseurl', 'undefined')
116
return '%s(%r)' % (self.__class__.__name__, b)
116
return '%s(%r)' % (self.__class__.__name__, self.baseurl)
118
118
__repr__ = __str__
122
122
raise BzrError("file mode %r not supported for remote branches" % mode)
123
123
return get_url(self.baseurl + '/.bzr/' + filename, False)
127
# no locking for remote branches yet
130
def lock_write(self):
131
from errors import LockError
132
raise LockError("write lock not supported for remote branch %s"
125
def _need_readlock(self):
126
# remote branch always safe for read
129
def _need_writelock(self):
130
raise BzrError("cannot get write lock on HTTP remote branch")
139
132
def relpath(self, path):
140
133
if not path.startswith(self.baseurl):
143
136
pl = len(self.baseurl)
144
137
return path[pl:].lstrip('/')
147
139
def get_revision(self, revision_id):
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)
140
from revision import Revision
141
revf = get_url(self.baseurl + '/.bzr/revision-store/' + revision_id,
143
r = Revision.read_xml(revf)
152
144
if r.revision_id != revision_id:
153
145
raise BzrCheckError('revision stored as {%s} actually contains {%s}'
154
146
% (revision_id, r.revision_id))
158
class RemoteStore(object):
159
def __init__(self, baseurl):
160
self._baseurl = baseurl
163
def _path(self, name):
165
raise ValueError('invalid store id', name)
166
return self._baseurl + '/' + name
168
def __getitem__(self, fileid):
169
p = self._path(fileid)
170
return get_url(p, compressed=True)
173
150
def simple_walk():
174
"""For experimental purposes, traverse many parts of a remote branch"""
175
from bzrlib.revision import Revision
176
from bzrlib.branch import Branch
177
from bzrlib.inventory import Inventory
178
from bzrlib.xml import unpack_xml
151
from revision import Revision
152
from branch import Branch
153
from inventory import Inventory
183
158
print 'read history'
184
159
history = get_url('/.bzr/revision-history').readlines()
193
168
rev_f = get_url('/.bzr/revision-store/%s' % rev_id,
196
rev = unpack_xml(Revision, rev_f)
171
rev = Revision.read_xml(rev_f)
197
172
print rev.message
198
173
inv_id = rev.inventory_id
199
174
if inv_id not in got_invs:
212
187
print ' fetch %s text {%s}' % (path, text_id)
213
188
text_f = get_url('/.bzr/text-store/%s' % text_id,
215
got_texts[text_id] = True
190
got_texts.add(text_id)
217
got_invs.add[inv_id] = True