Rev 2753: review cleanups of hash pack access routines in http://sourcefrog.net/bzr/pack-hashes

Martin Pool mbp at sourcefrog.net
Wed Sep 5 07:50:53 BST 2007


At http://sourcefrog.net/bzr/pack-hashes

------------------------------------------------------------
revno: 2753
revision-id: mbp at sourcefrog.net-20070905065052-yky9zi8np96kbfcv
parent: mbp at sourcefrog.net-20070830083437-gtoy9f4awpnxiyx3
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: pack-hashes
timestamp: Wed 2007-09-05 16:50:52 +1000
message:
  review cleanups of hash pack access routines
modified:
  bzrlib/repofmt/pack_repo.py    pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
  bzrlib/tests/test_pack_repository.py test_pack_repository-20070828111851-nof5soh31tidz2dq-1
=== modified file 'bzrlib/repofmt/pack_repo.py'
--- a/bzrlib/repofmt/pack_repo.py	2007-08-30 08:34:37 +0000
+++ b/bzrlib/repofmt/pack_repo.py	2007-09-05 06:50:52 +0000
@@ -89,6 +89,7 @@
 
 
 class RepositoryPackCollection(object):
+    """Management of packs within a repository."""
 
     def __init__(self, repo, transport):
         self.repo = repo
@@ -1185,13 +1186,16 @@
     they simulate - this just provides common delegated implementations.
     """
 
-    def _add_bytes_by_hash_multi(self, new_hashes, new_texts):
+    def _add_bytes_by_hashes(self, add_pairs):
         """Add hash-indexed content to the repository.
+
+        :param add_pairs: List of (sha1, text) pairs.  The caller is 
+            responsible for making the hashes correct.
         """
         # TODO: Could we benefit from the pack writer accepting several texts
         # at a time so it can better buffer the writing?
         index_updates = []
-        for h, t in zip(new_hashes, new_texts):
+        for h, t in add_pairs:
             assert len(h) == 40, \
                     "%r doesn't look like a sha1 hash" % h
             offset, length = self._open_pack_writer.add_bytes_record(t, [])
@@ -1200,7 +1204,7 @@
             index_updates.append((key, value))
         self._hash_write_index.add_nodes(index_updates)
 
-    def _get_bytes_by_hash_multi(self, hashes):
+    def _get_bytes_by_hashes(self, hashes):
         """Look up objects by hash.
 
         :param hashes: Sequence of hashes.
@@ -1237,7 +1241,7 @@
         return r
 
     def _get_bytes_by_hash(self, h):
-        return self._get_bytes_by_hash_multi([h])[h]
+        return self._get_bytes_by_hashes([h])[h]
 
     def _make_index_map(self, suffix):
         """Return information on existing indexes.

=== modified file 'bzrlib/tests/test_pack_repository.py'
--- a/bzrlib/tests/test_pack_repository.py	2007-08-30 08:34:37 +0000
+++ b/bzrlib/tests/test_pack_repository.py	2007-09-05 06:50:52 +0000
@@ -47,7 +47,7 @@
         # store some stuff
         texts = ['hello repo!', 'binary\0\n\r\n\0']
         hashes = map(sha_string, texts)
-        repo._add_bytes_by_hash_multi(hashes, texts)
+        repo._add_bytes_by_hashes(zip(hashes, texts))
         # finish storing
         repo.commit_write_group()
         # try to get it back




More information about the bazaar-commits mailing list