39
39
ENABLE_URLGRABBER = True
41
from bzrlib.errors import BzrError
43
class GetFailed(BzrError):
44
def __init__(self, url, status):
45
BzrError.__init__(self, "Get %s failed with status %s" % (url, status))
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)
152
143
pl = len(self.baseurl)
153
144
return path[pl:].lstrip('/')
156
146
def get_revision(self, revision_id):
157
from bzrlib.revision import Revision
158
from bzrlib.xml import unpack_xml
159
revf = self.revision_store[revision_id]
160
r = unpack_xml(Revision, revf)
147
from revision import Revision
148
revf = get_url(self.baseurl + '/.bzr/revision-store/' + revision_id,
150
r = Revision.read_xml(revf)
161
151
if r.revision_id != revision_id:
162
152
raise BzrCheckError('revision stored as {%s} actually contains {%s}'
163
153
% (revision_id, r.revision_id))
177
167
def __getitem__(self, fileid):
178
168
p = self._path(fileid)
180
return get_url(p, compressed=True)
182
raise KeyError(fileid)
169
return get_url(p, compressed=True)
173
"""For experimental purposes, traverse many parts of a remote branch"""
174
from revision import Revision
175
from branch import Branch
176
from inventory import Inventory
182
history = get_url('/.bzr/revision-history').readlines()
183
num_revs = len(history)
184
for i, rev_id in enumerate(history):
185
rev_id = rev_id.rstrip()
186
print 'read revision %d/%d' % (i, num_revs)
188
# python gzip needs a seekable file (!!) but the HTTP response
189
# isn't, so we need to buffer it
191
rev_f = get_url('/.bzr/revision-store/%s' % rev_id,
194
rev = Revision.read_xml(rev_f)
196
inv_id = rev.inventory_id
197
if inv_id not in got_invs:
198
print 'get inventory %s' % inv_id
199
inv_f = get_url('/.bzr/inventory-store/%s' % inv_id,
201
inv = Inventory.read_xml(inv_f)
202
print '%4d inventory entries' % len(inv)
204
for path, ie in inv.iter_entries():
208
if text_id in got_texts:
210
print ' fetch %s text {%s}' % (path, text_id)
211
text_f = get_url('/.bzr/text-store/%s' % text_id,
213
got_texts[text_id] = True
215
got_invs.add[inv_id] = True
221
BASE_URL = 'http://bazaar-ng.org/bzr/bzr.dev/'
222
b = RemoteBranch(BASE_URL)
223
## print '\n'.join(b.revision_history())
224
from log import show_log
228
if __name__ == '__main__':