Rev 6508: Fix bug #1046284. We had an ordering issue with get_file_text consuming iter_files_bytes. in http://bazaar.launchpad.net/~jameinel/bzr/2.5.2-get_file_text-1046284

John Arbash Meinel john at arbash-meinel.com
Wed Sep 5 13:06:48 UTC 2012


At http://bazaar.launchpad.net/~jameinel/bzr/2.5.2-get_file_text-1046284

------------------------------------------------------------
revno: 6508
revision-id: john at arbash-meinel.com-20120905130628-zmofd6f0l3i2ngnx
parent: pqm at pqm.ubuntu.com-20120831171407-k9tg1ahp8xrg52oo
fixes bug: https://launchpad.net/bugs/1046284
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.5.2-get_file_text-1046284
timestamp: Wed 2012-09-05 17:06:28 +0400
message:
  Fix bug #1046284. We had an ordering issue with get_file_text consuming iter_files_bytes.
  
  Specifically, you are supposed to consume the content iterator before you step the
  outer iterator. We only notice with remote repository because the other apis
  don't explicitly depend on that behavior.
-------------- next part --------------
=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py	2012-01-06 14:09:04 +0000
+++ b/bzrlib/workingtree_4.py	2012-09-05 13:06:28 +0000
@@ -1882,8 +1882,19 @@
         return self.inventory[file_id].text_size
 
     def get_file_text(self, file_id, path=None):
-        _, content = list(self.iter_files_bytes([(file_id, None)]))[0]
-        return ''.join(content)
+        full_content = None
+        for _, content in self.iter_files_bytes([(file_id, None)]):
+            if full_content is not None:
+                raise AssertionError('iter_files_bytes returned'
+                    ' too many entries')
+            # For each entry returned by iter_files_bytes, we must consume the
+            # content before we step the iterator.
+            full_content = ''.join(content)
+            del content
+        if full_content is None:
+            raise AssertionError('iter_files_bytes did not return'
+                ' the requested data')
+        return full_content
 
     def get_reference_revision(self, file_id, path=None):
         return self.inventory[file_id].reference_revision



More information about the bazaar-commits mailing list