Rev 5089: (Jelmer) Support merge directives with multiple output files. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Sat Mar 13 23:39:35 GMT 2010
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5089 [merge]
revision-id: pqm at pqm.ubuntu.com-20100313233933-4xpo3axwexbhu2jz
parent: pqm at pqm.ubuntu.com-20100313005423-zi688149jc260xvl
parent: jelmer at samba.org-20100313024914-rpuoguinoxpxt05b
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sat 2010-03-13 23:39:33 +0000
message:
(Jelmer) Support merge directives with multiple output files.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/bundle/commands.py __init__.py-20050617152058-1b6530d9ab85c11c
bzrlib/hooks.py hooks.py-20070325015548-ix4np2q0kd8452au-1
bzrlib/merge_directive.py merge_directive.py-20070228184838-ja62280spt1g7f4x-1
bzrlib/send.py send.py-20090521192735-j7cdb33ykmtmzx4w-1
=== modified file 'NEWS'
--- a/NEWS 2010-03-11 18:00:23 +0000
+++ b/NEWS 2010-03-12 19:59:50 +0000
@@ -135,6 +135,10 @@
API Changes
***********
+* ``bzrlib.merge_directive._BaseMergeDirective`` has been renamed to
+ ``bzrlib.merge_directive.BaseMergeDirective`` and is now public.
+ (Jelmer Vernooij)
+
* ``BranchFormat.initialize`` now takes an optional ``name`` of the colocated
branch to create. (Jelmer Vernooij)
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2010-03-08 02:23:17 +0000
+++ b/bzrlib/builtins.py 2010-03-13 02:49:14 +0000
@@ -5143,7 +5143,7 @@
short_name='f',
type=unicode),
Option('output', short_name='o',
- help='Write merge directive to this file; '
+ help='Write merge directive to this file or directory; '
'use - for stdout.',
type=unicode),
Option('strict',
=== modified file 'bzrlib/bundle/commands.py'
--- a/bzrlib/bundle/commands.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/bundle/commands.py 2010-03-12 19:59:50 +0000
@@ -54,7 +54,7 @@
from bzrlib import osutils
term_encoding = osutils.get_terminal_encoding()
bundle_info = read_mergeable_from_url(location)
- if isinstance(bundle_info, merge_directive._BaseMergeDirective):
+ if isinstance(bundle_info, merge_directive.BaseMergeDirective):
bundle_file = StringIO(bundle_info.get_raw_bundle())
bundle_info = read_bundle(bundle_file)
else:
=== modified file 'bzrlib/hooks.py'
--- a/bzrlib/hooks.py 2010-02-17 17:11:16 +0000
+++ b/bzrlib/hooks.py 2010-03-12 19:59:50 +0000
@@ -59,7 +59,7 @@
('bzrlib.version_info_formats.format_rio', 'RioVersionInfoBuilder.hooks'),
'bzrlib.version_info_formats.format_rio', 'RioVersionInfoBuilderHooks')
known_hooks.register_lazy(
- ('bzrlib.merge_directive', '_BaseMergeDirective.hooks'),
+ ('bzrlib.merge_directive', 'BaseMergeDirective.hooks'),
'bzrlib.merge_directive', 'MergeDirectiveHooks')
=== modified file 'bzrlib/merge_directive.py'
--- a/bzrlib/merge_directive.py 2010-02-17 17:11:16 +0000
+++ b/bzrlib/merge_directive.py 2010-03-13 02:49:14 +0000
@@ -64,10 +64,20 @@
" provided to the next.", (1, 15, 0), False))
-class _BaseMergeDirective(object):
+class BaseMergeDirective(object):
+ """A request to perform a merge into a branch.
+
+ This is the base class that all merge directive implementations
+ should derive from.
+
+ :cvar multiple_output_files: Whether or not this merge directive
+ stores a set of revisions in more than one file
+ """
hooks = MergeDirectiveHooks()
+ multiple_output_files = False
+
def __init__(self, revision_id, testament_sha1, time, timezone,
target_branch, patch=None, source_branch=None, message=None,
bundle=None):
@@ -92,6 +102,27 @@
self.source_branch = source_branch
self.message = message
+ def to_lines(self):
+ """Serialize as a list of lines
+
+ :return: a list of lines
+ """
+ raise NotImplementedError(self.to_lines)
+
+ def to_files(self):
+ """Serialize as a set of files.
+
+ :return: List of tuples with filename and contents as lines
+ """
+ raise NotImplementedError(self.to_files)
+
+ def get_raw_bundle(self):
+ """Return the bundle for this merge directive.
+
+ :return: bundle text or None if there is no bundle
+ """
+ return None
+
def _to_lines(self, base_revision=False):
"""Serialize as a list of lines
@@ -111,6 +142,13 @@
lines.append('# \n')
return lines
+ def write_to_directory(self, path):
+ """Write this merge directive to a series of files in a directory.
+
+ :param path: Filesystem path to write to
+ """
+ raise NotImplementedError(self.write_to_directory)
+
@classmethod
def from_objects(klass, repository, revision_id, time, timezone,
target_branch, patch_type='bundle',
@@ -303,7 +341,7 @@
basename, body)
-class MergeDirective(_BaseMergeDirective):
+class MergeDirective(BaseMergeDirective):
"""A request to perform a merge into a branch.
@@ -338,7 +376,7 @@
:param source_branch: A public location to merge the revision from
:param message: The message to use when committing this merge
"""
- _BaseMergeDirective.__init__(self, revision_id, testament_sha1, time,
+ BaseMergeDirective.__init__(self, revision_id, testament_sha1, time,
timezone, target_branch, patch, source_branch, message)
if patch_type not in (None, 'diff', 'bundle'):
raise ValueError(patch_type)
@@ -428,7 +466,7 @@
return None, self.revision_id, 'inapplicable'
-class MergeDirective2(_BaseMergeDirective):
+class MergeDirective2(BaseMergeDirective):
_format_string = 'Bazaar merge directive format 2 (Bazaar 0.90)'
@@ -437,7 +475,7 @@
bundle=None, base_revision_id=None):
if source_branch is None and bundle is None:
raise errors.NoMergeSource()
- _BaseMergeDirective.__init__(self, revision_id, testament_sha1, time,
+ BaseMergeDirective.__init__(self, revision_id, testament_sha1, time,
timezone, target_branch, patch, source_branch, message)
self.bundle = bundle
self.base_revision_id = base_revision_id
=== modified file 'bzrlib/send.py'
--- a/bzrlib/send.py 2010-02-10 02:17:15 +0000
+++ b/bzrlib/send.py 2010-03-13 02:49:14 +0000
@@ -15,6 +15,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import os
import time
from bzrlib import (
@@ -134,15 +135,29 @@
directive.compose_merge_request(mail_client, mail_to, body,
branch, tree)
else:
- if output == '-':
- outfile = to_file
+ if directive.multiple_output_files:
+ if output == '-':
+ raise errors.BzrCommandError('- not supported for '
+ 'merge directives that use more than one output file.')
+ if not os.path.exists(output):
+ os.mkdir(output, 0755)
+ for (filename, lines) in directive.to_files():
+ path = os.path.join(output, filename)
+ outfile = open(path, 'wb')
+ try:
+ outfile.writelines(lines)
+ finally:
+ outfile.close()
else:
- outfile = open(output, 'wb')
- try:
- outfile.writelines(directive.to_lines())
- finally:
- if outfile is not to_file:
- outfile.close()
+ if output == '-':
+ outfile = to_file
+ else:
+ outfile = open(output, 'wb')
+ try:
+ outfile.writelines(directive.to_lines())
+ finally:
+ if outfile is not to_file:
+ outfile.close()
finally:
branch.unlock()
More information about the bazaar-commits
mailing list