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