[Pkg-bazaar-commits] ./bzr/unstable r411: - start adding more useful RemoteBranch() class
Martin Pool
mbp at sourcefrog.net
Fri Apr 10 07:52:13 UTC 2009
------------------------------------------------------------
revno: 411
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Mon 2005-05-09 15:42:06 +1000
message:
- start adding more useful RemoteBranch() class
modified:
bzrlib/remotebranch.py
-------------- next part --------------
=== modified file 'bzrlib/remotebranch.py'
--- a/bzrlib/remotebranch.py 2005-04-08 05:38:42 +0000
+++ b/bzrlib/remotebranch.py 2005-05-09 05:42:06 +0000
@@ -1,3 +1,5 @@
+#! /usr/bin/env python
+
# Copyright (C) 2005 Canonical Ltd
# This program is free software; you can redistribute it and/or modify
@@ -27,6 +29,7 @@
from errors import BzrError
from revision import Revision
+from branch import Branch
from inventory import Inventory
# h = HTTPConnection('localhost:8000')
@@ -41,12 +44,12 @@
import urlgrabber
-prefix = 'http://localhost:8000'
-# prefix = 'http://bazaar-ng.org/bzr/main/'
+# prefix = 'http://localhost:8000'
+BASE_URL = 'http://bazaar-ng.org/bzr/bzr.dev/'
def get_url(path, compressed=False):
try:
- url = prefix + path
+ url = path
if compressed:
url += '.gz'
url_f = urlgrabber.urlopen(url, keepalive=1, close_connection=0)
@@ -58,43 +61,75 @@
raise BzrError("remote fetch failed: %r: %s" % (url, e))
-got_invs = Set()
-got_texts = Set()
-
-print 'read history'
-history = get_url('/.bzr/revision-history').readlines()
-num_revs = len(history)
-for i, rev_id in enumerate(history):
- rev_id = rev_id.rstrip()
- print 'read revision %d/%d' % (i, num_revs)
-
- # python gzip needs a seekable file (!!) but the HTTP response
- # isn't, so we need to buffer it
+class RemoteBranch(Branch):
+ def __init__(self, baseurl):
+ """Create new proxy for a remote branch."""
+ self.baseurl = baseurl
+ self._check_format()
+
+
+ def controlfile(self, filename, mode):
+ if mode not in ('rb', 'rt', 'r'):
+ raise BzrError("file mode %r not supported for remote branches" % mode)
+ return get_url(self.baseurl + '/.bzr/' + filename, False)
+
+ def _need_readlock(self):
+ # remote branch always safe for read
+ pass
+
+ def _need_writelock(self):
+ raise BzrError("cannot get write lock on HTTP remote branch")
- rev_f = get_url('/.bzr/revision-store/%s' % rev_id,
- compressed=True)
-
- rev = Revision.read_xml(rev_f)
- print rev.message
- inv_id = rev.inventory_id
- if inv_id not in got_invs:
- print 'get inventory %s' % inv_id
- inv_f = get_url('/.bzr/inventory-store/%s' % inv_id,
+
+
+def simple_walk():
+ got_invs = Set()
+ got_texts = Set()
+
+ print 'read history'
+ history = get_url('/.bzr/revision-history').readlines()
+ num_revs = len(history)
+ for i, rev_id in enumerate(history):
+ rev_id = rev_id.rstrip()
+ print 'read revision %d/%d' % (i, num_revs)
+
+ # python gzip needs a seekable file (!!) but the HTTP response
+ # isn't, so we need to buffer it
+
+ rev_f = get_url('/.bzr/revision-store/%s' % rev_id,
compressed=True)
- inv = Inventory.read_xml(inv_f)
- print '%4d inventory entries' % len(inv)
-
- for path, ie in inv.iter_entries():
- text_id = ie.text_id
- if text_id == None:
- continue
- if text_id in got_texts:
- continue
- print ' fetch %s text {%s}' % (path, text_id)
- text_f = get_url('/.bzr/text-store/%s' % text_id,
- compressed=True)
- got_texts.add(text_id)
-
- got_invs.add(inv_id)
-
- print '----'
+
+ rev = Revision.read_xml(rev_f)
+ print rev.message
+ inv_id = rev.inventory_id
+ if inv_id not in got_invs:
+ print 'get inventory %s' % inv_id
+ inv_f = get_url('/.bzr/inventory-store/%s' % inv_id,
+ compressed=True)
+ inv = Inventory.read_xml(inv_f)
+ print '%4d inventory entries' % len(inv)
+
+ for path, ie in inv.iter_entries():
+ text_id = ie.text_id
+ if text_id == None:
+ continue
+ if text_id in got_texts:
+ continue
+ print ' fetch %s text {%s}' % (path, text_id)
+ text_f = get_url('/.bzr/text-store/%s' % text_id,
+ compressed=True)
+ got_texts.add(text_id)
+
+ got_invs.add(inv_id)
+
+ print '----'
+
+
+def try_me():
+ b = RemoteBranch(BASE_URL)
+ print '\n'.join(b.revision_history())
+
+
+if __name__ == '__main__':
+ try_me()
+
More information about the Pkg-bazaar-commits
mailing list