Rev 4853: (Martin <gz>) Use get_bytes() to ensure that read bundles get closed in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Dec 2 19:13:26 GMT 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4853 [merge]
revision-id: pqm at pqm.ubuntu.com-20091202191323-mugzkr6x5sri5meb
parent: pqm at pqm.ubuntu.com-20091202092607-yc4f215s6ucjfb00
parent: gzlist at googlemail.com-20091128004803-nirz54wazyj0waf8
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2009-12-02 19:13:23 +0000
message:
(Martin <gz>) Use get_bytes() to ensure that read bundles get closed
properly.
modified:
bzrlib/bundle/__init__.py changeset.py-20050513021216-b02ab57fb9738913
bzrlib/merge_directive.py merge_directive.py-20070228184838-ja62280spt1g7f4x-1
bzrlib/tests/blackbox/test_merge.py test_merge.py-20060323225809-9bc0459c19917f41
bzrlib/tests/blackbox/test_send.py test_bundle.py-20060616222707-c21c8b7ea5ef57b1
=== modified file 'bzrlib/bundle/__init__.py'
--- a/bzrlib/bundle/__init__.py 2009-07-20 02:04:21 +0000
+++ b/bzrlib/bundle/__init__.py 2009-11-28 00:48:03 +0000
@@ -14,6 +14,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+from cStringIO import StringIO
+
from bzrlib.symbol_versioning import deprecated_function, deprecated_in
from bzrlib.lazy_import import lazy_import
lazy_import(globals(), """
@@ -22,6 +24,7 @@
urlutils,
)
from bzrlib.bundle import serializer as _serializer
+from bzrlib.merge_directive import MergeDirective
from bzrlib.transport import (
do_catching_redirections,
get_transport,
@@ -51,33 +54,22 @@
def read_mergeable_from_transport(transport, filename, _do_directive=True):
- # All of this must be in the try/except
- # Some transports cannot detect that we are trying to read a
- # directory until we actually issue read() on the handle.
+ def get_bundle(transport):
+ return StringIO(transport.get_bytes(filename)), transport
+
+ def redirected_transport(transport, exception, redirection_notice):
+ note(redirection_notice)
+ url, filename = urlutils.split(exception.target,
+ exclude_trailing_slash=False)
+ if not filename:
+ raise errors.NotABundle('A directory cannot be a bundle')
+ return get_transport(url)
+
try:
- def get_bundle(transport):
- return transport.get(filename), transport
-
- def redirected_transport(transport, exception, redirection_notice):
- note(redirection_notice)
- url, filename = urlutils.split(exception.target,
- exclude_trailing_slash=False)
- if not filename:
- raise errors.NotABundle('A directory cannot be a bundle')
- return get_transport(url)
-
- try:
- f, transport = do_catching_redirections(get_bundle, transport,
+ bytef, transport = do_catching_redirections(get_bundle, transport,
redirected_transport)
- except errors.TooManyRedirections:
- raise errors.NotABundle(transport.clone(filename).base)
-
- if _do_directive:
- from bzrlib.merge_directive import MergeDirective
- directive = MergeDirective.from_lines(f.readlines())
- return directive, transport
- else:
- return _serializer.read_bundle(f), transport
+ except errors.TooManyRedirections:
+ raise errors.NotABundle(transport.clone(filename).base)
except (errors.ConnectionReset, errors.ConnectionError), e:
raise
except (errors.TransportError, errors.PathError), e:
@@ -91,6 +83,11 @@
# StubSFTPServer does fail during get() (because of prefetch)
# so it has an opportunity to translate the error.
raise errors.NotABundle(str(e))
- except errors.NotAMergeDirective:
- f.seek(0)
- return _serializer.read_bundle(f), transport
+
+ if _do_directive:
+ try:
+ return MergeDirective.from_lines(bytef), transport
+ except errors.NotAMergeDirective:
+ bytef.seek(0)
+
+ return _serializer.read_bundle(bytef), transport
=== modified file 'bzrlib/merge_directive.py'
--- a/bzrlib/merge_directive.py 2009-10-29 05:49:32 +0000
+++ b/bzrlib/merge_directive.py 2009-11-28 00:48:03 +0000
@@ -371,15 +371,13 @@
:return: a MergeRequest
"""
line_iter = iter(lines)
+ firstline = ""
for line in line_iter:
if line.startswith('# Bazaar merge directive format '):
- break
- else:
- if len(lines) > 0:
- raise errors.NotAMergeDirective(lines[0])
- else:
- raise errors.NotAMergeDirective('')
- return _format_registry.get(line[2:].rstrip())._from_lines(line_iter)
+ return _format_registry.get(line[2:].rstrip())._from_lines(
+ line_iter)
+ firstline = firstline or line.strip()
+ raise errors.NotAMergeDirective(firstline)
@classmethod
def _from_lines(klass, line_iter):
=== modified file 'bzrlib/tests/blackbox/test_merge.py'
--- a/bzrlib/tests/blackbox/test_merge.py 2009-10-06 14:40:37 +0000
+++ b/bzrlib/tests/blackbox/test_merge.py 2009-11-09 00:39:44 +0000
@@ -589,6 +589,18 @@
self.run_bzr('merge -d this other -r0..')
self.failUnlessExists('this/other_file')
+ def test_merge_reversed_revision_range(self):
+ tree = self.make_branch_and_tree(".")
+ for f in ("a", "b"):
+ self.build_tree([f])
+ tree.add(f)
+ tree.commit("added "+f)
+ for context in (".", "", "a"):
+ self.run_bzr("merge -r 1..0 " + context)
+ self.failIfExists("a")
+ tree.revert()
+ self.failUnlessExists("a")
+
class TestMergeForce(tests.TestCaseWithTransport):
=== modified file 'bzrlib/tests/blackbox/test_send.py'
--- a/bzrlib/tests/blackbox/test_send.py 2009-10-02 07:24:29 +0000
+++ b/bzrlib/tests/blackbox/test_send.py 2009-11-28 00:48:03 +0000
@@ -67,7 +67,7 @@
def get_MD(self, args, cmd=None, wd='branch'):
out = StringIO(self.run_send(args, cmd=cmd, wd=wd)[0])
- return merge_directive.MergeDirective.from_lines(out.readlines())
+ return merge_directive.MergeDirective.from_lines(out)
def assertBundleContains(self, revs, args, cmd=None, wd='branch'):
md = self.get_MD(args, cmd=cmd, wd=wd)
@@ -322,8 +322,7 @@
out, err = self.run_send(args)
self.assertEquals(
'Bundling %d revision(s).\n' % len(revs), err)
- md = merge_directive.MergeDirective.from_lines(
- StringIO(out).readlines())
+ md = merge_directive.MergeDirective.from_lines(StringIO(out))
self.assertEqual('parent', md.base_revision_id)
br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
More information about the bazaar-commits
mailing list