Rev 4854: (jam) Switch from Transport.get() to .get_bytes(), in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Dec 2 23:10:57 GMT 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4854 [merge]
revision-id: pqm at pqm.ubuntu.com-20091202231048-9vm2dtt7rc447qnc
parent: pqm at pqm.ubuntu.com-20091202191323-mugzkr6x5sri5meb
parent: john at arbash-meinel.com-20091202220404-nngfd7uega503nwf
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2009-12-02 23:10:48 +0000
message:
(jam) Switch from Transport.get() to .get_bytes(),
close open file handles.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/config.py config.py-20051011043216-070c74f4e9e338e8
bzrlib/index.py index.py-20070712131115-lolkarso50vjr64s-1
bzrlib/lockdir.py lockdir.py-20060220222025-98258adf27fbdda3
bzrlib/repository.py rev_storage.py-20051111201905-119e9401e46257e3
bzrlib/workingtree.py workingtree.py-20050511021032-29b6ec0a681e02e3
=== modified file 'NEWS'
--- a/NEWS 2009-12-02 07:56:16 +0000
+++ b/NEWS 2009-12-02 18:10:32 +0000
@@ -77,6 +77,13 @@
Internals
*********
+* Several code paths that were calling ``Transport.get().read()`` have
+ been changed to the equalivent ``Transport.get_bytes()``. The main
+ difference is that the latter will explicitly call ``file.close()``,
+ rather than expecting the garbage collector to handle it. This helps
+ with some race conditions on Windows during the test suite and sftp
+ tests. (John Arbash Meinel)
+
Testing
*******
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2009-10-15 02:11:18 +0000
+++ b/bzrlib/branch.py 2009-12-02 17:50:30 +0000
@@ -1440,7 +1440,7 @@
"""Return the format for the branch object in a_bzrdir."""
try:
transport = a_bzrdir.get_branch_transport(None)
- format_string = transport.get("format").read()
+ format_string = transport.get_bytes("format")
return klass._formats[format_string]
except errors.NoSuchFile:
raise errors.NotBranchError(path=transport.base)
@@ -1979,7 +1979,7 @@
def get_reference(self, a_bzrdir):
"""See BranchFormat.get_reference()."""
transport = a_bzrdir.get_branch_transport(None)
- return transport.get('location').read()
+ return transport.get_bytes('location')
def set_reference(self, a_bzrdir, to_branch):
"""See BranchFormat.set_reference()."""
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py 2009-11-12 00:20:48 +0000
+++ b/bzrlib/bzrdir.py 2009-12-02 17:56:06 +0000
@@ -1827,7 +1827,7 @@
def probe_transport(klass, transport):
"""Return the .bzrdir style format present in a directory."""
try:
- format_string = transport.get(".bzr/branch-format").read()
+ format_string = transport.get_bytes(".bzr/branch-format")
except errors.NoSuchFile:
raise errors.NotBranchError(path=transport.base)
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2009-10-31 01:43:48 +0000
+++ b/bzrlib/config.py 2009-12-02 22:04:04 +0000
@@ -1472,7 +1472,7 @@
def _get_config_file(self):
try:
- return self._transport.get(self._filename)
+ return StringIO(self._transport.get_bytes(self._filename))
except errors.NoSuchFile:
return StringIO()
=== modified file 'bzrlib/index.py'
--- a/bzrlib/index.py 2009-12-01 16:03:14 +0000
+++ b/bzrlib/index.py 2009-12-02 17:59:15 +0000
@@ -455,6 +455,7 @@
trailers = 0
pos = stream.tell()
lines = stream.read().split('\n')
+ stream.close()
del lines[-1]
_, _, _, trailers = self._parse_lines(lines, pos)
for key, absent, references, value in self._keys_by_offset.itervalues():
=== 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.
=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py 2009-11-30 03:34:09 +0000
+++ b/bzrlib/repository.py 2009-12-02 18:05:08 +0000
@@ -3094,7 +3094,7 @@
"""
try:
transport = a_bzrdir.get_repository_transport(None)
- format_string = transport.get("format").read()
+ format_string = transport.get_bytes("format")
return format_registry.get(format_string)
except errors.NoSuchFile:
raise errors.NoRepositoryPresent(a_bzrdir)
=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py 2009-11-26 01:42:06 +0000
+++ b/bzrlib/workingtree.py 2009-12-02 18:15:55 +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