/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
35
192 by mbp at sourcefrog
- exercise the network more towards doing a remote clone
36
# prefix = 'http://localhost:8000'
37
prefix = 'http://bazaar-ng.org/bzr/main/'
188 by mbp at sourcefrog
- experimental remote-branch support
38
192 by mbp at sourcefrog
- exercise the network more towards doing a remote clone
39
def get_url(path, compressed=False):
188 by mbp at sourcefrog
- experimental remote-branch support
40
    try:
41
        url = prefix + path
192 by mbp at sourcefrog
- exercise the network more towards doing a remote clone
42
        if compressed:
43
            url += '.gz'
44
        url_f = urllib2.urlopen(url)
45
        if not compressed:
46
            return url_f
47
        else:
48
            return gzip.GzipFile(fileobj=StringIO(url_f.read()))
188 by mbp at sourcefrog
- experimental remote-branch support
49
    except urllib2.URLError, e:
50
        raise BzrError("remote fetch failed: %r: %s" % (url, e))
51
192 by mbp at sourcefrog
- exercise the network more towards doing a remote clone
52
53
got_invs = Set()
54
got_texts = Set()
55
188 by mbp at sourcefrog
- experimental remote-branch support
56
print 'read history'
192 by mbp at sourcefrog
- exercise the network more towards doing a remote clone
57
history = get_url('/.bzr/revision-history').readlines()
58
num_revs = len(history)
188 by mbp at sourcefrog
- experimental remote-branch support
59
for i, rev_id in enumerate(history):
192 by mbp at sourcefrog
- exercise the network more towards doing a remote clone
60
    rev_id = rev_id.rstrip()
61
    print 'read revision %d/%d' % (i, num_revs)
188 by mbp at sourcefrog
- experimental remote-branch support
62
63
    # python gzip needs a seekable file (!!) but the HTTP response
64
    # isn't, so we need to buffer it
65
    
192 by mbp at sourcefrog
- exercise the network more towards doing a remote clone
66
    rev_f = get_url('/.bzr/revision-store/%s' % rev_id,
67
                    compressed=True)
188 by mbp at sourcefrog
- experimental remote-branch support
68
192 by mbp at sourcefrog
- exercise the network more towards doing a remote clone
69
    rev = Revision.read_xml(rev_f)
188 by mbp at sourcefrog
- experimental remote-branch support
70
    print rev.message
192 by mbp at sourcefrog
- exercise the network more towards doing a remote clone
71
    inv_id = rev.inventory_id
72
    if inv_id not in got_invs:
73
        print 'get inventory %s' % inv_id
74
        inv_f = get_url('/.bzr/inventory-store/%s' % inv_id,
75
                        compressed=True)
76
        inv = Inventory.read_xml(inv_f)
77
        print '%4d inventory entries' % len(inv)
78
79
        for path, ie in inv.iter_entries():
80
            text_id = ie.text_id
81
            if text_id == None:
82
                continue
83
            if text_id in got_texts:
84
                continue
85
            print '  fetch %s text {%s}' % (path, text_id)
86
            text_f = get_url('/.bzr/text-store/%s' % text_id,
87
                             compressed=True)
88
            got_texts.add(text_id)
89
            
90
        got_invs.add(inv_id)
91
188 by mbp at sourcefrog
- experimental remote-branch support
92
    print '----'