~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remotebranch.py

  • Committer: aaron.bentley at utoronto
  • Date: 2005-08-19 12:06:01 UTC
  • mto: (1092.1.41) (1185.3.4) (974.1.47)
  • mto: This revision was merged to the branch mainline in revision 1110.
  • Revision ID: aaron.bentley@utoronto.ca-20050819120601-58525b75283a9c1c
Initial greedy fetch work

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
ENABLE_URLGRABBER = True
40
40
 
 
41
from bzrlib.errors import BzrError
 
42
 
 
43
class GetFailed(BzrError):
 
44
    def __init__(self, url, status):
 
45
        BzrError.__init__(self, "Get %s failed with status %s" % (url, status))
 
46
        self.url = url
 
47
        self.status = status
41
48
 
42
49
if ENABLE_URLGRABBER:
43
 
    import urlgrabber
44
 
    import urlgrabber.keepalive
45
 
    urlgrabber.keepalive.DEBUG = 0
 
50
    import util.urlgrabber
 
51
    import util.urlgrabber.keepalive
 
52
    util.urlgrabber.keepalive.DEBUG = 0
46
53
    def get_url(path, compressed=False):
47
54
        try:
48
55
            url = path
49
56
            if compressed:
50
57
                url += '.gz'
51
58
            mutter("grab url %s" % url)
52
 
            url_f = urlgrabber.urlopen(url, keepalive=1, close_connection=0)
 
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)
53
62
            if not compressed:
54
63
                return url_f
55
64
            else:
143
152
        pl = len(self.baseurl)
144
153
        return path[pl:].lstrip('/')
145
154
 
 
155
 
146
156
    def get_revision(self, revision_id):
147
 
        from revision import Revision
148
 
        revf = get_url(self.baseurl + '/.bzr/revision-store/' + revision_id,
149
 
                       True)
150
 
        r = Revision.read_xml(revf)
 
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)
151
161
        if r.revision_id != revision_id:
152
162
            raise BzrCheckError('revision stored as {%s} actually contains {%s}'
153
163
                                % (revision_id, r.revision_id))
166
176
        
167
177
    def __getitem__(self, fileid):
168
178
        p = self._path(fileid)
169
 
        return get_url(p, compressed=True)
 
179
        try:
 
180
            return get_url(p, compressed=True)
 
181
        except:
 
182
            raise KeyError(fileid)
170
183
    
171
184
 
172
 
def simple_walk():
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
177
 
 
178
 
    got_invs = {}
179
 
    got_texts = {}
180
 
 
181
 
    print 'read history'
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)
187
 
 
188
 
        # python gzip needs a seekable file (!!) but the HTTP response
189
 
        # isn't, so we need to buffer it
190
 
 
191
 
        rev_f = get_url('/.bzr/revision-store/%s' % rev_id,
192
 
                        compressed=True)
193
 
 
194
 
        rev = Revision.read_xml(rev_f)
195
 
        print rev.message
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,
200
 
                            compressed=True)
201
 
            inv = Inventory.read_xml(inv_f)
202
 
            print '%4d inventory entries' % len(inv)
203
 
 
204
 
            for path, ie in inv.iter_entries():
205
 
                text_id = ie.text_id
206
 
                if text_id == None:
207
 
                    continue
208
 
                if text_id in got_texts:
209
 
                    continue
210
 
                print '  fetch %s text {%s}' % (path, text_id)
211
 
                text_f = get_url('/.bzr/text-store/%s' % text_id,
212
 
                                 compressed=True)
213
 
                got_texts[text_id] = True
214
 
 
215
 
            got_invs.add[inv_id] = True
216
 
 
217
 
        print '----'
218
 
 
219
 
 
220
 
def try_me():
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
225
 
    show_log(b)
226
 
 
227
 
 
228
 
if __name__ == '__main__':
229
 
    try_me()
230
185