Rev 4859: Lots of tweaks in WorkingTree. in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b4-close-file-handles

John Arbash Meinel john at arbash-meinel.com
Wed Dec 2 18:06:10 GMT 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b4-close-file-handles

------------------------------------------------------------
revno: 4859
revision-id: john at arbash-meinel.com-20091202180602-70ja2y4kwb9y3tw7
parent: john at arbash-meinel.com-20091202180508-5ivma09qogs2wg1c
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0b4-close-file-handles
timestamp: Wed 2009-12-02 12:06:02 -0600
message:
  Lots of tweaks in WorkingTree.
  
  When we can, use get_bytes() rather than get(). However for the cases
  where we still use .get() make sure to try/finally:f.close() the
  file handle.
-------------- next part --------------
=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py	2009-11-26 01:42:06 +0000
+++ b/bzrlib/workingtree.py	2009-12-02 18:06:02 +0000
@@ -543,11 +543,11 @@
         else:
             parents = [last_rev]
         try:
-            merges_file = self._transport.get('pending-merges')
+            merges_bytes = self._transport.get_bytes('pending-merges')
         except errors.NoSuchFile:
             pass
         else:
-            for l in merges_file.readlines():
+            for l in osutils.split_lines(merges_bytes)):
                 revision_id = l.rstrip('\n')
                 parents.append(revision_id)
         return parents
@@ -1844,7 +1844,11 @@
     def _reset_data(self):
         """Reset transient data that cannot be revalidated."""
         self._inventory_is_modified = False
-        result = self._deserialize(self._transport.get('inventory'))
+        f = self._transport.get('inventory')
+        try:
+            result = self._deserialize(f)
+        finally:
+            f.close()
         self._set_inventory(result, dirty=False)
 
     @needs_tree_write_lock
@@ -1926,7 +1930,11 @@
         # binary.
         if self._inventory_is_modified:
             raise errors.InventoryModified(self)
-        result = self._deserialize(self._transport.get('inventory'))
+        f = self._transport.get('inventory')
+        try:
+            result = self._deserialize(f)
+        finally:
+            f.close()
         self._set_inventory(result, dirty=False)
         return result
 
@@ -2770,7 +2778,7 @@
         """Return the format for the working tree object in a_bzrdir."""
         try:
             transport = a_bzrdir.get_workingtree_transport(None)
-            format_string = transport.get("format").read()
+            format_string = transport.get_bytes("format")
             return klass._formats[format_string]
         except errors.NoSuchFile:
             raise errors.NoWorkingTree(base=transport.base)



More information about the bazaar-commits mailing list