Rev 66: Avoid direct use of cmd_bundle_revisions. in file:///home/jelmer/bzr-submit/trunk/
Jelmer Vernooij
jelmer at samba.org
Wed Apr 11 15:44:35 BST 2007
At file:///home/jelmer/bzr-submit/trunk/
------------------------------------------------------------
revno: 66
revision-id: jelmer at samba.org-20070411144429-a40kzl6gdnfqyazf
parent: jelmer at samba.org-20070411143422-wxjop3d3u006dyw5
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Wed 2007-04-11 16:44:29 +0200
message:
Avoid direct use of cmd_bundle_revisions.
modified:
submit_helpers.py submit_helpers.py-20060624164558-9aabyghnw7kxeuwg-2
=== modified file 'submit_helpers.py'
--- a/submit_helpers.py 2007-04-11 14:34:22 +0000
+++ b/submit_helpers.py 2007-04-11 14:44:29 +0000
@@ -15,6 +15,7 @@
import bzrlib.osutils
import bzrlib.urlutils
from bzrlib import (bundle, errors, gpg, user_encoding)
+from bzrlib.bundle.serializer import (read_bundle, write_bundle)
from bzrlib.errors import BzrCommandError
from bzrlib.trace import (note, warning)
@@ -183,41 +184,12 @@
return '[PATCH] ' + rev.message.replace('\n', ' ')
def get_bundle_text(branch, revision, remember):
- """Handle tempfile etc. during bundle creation"""
- if base is not None:
- bundle_remember = remember
- else:
- bundle_remember = False
-
- #TODO: Use StringIO instead of tempfile
- # This requires calling the bundle creating function directly instead of
- # the command.run() function
- bundle_file = None
- try:
- tmp_fileno, bundle_file = tempfile.mkstemp(prefix='bundle', dir=u'.')
- os.close(tmp_fileno)
-
- bundle_cmd = bundle.commands.cmd_bundle_revisions()
- bundle_cmd.run(base, revision, output = bundle_file,
- remember = bundle_remember)
-
- f = open(bundle_file, "r")
- bundle_text = f.read()
- f.close()
- finally:
- if bundle_file is not None:
- try:
- os.unlink(bundle_file)
- except OSError, e:
- warning("Could not unlink temporary file:", bundle_file, str(e))
-
- if len(bundle_text)<40:
- # Currently an empty bundle is 32 bytes long.
- # 40 bytes leaves some space for future changes
- # but should be low enough to let all valid bundles
- # pass through
- raise BzrCommandError("Sending an empty bundle makes no sense")
- return bundle_text
+ """Obtain the text for a bundle."""
+ stream = StringIO()
+ write_bundle(branch.repository, revision,
+ branch.repository.revision_parents(revision)[0], stream)
+ stream.seek(0)
+ return stream.read()
def get_message_text(mail_to, bundle_text, message_file):
"""Get message either by launching an editor or reading message_file."""
@@ -300,6 +272,9 @@
__init__.read_options(branch)
mail_to, multipart, pqm = get_mailto(config, address, target,
remember, dry_run)
+
+ if revision is None:
+ revision = branch.last_revision()
bundle_text = get_bundle_text(branch, revision, remember)
@@ -399,7 +374,6 @@
""" Apply a bundle from an email message. """
from bzrlib.workingtree import WorkingTree
- from bzrlib.bundle.serializer import read_bundle
from bzrlib.bundle.apply_bundle import install_bundle
from bzrlib.testament import Testament
from bzrlib.merge import Merge3Merger
More information about the bazaar-commits
mailing list