Rev 4853: Change the LockDir code to use get_bytes rather than get(). in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b4-close-file-handles

John Arbash Meinel john at arbash-meinel.com
Wed Dec 2 17:49:52 GMT 2009


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

------------------------------------------------------------
revno: 4853
revision-id: john at arbash-meinel.com-20091202174945-80ack0gu7j8j8mqm
parent: pqm at pqm.ubuntu.com-20091202092607-yc4f215s6ucjfb00
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0b4-close-file-handles
timestamp: Wed 2009-12-02 11:49:45 -0600
message:
  Change the LockDir code to use get_bytes rather than get().
  
  If we are always going to read all the bytes anyway, this is better for
  apis. Also, get_bytes() always closes the file handle in a finally block,
  rather than doing it asynchronously through the deconstructors.
-------------- next part --------------
=== modified file 'bzrlib/lockdir.py'
--- a/bzrlib/lockdir.py	2009-10-15 02:11:18 +0000
+++ b/bzrlib/lockdir.py	2009-12-02 17:49:45 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2006, 2007, 2008 Canonical Ltd
+# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -110,6 +110,7 @@
     debug,
     errors,
     lock,
+    osutils,
     )
 import bzrlib.config
 from bzrlib.decorators import only_raises
@@ -416,7 +417,7 @@
 
         peek() reads the info file of the lock holder, if any.
         """
-        return self._parse_info(self.transport.get(path))
+        return self._parse_info(self.transport.get_bytes(path))
 
     def peek(self):
         """Check if the lock is held by anyone.
@@ -449,8 +450,9 @@
                    )
         return s.to_string()
 
-    def _parse_info(self, info_file):
-        return rio.read_stanza(info_file.readlines()).as_dict()
+    def _parse_info(self, info_bytes):
+        # TODO: Handle if info_bytes is empty
+        return rio.read_stanza(osutils.split_lines(info_bytes)).as_dict()
 
     def attempt_lock(self):
         """Take the lock; fail if it's already held.



More information about the bazaar-commits mailing list