Rev 5080: Rework the bootstrapping a bit. Move more stuff into local vars rather than class. in http://bzr.arbash-meinel.com/branches/bzr/lp/2.2.0b2-contained-pack

John Arbash Meinel john at arbash-meinel.com
Thu Mar 4 22:52:52 GMT 2010


At http://bzr.arbash-meinel.com/branches/bzr/lp/2.2.0b2-contained-pack

------------------------------------------------------------
revno: 5080
revision-id: john at arbash-meinel.com-20100304225223-hkgegogaj2vusvol
parent: john at arbash-meinel.com-20100304224322-1y9ot2twh0tv9g0g
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.2.0b2-contained-pack
timestamp: Thu 2010-03-04 16:52:23 -0600
message:
  Rework the bootstrapping a bit. Move more stuff into local vars rather than class.
  
  I would like to have a small amount of state, and the bootstrapping can just be one
  way that the state gets populated. That way it should be easier for 'PackCollection'
  to hold that state in the equivalent 'pack-names' file, and poke that into the
  root index for each sub-file instead.
-------------- next part --------------
=== modified file 'bzrlib/sack.py'
--- a/bzrlib/sack.py	2010-03-04 22:43:22 +0000
+++ b/bzrlib/sack.py	2010-03-04 22:52:23 +0000
@@ -93,30 +93,25 @@
     def __init__(self, version, start_offset):
         self.start_offset = start_offset
         self.version = version
-        self._end_of_file = None
-        self._base_transport = None
-        self._base_filename = None
-        # This is a BTreeGraphIndex mapping names => their offsets in the sack.
-        self._named_sections = None
         # This is a transport.file_view.FileView which allows us to maps names
         # into offsets in the backing transport
+        self._section_file_map = {}
         self._file_view = None
-        self._section_file_map = {}
 
-    def _ensure_named_sections(self):
+    def _read_named_sections(self, base_transport, filename, end_of_file):
         expected_header = '%s%d\n' % (_HEADER_BASE, self.version)
-        _, start = self._base_transport.readv(self._base_filename,
+        _, start = base_transport.readv(filename,
             [(self.start_offset, len(expected_header))]).next()
         assert start == expected_header
         root_start = self.start_offset + len(expected_header)
-        root_end = self._end_of_file - 12
-        self._section_file_map = {'root-index': (root_start, root_end)}
-        self._file_view = file_view.FileView(self._base_transport,
-            self._base_filename, self._section_file_map)
-        self._named_sections = btree_index.BTreeGraphIndex(
+        root_end = end_of_file - 12
+        self._section_file_map['root-index'] = (root_start, root_end)
+        self._file_view = file_view.FileView(base_transport, filename,
+            self._section_file_map)
+        named_sections = btree_index.BTreeGraphIndex(
             self._file_view, 'root-index', root_end - root_start)
         # Ensure that we have entries
-        for _, key, value in self._named_sections.iter_all_entries():
+        for _, key, value in named_sections.iter_all_entries():
             start, length = map(int, value.split())
             assert len(key) == 1
             name, = key
@@ -136,10 +131,7 @@
         file_st = transport.stat(filename)
         _,tail = transport.readv(filename, [(file_st.st_size-12, 12)]).next()
         ti = TrailingIndex.parse_tail_bytes(tail)
-        ti._base_transport = transport
-        ti._base_filename = filename
-        ti._end_of_file = file_st.st_size
-        ti._ensure_named_sections()
+        ti._read_named_sections(transport, filename, file_st.st_size)
         return ti
 
 



More information about the bazaar-commits mailing list