188
by mbp at sourcefrog
- experimental remote-branch support |
1 |
# Copyright (C) 2005 Canonical Ltd
|
2 |
||
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
||
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
||
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
||
18 |
## XXX: This is pretty slow on high-latency connections because it
|
|
19 |
## doesn't keep the HTTP connection alive. If you have a smart local
|
|
20 |
## proxy it may be much better. Eventually I want to switch to
|
|
21 |
## urlgrabber which should use HTTP much more efficiently.
|
|
22 |
||
23 |
||
24 |
import urllib2, gzip, zlib |
|
192
by mbp at sourcefrog
- exercise the network more towards doing a remote clone |
25 |
from sets import Set |
26 |
from cStringIO import StringIO |
|
188
by mbp at sourcefrog
- experimental remote-branch support |
27 |
|
28 |
from errors import BzrError |
|
29 |
from revision import Revision |
|
192
by mbp at sourcefrog
- exercise the network more towards doing a remote clone |
30 |
from inventory import Inventory |
188
by mbp at sourcefrog
- experimental remote-branch support |
31 |
|
32 |
# h = HTTPConnection('localhost:8000')
|
|
33 |
# h = HTTPConnection('bazaar-ng.org')
|
|
34 |
||
193
by mbp at sourcefrog
more experiments with http get |
35 |
# velocitynet.com.au transparently proxies connections and thereby
|
36 |
# breaks keep-alive -- sucks!
|
|
37 |
||
38 |
||
39 |
import urlgrabber.keepalive |
|
40 |
urlgrabber.keepalive.DEBUG = 2 |
|
41 |
||
42 |
import urlgrabber |
|
43 |
||
44 |
prefix = 'http://localhost:8000' |
|
45 |
# prefix = 'http://bazaar-ng.org/bzr/main/'
|
|
188
by mbp at sourcefrog
- experimental remote-branch support |
46 |
|
192
by mbp at sourcefrog
- exercise the network more towards doing a remote clone |
47 |
def get_url(path, compressed=False): |
188
by mbp at sourcefrog
- experimental remote-branch support |
48 |
try: |
49 |
url = prefix + path |
|
192
by mbp at sourcefrog
- exercise the network more towards doing a remote clone |
50 |
if compressed: |
51 |
url += '.gz' |
|
193
by mbp at sourcefrog
more experiments with http get |
52 |
url_f = urlgrabber.urlopen(url, keepalive=1, close_connection=0) |
192
by mbp at sourcefrog
- exercise the network more towards doing a remote clone |
53 |
if not compressed: |
54 |
return url_f |
|
55 |
else: |
|
56 |
return gzip.GzipFile(fileobj=StringIO(url_f.read())) |
|
188
by mbp at sourcefrog
- experimental remote-branch support |
57 |
except urllib2.URLError, e: |
58 |
raise BzrError("remote fetch failed: %r: %s" % (url, e)) |
|
59 |
||
192
by mbp at sourcefrog
- exercise the network more towards doing a remote clone |
60 |
|
61 |
got_invs = Set() |
|
62 |
got_texts = Set() |
|
63 |
||
188
by mbp at sourcefrog
- experimental remote-branch support |
64 |
print 'read history' |
192
by mbp at sourcefrog
- exercise the network more towards doing a remote clone |
65 |
history = get_url('/.bzr/revision-history').readlines() |
66 |
num_revs = len(history) |
|
188
by mbp at sourcefrog
- experimental remote-branch support |
67 |
for i, rev_id in enumerate(history): |
192
by mbp at sourcefrog
- exercise the network more towards doing a remote clone |
68 |
rev_id = rev_id.rstrip() |
69 |
print 'read revision %d/%d' % (i, num_revs) |
|
188
by mbp at sourcefrog
- experimental remote-branch support |
70 |
|
71 |
# python gzip needs a seekable file (!!) but the HTTP response
|
|
72 |
# isn't, so we need to buffer it
|
|
73 |
||
192
by mbp at sourcefrog
- exercise the network more towards doing a remote clone |
74 |
rev_f = get_url('/.bzr/revision-store/%s' % rev_id, |
75 |
compressed=True) |
|
188
by mbp at sourcefrog
- experimental remote-branch support |
76 |
|
192
by mbp at sourcefrog
- exercise the network more towards doing a remote clone |
77 |
rev = Revision.read_xml(rev_f) |
188
by mbp at sourcefrog
- experimental remote-branch support |
78 |
print rev.message |
192
by mbp at sourcefrog
- exercise the network more towards doing a remote clone |
79 |
inv_id = rev.inventory_id |
80 |
if inv_id not in got_invs: |
|
81 |
print 'get inventory %s' % inv_id |
|
82 |
inv_f = get_url('/.bzr/inventory-store/%s' % inv_id, |
|
83 |
compressed=True) |
|
84 |
inv = Inventory.read_xml(inv_f) |
|
85 |
print '%4d inventory entries' % len(inv) |
|
86 |
||
87 |
for path, ie in inv.iter_entries(): |
|
88 |
text_id = ie.text_id |
|
89 |
if text_id == None: |
|
90 |
continue
|
|
91 |
if text_id in got_texts: |
|
92 |
continue
|
|
93 |
print ' fetch %s text {%s}' % (path, text_id) |
|
94 |
text_f = get_url('/.bzr/text-store/%s' % text_id, |
|
95 |
compressed=True) |
|
96 |
got_texts.add(text_id) |
|
97 |
||
98 |
got_invs.add(inv_id) |
|
99 |
||
188
by mbp at sourcefrog
- experimental remote-branch support |
100 |
print '----' |