Rev 63: Merge from trunk in file:///home/jelmer/bzr-submit/nowrap/

Jelmer Vernooij jelmer at samba.org
Wed Apr 11 16:03:56 BST 2007


At file:///home/jelmer/bzr-submit/nowrap/

------------------------------------------------------------
revno: 63
revision-id: jelmer at samba.org-20070411150352-i05y7y3iyztrciad
parent: jelmer at samba.org-20070411142424-8n2iy03yn6bmr0sh
parent: jelmer at samba.org-20070411145239-6scra7lush8lk57w
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: nowrap
timestamp: Wed 2007-04-11 17:03:52 +0200
message:
  Merge from trunk
modified:
  TODO                           todo-20061109184753-jxe69s6g2p00byt4-1
  __init__.py                    __init__.py-20060624164558-9aabyghnw7kxeuwg-1
  submit_helpers.py              submit_helpers.py-20060624164558-9aabyghnw7kxeuwg-2
    ------------------------------------------------------------
    revno: 59.1.8
    merged: jelmer at samba.org-20070411145239-6scra7lush8lk57w
    parent: jelmer at samba.org-20070411144429-a40kzl6gdnfqyazf
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: trunk
    timestamp: Wed 2007-04-11 16:52:39 +0200
    message:
      Move revision parse code to cmd_submit_bundle class.
    ------------------------------------------------------------
    revno: 59.1.7
    merged: 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.
    ------------------------------------------------------------
    revno: 59.1.6
    merged: jelmer at samba.org-20070411143422-wxjop3d3u006dyw5
    parent: jelmer at samba.org-20070409153408-w669pmw6slksneh5
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: trunk
    timestamp: Wed 2007-04-11 16:34:22 +0200
    message:
      Allow passing in a branch argument to submit_bundle (useful for testing).
=== modified file 'TODO'
--- a/TODO	2007-03-23 23:17:50 +0000
+++ b/TODO	2007-04-11 14:52:39 +0000
@@ -2,3 +2,4 @@
 - Convert to 0.15 hooks
 - Write tests!
 - Set content-type headers.
+- support submitting more than one bundle

=== modified file '__init__.py'
--- a/__init__.py	2007-04-09 15:32:00 +0000
+++ b/__init__.py	2007-04-11 15:03:52 +0000
@@ -53,9 +53,22 @@
                     ]
     aliases = ['submit']
 
-    def run(self, branch=None, from_address=None, **parameters):
+    def run(self, branch=None, from_address=None, revision=None, **parameters):
         from submit_helpers import submit_bundle
-        return submit_bundle(branch, mail_from=from_address, **parameters)
+        from bzrlib.branch import Branch
+
+        branch = Branch.open_containing('.')[0]
+        if revision is None:
+            rev_id = branch.last_revision()
+        else:
+            if len(revision)==1:
+                rev_id = revision[0].in_history(branch).rev_id
+            else:
+                rev_id = revision[1].in_history(branch).rev_id    
+                if rev_id is None:
+                    rev_id = revision[0].in_history(branch).rev_id
+        return submit_bundle(branch, mail_from=from_address, revision=rev_id,
+                             **parameters)
 
 
 class cmd_apply_bundle(Command):

=== modified file 'submit_helpers.py'
--- a/submit_helpers.py	2007-04-11 14:24:24 +0000
+++ b/submit_helpers.py	2007-04-11 15:03:52 +0000
@@ -15,7 +15,9 @@
 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.testament import Testament
 from bzrlib.trace import (note, warning)
 
 # This allows easy extension
@@ -128,7 +130,6 @@
     return (mail_to, multipart, pqm)
 
 
-
 # Taken from pqm-submit plugin. 
 # http://bazaar.launchpad.net/~bzr-pqm-devel/bzr-pqm/devel/
 def public_branch(branch, config):
@@ -145,26 +146,6 @@
     return target_base
 
 
-def get_testament(branch, revision):
-    """ Get the testament for the specified revision. """
-    from bzrlib.testament import Testament
-    branch.lock_read()
-    try:
-        if revision is None:
-            rev_id = branch.last_revision()
-        else:
-            if len(revision)==1:
-                rev_id = revision[0].in_history(branch).rev_id
-            else:
-                rev_id = revision[1].in_history(branch).rev_id    
-                if rev_id is None:
-                    rev_id = revision[0].in_history(branch).rev_id
-        testament = Testament.from_revision(branch.repository, 
-            rev_id).as_short_text()
-    finally:
-        branch.unlock()
-    return testament
-
 def send_message(config, mail_from, mail_to, msg_text):
     """ Actually send the message via smtp. """
     username = config.get_smtp_user()
@@ -183,42 +164,13 @@
     rev = branch.repository.get_revision(branch.last_revision())
     return '[PATCH] ' + rev.message.replace('\n', ' ') 
     
-def get_bundle_text(base, 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
+def get_bundle_text(branch, revision, remember):
+    """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."""
@@ -265,13 +217,13 @@
         msg.attach(part)
     return msg.as_string()
 
-def submit_bundle(base=None, revision=None, subject=None, dry_run=False, 
+def submit_bundle(branch=None, revision=None, subject=None, dry_run=False, 
     message_file=None, address=None, remember=False, target='default', 
     mail_from=None, output_file=None):
     """Submit a bundle via email.
     
         Parameters:
-            base, revision: Same as the parameter to the bundle command
+            branch, revision: Same as the parameter to the bundle command
             subject: Message subject (defaults to [PATCH] + commit_message)
             dry_run: Print the message to stdout
             message_file: Read message from this file
@@ -283,8 +235,6 @@
                          (forces dry_run = True)
     """
     
-    from bzrlib.bzrdir import BzrDir
-    branch = BzrDir.open_containing('.')[0].open_branch()
     config = BranchConfigSubmitBundle(branch)
     
     if output_file:
@@ -295,16 +245,19 @@
         mail_from = config.username()
 
     try:
-        mail_to, multipart, pqm = get_mailto(address, target, 
+        mail_to, multipart, pqm = get_mailto(config, address, target, 
             remember, dry_run)
     except BzrCommandError:
         #Ugly hack
         import __init__
         __init__.read_options(branch)
-        mail_to, multipart, pqm = get_mailto(address, target, 
+        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(base, revision, remember)
+    bundle_text = get_bundle_text(branch, revision, remember)
 
     if not pqm:
         message_text = get_message_text(mail_to, bundle_text, message_file)
@@ -313,8 +266,9 @@
             base = public_branch(branch, config) 
         message_text = "patch %s" % base
 
-    message_text = message_text + "\n" + get_testament(branch, revision)
-    
+    message_text += "\n" + \
+            Testament.from_revision(branch.repository, revision).as_short_text()
+
     if not multipart:
         message_text = message_text + bundle_text
     
@@ -342,9 +296,8 @@
             f.close()
         else:
             print msg
-        return
-    
-    send_message(config, mail_from, mail_to, msg)
+    else:
+        send_message(config, mail_from, mail_to, msg)
     return 0 # Everything OK
 
 
@@ -403,9 +356,7 @@
     """ 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
     testament_re = re.compile(r'bazaar-ng testament short form 1' +
         r'(?P<lineending>\r\n|\n)'+




More information about the bazaar-commits mailing list