Rev 3033: (robertc) Fix upgrade tests and the get_data_stream method of Knits in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Nov 27 02:00:41 GMT 2007


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3033
revision-id:pqm at pqm.ubuntu.com-20071127020038-4i8r0718qpokyky9
parent: pqm at pqm.ubuntu.com-20071127010418-gbuxg943nyu8vefz
parent: robertc at robertcollins.net-20071127012001-sb2v181c9f6vmku4
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2007-11-27 02:00:38 +0000
message:
  (robertc) Fix upgrade tests and the get_data_stream method of Knits
  	to work with the pack repository type. (Robert Collins)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
  bzrlib/tests/repository_implementations/test_repository.py test_repository.py-20060131092128-ad07f494f5c9d26c
  bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
  bzrlib/tests/test_repository.py test_repository.py-20060131075918-65c555b881612f4d
  bzrlib/tests/test_upgrade.py   test_upgrade.py-20051004040251-555fe1d2bae1bc71
    ------------------------------------------------------------
    revno: 3015.2.20
    revision-id:robertc at robertcollins.net-20071127012001-sb2v181c9f6vmku4
    parent: robertc at robertcollins.net-20071126223325-wua9x81prpxueom3
    parent: pqm at pqm.ubuntu.com-20071127010418-gbuxg943nyu8vefz
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: integration
    timestamp: Tue 2007-11-27 12:20:01 +1100
    message:
      Merge bzr.dev.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/tests/test_bzrdir.py    test_bzrdir.py-20060131065654-deba40eef51cf220
      bzrlib/tests/test_revert.py    test_revert.py-20060828180832-fqb1v6ecpyvnlitj-1
      bzrlib/tests/test_transform.py test_transaction.py-20060105172520-b3ffb3946550e6c4
      bzrlib/transform.py            transform.py-20060105172343-dd99e54394d91687
      bzrlib/win32utils.py           win32console.py-20051021033308-123c6c929d04973d
      doc/en/user-reference/hooks.txt hooks.txt-20070830033044-xxu2rced13f72dka-1
    ------------------------------------------------------------
    revno: 3015.2.19
    revision-id:robertc at robertcollins.net-20071126223325-wua9x81prpxueom3
    parent: robertc at robertcollins.net-20071126211526-zp59n29oqm2m8s99
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: pack.read-locks
    timestamp: Tue 2007-11-27 09:33:25 +1100
    message:
      Don't include the pack container length in the lengths given by get_data_stream.
    modified:
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
      bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
    ------------------------------------------------------------
    revno: 3015.2.18
    revision-id:robertc at robertcollins.net-20071126211526-zp59n29oqm2m8s99
    parent: robertc at robertcollins.net-20071126210129-rnbasaov7i0iia8g
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: pack.read-locks
    timestamp: Tue 2007-11-27 08:15:26 +1100
    message:
      Lock correctness for test_upgrade.py.
    modified:
      bzrlib/tests/test_upgrade.py   test_upgrade.py-20051004040251-555fe1d2bae1bc71
    ------------------------------------------------------------
    revno: 3015.2.17
    revision-id:robertc at robertcollins.net-20071126210129-rnbasaov7i0iia8g
    parent: robertc at robertcollins.net-20071126204930-3ykndfwze7ju7l9e
    parent: mbp at sourcefrog.net-20071126080428-ccgoqxa6hr4xawf0
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: pack.read-locks
    timestamp: Tue 2007-11-27 08:01:29 +1100
    message:
      Merge the data-stream ordering fix.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
      bzrlib/tests/repository_implementations/test_repository.py test_repository.py-20060131092128-ad07f494f5c9d26c
      bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
      bzrlib/tests/test_repository.py test_repository.py-20060131075918-65c555b881612f4d
        ------------------------------------------------------------
        revno: 3023.2.4
        revision-id:mbp at sourcefrog.net-20071126080428-ccgoqxa6hr4xawf0
        parent: mbp at sourcefrog.net-20071126072017-h939i3145omvpore
        committer: Martin Pool <mbp at sourcefrog.net>
        branch nick: 164637-delta-order
        timestamp: Mon 2007-11-26 19:04:28 +1100
        message:
          update NEWS
        modified:
          NEWS                           NEWS-20050323055033-4e00b5db738777ff
        ------------------------------------------------------------
        revno: 3023.2.3
        revision-id:mbp at sourcefrog.net-20071126072017-h939i3145omvpore
        parent: mbp at sourcefrog.net-20071126064616-ds3a78w2s1erqjhl
        committer: Martin Pool <mbp at sourcefrog.net>
        branch nick: 164637-delta-order
        timestamp: Mon 2007-11-26 18:20:17 +1100
        message:
          Update tests for new ordering of results from get_data_stream - the order is not defined by the interface, but is stable
        modified:
          bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
          bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
          bzrlib/tests/test_repository.py test_repository.py-20060131075918-65c555b881612f4d
        ------------------------------------------------------------
        revno: 3023.2.2
        revision-id:mbp at sourcefrog.net-20071126064616-ds3a78w2s1erqjhl
        parent: mbp at sourcefrog.net-20071126023458-h63ii4ddopag1vq3
        committer: Martin Pool <mbp at sourcefrog.net>
        branch nick: 164637-delta-order
        timestamp: Mon 2007-11-26 17:46:16 +1100
        message:
          Fix KnitVersionedFile.get_data_stream to not assume .versions() is sorted. (lp:165106)
        modified:
          bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
          bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
        ------------------------------------------------------------
        revno: 3023.2.1
        revision-id:mbp at sourcefrog.net-20071126023458-h63ii4ddopag1vq3
        parent: pqm at pqm.ubuntu.com-20071125173141-g89p6qnnh90tk5zi
        committer: Martin Pool <mbp at sourcefrog.net>
        branch nick: 164637-delta-order
        timestamp: Mon 2007-11-26 13:34:58 +1100
        message:
          test_get_data_stream should indicate NotApplicable rather than silently passing
        modified:
          bzrlib/tests/repository_implementations/test_repository.py test_repository.py-20060131092128-ad07f494f5c9d26c
    ------------------------------------------------------------
    revno: 3015.2.16
    revision-id:robertc at robertcollins.net-20071126204930-3ykndfwze7ju7l9e
    parent: robertc at robertcollins.net-20071126203008-hst9k6pxrbzoci6w
    parent: pqm at pqm.ubuntu.com-20071126201850-7bugi709x0jjfqpg
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: pack.read-locks
    timestamp: Tue 2007-11-27 07:49:30 +1100
    message:
      Merge bzr.dev.
    added:
      bzrlib/switch.py               switch.py-20071116011000-v5lnw7d2wkng9eux-1
      bzrlib/tests/blackbox/test_switch.py test_switch.py-20071122111948-0c5en6uz92bwl76h-1
      bzrlib/tests/test_switch.py    test_switch.py-20071116011000-v5lnw7d2wkng9eux-2
    renamed:
      doc/developers/knitpack.txt => doc/developers/packrepo.txt knitpack.txt-20071023074744-q0g5u8me8gk5zbtb-1
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
      bzrlib/conflicts.py            conflicts.py-20051001061850-78ef952ba63d2b42
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
      bzrlib/lru_cache.py            lru_cache.py-20070119165515-tlw203kuwh0id5gv-1
      bzrlib/repofmt/pack_repo.py    pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
      bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
      bzrlib/revision.py             revision.py-20050309040759-e77802c08f3999d5
      bzrlib/smart/medium.py         medium.py-20061103051856-rgu2huy59fkz902q-1
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/blackbox/__init__.py __init__.py-20051128053524-eba30d8255e08dc3
      bzrlib/tests/blackbox/test_info.py test_info.py-20060215045507-bbdd2d34efab9e0a
      bzrlib/tests/blackbox/test_merge.py test_merge.py-20060323225809-9bc0459c19917f41
      bzrlib/tests/ftp_server.py     ftpserver.py-20071019102346-61jbvdkrr70igauv-1
      bzrlib/tests/interrepository_implementations/__init__.py __init__.py-20060220054744-baf49a1f88f17b1a
      bzrlib/tests/interrepository_implementations/test_interrepository.py test_interrepository.py-20060220061411-1ec13fa99e5e3eee
      bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
      bzrlib/tests/test_conflicts.py test_conflicts.py-20051006031059-e2dad9bbeaa5891f
      bzrlib/tests/test_errors.py    test_errors.py-20060210110251-41aba2deddf936a8
      bzrlib/tests/test_info.py      test_info.py-20070320150933-m0xxm1g7xi9v6noe-1
      bzrlib/tests/test_lru_cache.py test_lru_cache.py-20070119165535-hph6rk4h9rzy4180-1
      bzrlib/tests/test_repository.py test_repository.py-20060131075918-65c555b881612f4d
      bzrlib/tests/test_transform.py test_transaction.py-20060105172520-b3ffb3946550e6c4
      bzrlib/tests/test_transport.py testtransport.py-20050718175618-e5cdb99f4555ddce
      bzrlib/tests/test_transport_implementations.py test_transport_implementations.py-20051227111451-f97c5c7d5c49fce7
      bzrlib/tests/test_workingtree.py testworkingtree.py-20051004024258-b88d0fe8f101d468
      bzrlib/transform.py            transform.py-20060105172343-dd99e54394d91687
      bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
      bzrlib/transport/ftp.py        ftp.py-20051116161804-58dc9506548c2a53
      bzrlib/transport/memory.py     memory.py-20051016101338-cd008dbdf69f04fc
      bzrlib/transport/remote.py     ssh.py-20060608202016-c25gvf1ob7ypbus6-1
      bzrlib/util/configobj/configobj.py configobj.py-20051018184548-06992a2246425e3e
      bzrlib/util/configobj/docs/BSD-LICENSE.txt BSDLICENSE.txt-20051018184548-29b89ff3102657f5
      bzrlib/util/configobj/docs/configobj.txt configobj.txt-20051018184548-4949b5f17e6a19c7
      bzrlib/util/configobj/docs/validate.txt validate.txt-20051018184548-9e0e5ad913e258f5
      bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
      doc/developers/packrepo.txt    knitpack.txt-20071023074744-q0g5u8me8gk5zbtb-1
=== modified file 'NEWS'
--- a/NEWS	2007-11-27 00:04:16 +0000
+++ b/NEWS	2007-11-27 01:20:01 +0000
@@ -60,6 +60,13 @@
 
   BUG FIXES:
 
+   * Fix possible error in insert_data_stream when copying between 
+     pack repositories over bzr+ssh or bzr+http.  
+     KnitVersionedFile.get_data_stream now makes sure that requested
+     compression parents are sent before any delta hunks that depend 
+     on them.
+     (Martin Pool, #164637)
+
    * A progress bar has been added for knitpack -> knitpack fetching.
      (Robert Collins, #157789)
 

=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2007-11-26 19:35:11 +0000
+++ b/bzrlib/knit.py	2007-11-26 22:33:25 +0000
@@ -576,7 +576,11 @@
         """Get a data stream for the specified versions.
 
         Versions may be returned in any order, not necessarily the order
-        specified.
+        specified.  They are returned in a partial order by compression
+        parent, so that the deltas can be applied as the data stream is
+        inserted; however note that compression parents will not be sent
+        unless they were specifically requested, as the client may already
+        have them.
 
         :param required_versions: The exact set of versions to be extracted.
             Unlike some other knit methods, this is not used to generate a
@@ -585,46 +589,63 @@
         :returns: format_signature, list of (version, options, length, parents),
             reader_callable.
         """
-        if not isinstance(required_versions, set):
-            required_versions = set(required_versions)
-        # we don't care about inclusions, the caller cares.
-        # but we need to setup a list of records to visit.
+        required_version_set = frozenset(required_versions)
+        version_index = {}
+        # list of revisions that can just be sent without waiting for their
+        # compression parent
+        ready_to_send = []
+        # map from revision to the children based on it
+        deferred = {}
+        # first, read all relevant index data, enough to sort into the right
+        # order to return
         for version_id in required_versions:
             if not self.has_version(version_id):
                 raise RevisionNotPresent(version_id, self.filename)
-        # Pick the desired versions out of the index in oldest-to-newest order
-        version_list = []
-        for version_id in self.versions():
-            if version_id in required_versions:
-                version_list.append(version_id)
-
-        # create the list of version information for the result
-        copy_queue_records = []
-        copy_set = set()
-        result_version_list = []
-        for version_id in version_list:
             options = self._index.get_options(version_id)
             parents = self._index.get_parents_with_ghosts(version_id)
             index_memo = self._index.get_position(version_id)
+            version_index[version_id] = (index_memo, options, parents)
+            if parents and parents[0] in required_version_set:
+                # must wait until the parent has been sent
+                deferred.setdefault(parents[0], []). \
+                    append(version_id)
+            else:
+                # either a fulltext, or a delta whose parent the client did
+                # not ask for and presumably already has
+                ready_to_send.append(version_id)
+        # build a list of results to return, plus instructions for data to
+        # read from the file
+        copy_queue_records = []
+        temp_version_list = []
+        while ready_to_send:
+            # XXX: pushing and popping lists may be a bit inefficient
+            version_id = ready_to_send.pop(0)
+            (index_memo, options, parents) = version_index[version_id]
             copy_queue_records.append((version_id, index_memo))
             none, data_pos, data_size = index_memo
-            copy_set.add(version_id)
-            # version, options, length, parents
-            result_version_list.append((version_id, options, data_size,
+            temp_version_list.append((version_id, options, data_size,
                 parents))
-
-        # Read the compressed record data.
-        # XXX:
-        # From here down to the return should really be logic in the returned
-        # callable -- in a class that adapts read_records_iter_raw to read
-        # requests.
+            if version_id in deferred:
+                # now we can send all the children of this revision - we could
+                # put them in anywhere, but we hope that sending them soon
+                # after the fulltext will give good locality in the receiver
+                ready_to_send[:0] = deferred.pop(version_id)
+        assert len(deferred) == 0, \
+            "Still have compressed child versions waiting to be sent"
+        # XXX: The stream format is such that we cannot stream it - we have to
+        # know the length of all the data a-priori.
         raw_datum = []
+        result_version_list = []
         for (version_id, raw_data), \
             (version_id2, options, _, parents) in \
             izip(self._data.read_records_iter_raw(copy_queue_records),
-                 result_version_list):
-            assert version_id == version_id2, 'logic error, inconsistent results'
+                 temp_version_list):
+            assert version_id == version_id2, \
+                'logic error, inconsistent results'
             raw_datum.append(raw_data)
+            result_version_list.append(
+                (version_id, options, len(raw_data), parents))
+        # provide a callback to get data incrementally.
         pseudo_file = StringIO(''.join(raw_datum))
         def read(length):
             if length is None:

=== modified file 'bzrlib/tests/repository_implementations/test_repository.py'
--- a/bzrlib/tests/repository_implementations/test_repository.py	2007-11-26 03:47:18 +0000
+++ b/bzrlib/tests/repository_implementations/test_repository.py	2007-11-26 21:01:29 +0000
@@ -29,7 +29,11 @@
 from bzrlib.delta import TreeDelta
 from bzrlib.inventory import Inventory, InventoryDirectory
 from bzrlib.revision import NULL_REVISION, Revision
-from bzrlib.tests import TestCaseWithTransport, TestSkipped
+from bzrlib.tests import (
+    TestCaseWithTransport,
+    TestNotApplicable,
+    TestSkipped,
+    )
 from bzrlib.tests.repository_implementations import TestCaseWithRepository
 from bzrlib.transport import get_transport
 from bzrlib.upgrade import upgrade
@@ -377,8 +381,8 @@
         try:
             stream = repo.get_data_stream(['rev_id'])
         except NotImplementedError:
-            # Not all repositories support streaming.
-            return
+            raise TestNotApplicable("%s doesn't support get_data_stream"
+                % repo._format)
 
         # The data stream is a iterator that yields (name, versioned_file)
         # pairs for:

=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py	2007-11-09 17:50:31 +0000
+++ b/bzrlib/tests/test_knit.py	2007-11-26 22:33:25 +0000
@@ -1605,6 +1605,44 @@
         self.assertEqual(expected_data_list, data_list)
         self.assertRecordContentEqual(k1, 'text-m', reader_callable(None))
         
+    def test_get_data_stream_unordered_index(self):
+        """Get a data stream when the knit index reports versions out of order.
+
+        https://bugs.launchpad.net/bzr/+bug/164637
+        """
+        k1 = self.make_test_knit()
+        test_data = [
+            ('text-a', [], TEXT_1),
+            ('text-b', ['text-a'], TEXT_1),
+            ('text-c', [], TEXT_1),
+            ('text-d', ['text-c'], TEXT_1),
+            ('text-m', ['text-b', 'text-d'], TEXT_1),
+            ]
+        for version_id, parents, lines in test_data:
+            k1.add_lines(version_id, parents, split_lines(lines))
+        # monkey-patch versions method to return out of order, as if coming
+        # from multiple independently indexed packs
+        original_versions = k1.versions
+        k1.versions = lambda: reversed(original_versions())
+        expected_data_list = [
+            ('text-a', ['fulltext'], 122, []),
+            ('text-b', ['line-delta'], 84, ['text-a'])]
+        # now check the fulltext is first and the delta second
+        format, data_list, _ = k1.get_data_stream(['text-a', 'text-b'])
+        self.assertEqual('knit-plain', format)
+        self.assertEqual(expected_data_list, data_list)
+        # and that's true if we ask for them in the opposite order too
+        format, data_list, _ = k1.get_data_stream(['text-b', 'text-a'])
+        self.assertEqual(expected_data_list, data_list)
+        # also try requesting more versions
+        format, data_list, _ = k1.get_data_stream([
+            'text-m', 'text-b', 'text-a'])
+        self.assertEqual([
+            ('text-a', ['fulltext'], 122, []),
+            ('text-b', ['line-delta'], 84, ['text-a']),
+            ('text-m', ['line-delta'], 84, ['text-b', 'text-d']),
+            ], data_list)
+
     def test_get_stream_ghost_parent(self):
         """Get a data stream for a version with a ghost parent."""
         k1 = self.make_test_knit()
@@ -1635,14 +1673,17 @@
             ('text-d', ['text-c'], TEXT_1),
             ('text-m', ['text-b', 'text-d'], TEXT_1),
             ]
+        for version_id, parents, lines in test_data:
+            k1.add_lines(version_id, parents, split_lines(lines))
+
+        # This test is actually a bit strict as the order in which they're
+        # returned is not defined.  This matches the current (deterministic)
+        # behaviour.
         expected_data_list = [
             # version, options, length, parents
+            ('text-d', ['line-delta'], 84, ['text-c']),
             ('text-b', ['line-delta'], 84, ['text-a']),
-            ('text-d', ['line-delta'], 84, ['text-c']),
             ]
-        for version_id, parents, lines in test_data:
-            k1.add_lines(version_id, parents, split_lines(lines))
-
         # Note that even though we request the revision IDs in a particular
         # order, the data stream may return them in any order it likes.  In this
         # case, they'll be in the order they were inserted into the knit.
@@ -1650,8 +1691,9 @@
             ['text-d', 'text-b'])
         self.assertEqual('knit-plain', format)
         self.assertEqual(expected_data_list, data_list)
+        # must match order they're returned
+        self.assertRecordContentEqual(k1, 'text-d', reader_callable(84))
         self.assertRecordContentEqual(k1, 'text-b', reader_callable(84))
-        self.assertRecordContentEqual(k1, 'text-d', reader_callable(84))
         self.assertEqual('', reader_callable(None),
                          "There should be no more bytes left to read.")
 
@@ -1673,17 +1715,20 @@
             ('text-d', ['text-c'], TEXT_1),
             ('text-m', ['text-b', 'text-d'], TEXT_1),
            ]
+        for version_id, parents, lines in test_data:
+            k1.add_lines(version_id, parents, split_lines(lines))
+
+        # This test is actually a bit strict as the order in which they're
+        # returned is not defined.  This matches the current (deterministic)
+        # behaviour.
         expected_data_list = [
             # version, options, length, parents
             ('text-a', ['fulltext'], 122, []),
             ('text-b', ['line-delta'], 84, ['text-a']),
+            ('text-m', ['line-delta'], 84, ['text-b', 'text-d']),
             ('text-c', ['fulltext'], 121, []),
             ('text-d', ['line-delta'], 84, ['text-c']),
-            ('text-m', ['line-delta'], 84, ['text-b', 'text-d']),
             ]
-        for version_id, parents, lines in test_data:
-            k1.add_lines(version_id, parents, split_lines(lines))
-
         format, data_list, reader_callable = k1.get_data_stream(
             ['text-a', 'text-b', 'text-c', 'text-d', 'text-m'])
         self.assertEqual('knit-plain', format)
@@ -2640,3 +2685,37 @@
             set(index.iter_parents(['tip'])))
         self.assertEqual(set(),
             set(index.iter_parents([])))
+
+
+class TestPackKnits(KnitTests):
+    """Tests that use a _PackAccess and KnitGraphIndex."""
+
+    def test_get_data_stream_packs_ignores_pack_overhead(self):
+        # Packs have an encoding overhead that should not be included in the
+        # 'size' field of a data stream, because it is not returned by the
+        # raw_reading functions - it is why index_memo's are opaque, and
+        # get_data_stream was abusing this.
+        packname = 'test.pack'
+        transport = self.get_transport()
+        def write_data(bytes):
+            transport.append_bytes(packname, bytes)
+        writer = pack.ContainerWriter(write_data)
+        writer.begin()
+        index = InMemoryGraphIndex(2)
+        knit_index = KnitGraphIndex(index, add_callback=index.add_nodes,
+            deltas=True)
+        indices = {index:(transport, packname)}
+        access = _PackAccess(indices, writer=(writer, index))
+        k = KnitVersionedFile('test', get_transport('.'),
+            delta=True, create=True, index=knit_index, access_method=access)
+        # insert something into the knit
+        k.add_lines('text-1', [], ["foo\n"])
+        # get a data stream for it
+        stream = k.get_data_stream(['text-1'])
+        # if the stream has been incorrectly assembled, we will get a short read
+        # reading from the stream (as streams have no trailer)
+        expected_length = stream[1][0][2]
+        # we use -1 to do the read, so that if a trailer is added this test
+        # will fail and we'll adjust it to handle that case correctly, rather
+        # than allowing an over-read that is bogus.
+        self.assertEqual(expected_length, len(stream[2](-1)))

=== modified file 'bzrlib/tests/test_repository.py'
--- a/bzrlib/tests/test_repository.py	2007-11-26 02:05:38 +0000
+++ b/bzrlib/tests/test_repository.py	2007-11-26 21:01:29 +0000
@@ -432,19 +432,22 @@
             ('text-d', ['text-c'], test_knit.TEXT_1),
             ('text-m', ['text-b', 'text-d'], test_knit.TEXT_1),
            ]
+        # This test is actually a bit strict as the order in which they're
+        # returned is not defined.  This matches the current (deterministic)
+        # behaviour.
         expected_data_list = [
             # version, options, parents
             ('text-a', ['fulltext'], []),
             ('text-b', ['line-delta'], ['text-a']),
+            ('text-m', ['line-delta'], ['text-b', 'text-d']),
             ('text-c', ['fulltext'], []),
             ('text-d', ['line-delta'], ['text-c']),
-            ('text-m', ['line-delta'], ['text-b', 'text-d']),
             ]
         for version_id, parents, lines in test_data:
             k1.add_lines(version_id, parents, test_knit.split_lines(lines))
 
         bytes = knitrepo._get_stream_as_bytes(
-            k1, ['text-a', 'text-b', 'text-c', 'text-d', 'text-m'])
+            k1, ['text-a', 'text-b', 'text-m', 'text-c', 'text-d', ])
 
         data = bencode.bdecode(bytes)
         format = data.pop(0)

=== modified file 'bzrlib/tests/test_upgrade.py'
--- a/bzrlib/tests/test_upgrade.py	2007-08-06 22:26:54 +0000
+++ b/bzrlib/tests/test_upgrade.py	2007-11-26 21:15:26 +0000
@@ -67,9 +67,17 @@
             'mbp at sourcefrog.net-20051004035756-235f2b7dcdddd8dd'])
         rt = b.repository.revision_tree(rh[0])
         foo_id = 'foo-20051004035605-91e788d1875603ae'
-        eq(rt.get_file_text(foo_id), 'initial contents\n')
+        rt.lock_read()
+        try:
+            eq(rt.get_file_text(foo_id), 'initial contents\n')
+        finally:
+            rt.unlock()
         rt = b.repository.revision_tree(rh[1])
-        eq(rt.get_file_text(foo_id), 'new contents\n')
+        rt.lock_read()
+        try:
+            eq(rt.get_file_text(foo_id), 'new contents\n')
+        finally:
+            rt.unlock()
         # check a backup was made:
         transport = get_transport(b.base)
         transport.stat('.bzr.backup')
@@ -125,11 +133,13 @@
         self.assertNotEqual(old_repo_format.__class__, repo._format.__class__)
         # and we should be able to read the names for the file id 
         # 'dir-20051005095101-da1441ea3fa6917a'
+        repo.lock_read()
+        self.addCleanup(repo.unlock)
         self.assertNotEqual(
             [],
             repo.weave_store.get_weave(
                 'dir-20051005095101-da1441ea3fa6917a',
-                repo.get_transaction()))
+                repo.get_transaction()).versions())
 
     def test_upgrade_to_meta_sets_workingtree_last_revision(self):
         self.build_tree_contents(_upgrade_dir_template)




More information about the bazaar-commits mailing list