Rev 5221: Support normal commit parameters in TreeTransform.commit in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Mon May 10 19:43:22 BST 2010
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5221 [merge]
revision-id: pqm at pqm.ubuntu.com-20100510184319-3mbzqg9cueihvpsw
parent: pqm at pqm.ubuntu.com-20100510172615-7d4a13a5a2omyo0f
parent: aaron at aaronbentley.com-20100510162547-zwzas3zj3xom2jst
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2010-05-10 19:43:19 +0100
message:
Support normal commit parameters in TreeTransform.commit
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/commit.py commit.py-20050511101309-79ec1a0168e0e825
bzrlib/mutabletree.py mutabletree.py-20060906023413-4wlkalbdpsxi2r4y-2
bzrlib/tests/test_transform.py test_transaction.py-20060105172520-b3ffb3946550e6c4
bzrlib/transform.py transform.py-20060105172343-dd99e54394d91687
=== modified file 'NEWS'
--- a/NEWS 2010-05-10 17:26:15 +0000
+++ b/NEWS 2010-05-10 18:43:19 +0000
@@ -281,6 +281,9 @@
* ``bzrlib.diff.get_trees_and_branches_to_diff`` is deprecated. Use
``get_trees_and_branches_to_diff_locked`` instead.
(Andrew Bennetts)
+
+* ``TreeTransform.commit`` supports the full set of commit parameters, and
+ auto-determines branch nick if not supplied. (Aaron Bentley)
Internals
*********
=== modified file 'bzrlib/commit.py'
--- a/bzrlib/commit.py 2010-04-30 11:35:43 +0000
+++ b/bzrlib/commit.py 2010-05-10 11:34:20 +0000
@@ -174,6 +174,43 @@
self.reporter = reporter
self.config = config
+ @staticmethod
+ def update_revprops(revprops, branch, authors=None, author=None,
+ local=False, possible_master_transports=None):
+ if revprops is None:
+ revprops = {}
+ if possible_master_transports is None:
+ possible_master_transports = []
+ if not 'branch-nick' in revprops:
+ revprops['branch-nick'] = branch._get_nick(
+ local,
+ possible_master_transports)
+ if authors is not None:
+ if author is not None:
+ raise AssertionError('Specifying both author and authors '
+ 'is not allowed. Specify just authors instead')
+ if 'author' in revprops or 'authors' in revprops:
+ # XXX: maybe we should just accept one of them?
+ raise AssertionError('author property given twice')
+ if authors:
+ for individual in authors:
+ if '\n' in individual:
+ raise AssertionError('\\n is not a valid character '
+ 'in an author identity')
+ revprops['authors'] = '\n'.join(authors)
+ if author is not None:
+ symbol_versioning.warn('The parameter author was deprecated'
+ ' in version 1.13. Use authors instead',
+ DeprecationWarning)
+ if 'author' in revprops or 'authors' in revprops:
+ # XXX: maybe we should just accept one of them?
+ raise AssertionError('author property given twice')
+ if '\n' in author:
+ raise AssertionError('\\n is not a valid character '
+ 'in an author identity')
+ revprops['authors'] = author
+ return revprops
+
def commit(self,
message=None,
timestamp=None,
=== modified file 'bzrlib/mutabletree.py'
--- a/bzrlib/mutabletree.py 2010-04-22 14:18:17 +0000
+++ b/bzrlib/mutabletree.py 2010-05-10 11:34:20 +0000
@@ -182,39 +182,14 @@
**kwargs):
# avoid circular imports
from bzrlib import commit
- if revprops is None:
- revprops = {}
possible_master_transports=[]
- if not 'branch-nick' in revprops:
- revprops['branch-nick'] = self.branch._get_nick(
+ revprops = commit.Commit.update_revprops(
+ revprops,
+ self.branch,
+ kwargs.pop('authors', None),
+ kwargs.pop('author', None),
kwargs.get('local', False),
possible_master_transports)
- authors = kwargs.pop('authors', None)
- author = kwargs.pop('author', None)
- if authors is not None:
- if author is not None:
- raise AssertionError('Specifying both author and authors '
- 'is not allowed. Specify just authors instead')
- if 'author' in revprops or 'authors' in revprops:
- # XXX: maybe we should just accept one of them?
- raise AssertionError('author property given twice')
- if authors:
- for individual in authors:
- if '\n' in individual:
- raise AssertionError('\\n is not a valid character '
- 'in an author identity')
- revprops['authors'] = '\n'.join(authors)
- if author is not None:
- symbol_versioning.warn('The parameter author was deprecated'
- ' in version 1.13. Use authors instead',
- DeprecationWarning)
- if 'author' in revprops or 'authors' in revprops:
- # XXX: maybe we should just accept one of them?
- raise AssertionError('author property given twice')
- if '\n' in author:
- raise AssertionError('\\n is not a valid character '
- 'in an author identity')
- revprops['authors'] = author
# args for wt.commit start at message from the Commit.commit method,
args = (message, ) + args
for hook in MutableTree.hooks['start_commit']:
=== modified file 'bzrlib/tests/test_transform.py'
--- a/bzrlib/tests/test_transform.py 2010-03-12 10:52:01 +0000
+++ b/bzrlib/tests/test_transform.py 2010-05-10 16:25:47 +0000
@@ -25,23 +25,37 @@
filters,
generate_ids,
osutils,
- progress,
revision as _mod_revision,
rules,
tests,
urlutils,
)
from bzrlib.bzrdir import BzrDir
-from bzrlib.conflicts import (DuplicateEntry, DuplicateID, MissingParent,
- UnversionedParent, ParentLoop, DeletingParent,
- NonDirectoryParent)
+from bzrlib.conflicts import (
+ DeletingParent,
+ DuplicateEntry,
+ DuplicateID,
+ MissingParent,
+ NonDirectoryParent,
+ ParentLoop,
+ UnversionedParent,
+)
from bzrlib.diff import show_diff_trees
-from bzrlib.errors import (DuplicateKey, MalformedTransform, NoSuchFile,
- ReusingTransform, CantMoveRoot,
- PathsNotVersionedError, ExistingLimbo,
- ExistingPendingDeletion, ImmortalLimbo,
- ImmortalPendingDeletion, LockError)
-from bzrlib.osutils import file_kind, pathjoin
+from bzrlib.errors import (
+ DuplicateKey,
+ ExistingLimbo,
+ ExistingPendingDeletion,
+ ImmortalLimbo,
+ ImmortalPendingDeletion,
+ LockError,
+ MalformedTransform,
+ NoSuchFile,
+ ReusingTransform,
+)
+from bzrlib.osutils import (
+ file_kind,
+ pathjoin,
+)
from bzrlib.merge import Merge3Merger, Merger
from bzrlib.tests import (
HardlinkFeature,
@@ -49,12 +63,20 @@
TestCase,
TestCaseInTempDir,
TestSkipped,
- )
-from bzrlib.transform import (TreeTransform, ROOT_PARENT, FinalPaths,
- resolve_conflicts, cook_conflicts,
- build_tree, get_backup_name,
- _FileMover, resolve_checkout,
- TransformPreview, create_from_tree)
+)
+from bzrlib.transform import (
+ build_tree,
+ create_from_tree,
+ cook_conflicts,
+ _FileMover,
+ FinalPaths,
+ get_backup_name,
+ resolve_conflicts,
+ resolve_checkout,
+ ROOT_PARENT,
+ TransformPreview,
+ TreeTransform,
+)
class TestTreeTransform(tests.TestCaseWithTransport):
@@ -2091,6 +2113,38 @@
self.assertRaises(errors.MalformedTransform, tt.commit, branch,
'message')
+ def test_commit_rich_revision_data(self):
+ branch, tt = self.get_branch_and_transform()
+ rev_id = tt.commit(branch, 'message', timestamp=1, timezone=43201,
+ committer='me <me at example.com>',
+ revprops={'foo': 'bar'}, revision_id='revid-1',
+ authors=['Author1 <author1 at example.com>',
+ 'Author2 <author2 at example.com>',
+ ])
+ self.assertEqual('revid-1', rev_id)
+ revision = branch.repository.get_revision(rev_id)
+ self.assertEqual(1, revision.timestamp)
+ self.assertEqual(43201, revision.timezone)
+ self.assertEqual('me <me at example.com>', revision.committer)
+ self.assertEqual(['Author1 <author1 at example.com>',
+ 'Author2 <author2 at example.com>'],
+ revision.get_apparent_authors())
+ del revision.properties['authors']
+ self.assertEqual({'foo': 'bar',
+ 'branch-nick': 'tree'},
+ revision.properties)
+
+ def test_no_explicit_revprops(self):
+ branch, tt = self.get_branch_and_transform()
+ rev_id = tt.commit(branch, 'message', authors=[
+ 'Author1 <author1 at example.com>',
+ 'Author2 <author2 at example.com>', ])
+ revision = branch.repository.get_revision(rev_id)
+ self.assertEqual(['Author1 <author1 at example.com>',
+ 'Author2 <author2 at example.com>'],
+ revision.get_apparent_authors())
+ self.assertEqual('tree', revision.properties['branch-nick'])
+
class MockTransform(object):
=== modified file 'bzrlib/transform.py'
--- a/bzrlib/transform.py 2010-04-30 11:35:43 +0000
+++ b/bzrlib/transform.py 2010-05-10 16:25:47 +0000
@@ -25,6 +25,7 @@
annotate,
bencode,
bzrdir,
+ commit,
delta,
errors,
inventory,
@@ -927,12 +928,27 @@
"""
return _PreviewTree(self)
- def commit(self, branch, message, merge_parents=None, strict=False):
+ def commit(self, branch, message, merge_parents=None, strict=False,
+ timestamp=None, timezone=None, committer=None, authors=None,
+ revprops=None, revision_id=None):
"""Commit the result of this TreeTransform to a branch.
:param branch: The branch to commit to.
:param message: The message to attach to the commit.
- :param merge_parents: Additional parents specified by pending merges.
+ :param merge_parents: Additional parent revision-ids specified by
+ pending merges.
+ :param strict: If True, abort the commit if there are unversioned
+ files.
+ :param timestamp: if not None, seconds-since-epoch for the time and
+ date. (May be a float.)
+ :param timezone: Optional timezone for timestamp, as an offset in
+ seconds.
+ :param committer: Optional committer in email-id format.
+ (e.g. "J Random Hacker <jrandom at example.com>")
+ :param authors: Optional list of authors in email-id format.
+ :param revprops: Optional dictionary of revision properties.
+ :param revision_id: Optional revision id. (Specifying a revision-id
+ may reduce performance for some non-native formats.)
:return: The revision_id of the revision committed.
"""
self._check_malformed()
@@ -955,7 +971,13 @@
if self._tree.get_revision_id() != last_rev_id:
raise ValueError('TreeTransform not based on branch basis: %s' %
self._tree.get_revision_id())
- builder = branch.get_commit_builder(parent_ids)
+ revprops = commit.Commit.update_revprops(revprops, branch, authors)
+ builder = branch.get_commit_builder(parent_ids,
+ timestamp=timestamp,
+ timezone=timezone,
+ committer=committer,
+ revprops=revprops,
+ revision_id=revision_id)
preview = self.get_preview_tree()
list(builder.record_iter_changes(preview, last_rev_id,
self.iter_changes()))
More information about the bazaar-commits
mailing list