Rev 5791: (jelmer) Add --lossy option to 'bzr commit'. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Sat Apr 16 14:16:52 UTC 2011
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5791 [merge]
revision-id: pqm at pqm.ubuntu.com-20110416141650-nyf3g3jmhw9cjoff
parent: pqm at pqm.ubuntu.com-20110416101151-adka24z3gayoxml7
parent: jelmer at samba.org-20110416125114-u8a87fd4u6osm5as
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sat 2011-04-16 14:16:50 +0000
message:
(jelmer) Add --lossy option to 'bzr commit'.
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/commit.py commit.py-20050511101309-79ec1a0168e0e825
bzrlib/plugins/weave_fmt/repository.py presplitout.py-20070125045333-wfav3tsh73oxu3zk-1
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/repofmt/groupcompress_repo.py repofmt.py-20080715094215-wp1qfvoo7093c8qr-1
bzrlib/repofmt/pack_repo.py pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
bzrlib/repository.py rev_storage.py-20051111201905-119e9401e46257e3
bzrlib/tests/blackbox/test_commit.py test_commit.py-20060212094538-ae88fc861d969db0
bzrlib/tests/blackbox/test_dpush.py test_dpush.py-20090108125928-st1td6le59g0vyv2-1
bzrlib/tests/per_repository/test_commit_builder.py test_commit_builder.py-20060606110838-76e3ra5slucqus81-1
bzrlib/tests/test_commit.py test_commit.py-20050914060732-279f057f8c295434
bzrlib/tests/test_foreign.py test_foreign.py-20081125004048-ywb901edgp9lluxo-1
doc/en/release-notes/bzr-2.4.txt bzr2.4.txt-20110114053217-k7ym9jfz243fddjm-1
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2011-04-05 14:57:58 +0000
+++ b/bzrlib/branch.py 2011-04-11 00:18:12 +0000
@@ -699,7 +699,7 @@
def get_commit_builder(self, parents, config=None, timestamp=None,
timezone=None, committer=None, revprops=None,
- revision_id=None):
+ revision_id=None, lossy=False):
"""Obtain a CommitBuilder for this branch.
:param parents: Revision ids of the parents of the new revision.
@@ -709,13 +709,16 @@
:param committer: Optional committer to set for commit.
:param revprops: Optional dictionary of revision properties.
:param revision_id: Optional revision id.
+ :param lossy: Whether to discard data that can not be natively
+ represented, when pushing to a foreign VCS
"""
if config is None:
config = self.get_config()
return self.repository.get_commit_builder(self, parents, config,
- timestamp, timezone, committer, revprops, revision_id)
+ timestamp, timezone, committer, revprops, revision_id,
+ lossy)
def get_master_branch(self, possible_transports=None):
"""Return the branch we are bound to.
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2011-04-07 11:25:14 +0000
+++ b/bzrlib/builtins.py 2011-04-11 00:18:12 +0000
@@ -3144,6 +3144,10 @@
Option('show-diff', short_name='p',
help='When no message is supplied, show the diff along'
' with the status summary in the message editor.'),
+ Option('lossy',
+ help='When committing to a foreign version control '
+ 'system do not push data that can not be natively '
+ 'represented.'),
]
aliases = ['ci', 'checkin']
@@ -3168,7 +3172,8 @@
def run(self, message=None, file=None, verbose=False, selected_list=None,
unchanged=False, strict=False, local=False, fixes=None,
- author=None, show_diff=False, exclude=None, commit_time=None):
+ author=None, show_diff=False, exclude=None, commit_time=None,
+ lossy=False):
from bzrlib.errors import (
PointlessCommit,
ConflictsInTree,
@@ -3270,7 +3275,8 @@
reporter=None, verbose=verbose, revprops=properties,
authors=author, timestamp=commit_stamp,
timezone=offset,
- exclude=tree.safe_relpath_files(exclude))
+ exclude=tree.safe_relpath_files(exclude),
+ lossy=lossy)
except PointlessCommit:
raise errors.BzrCommandError("No changes to commit."
" Please 'bzr add' the files you want to commit, or use"
=== modified file 'bzrlib/commit.py'
--- a/bzrlib/commit.py 2011-03-13 22:22:43 +0000
+++ b/bzrlib/commit.py 2011-04-13 00:58:10 +0000
@@ -229,7 +229,8 @@
message_callback=None,
recursive='down',
exclude=None,
- possible_master_transports=None):
+ possible_master_transports=None,
+ lossy=False):
"""Commit working copy as a new revision.
:param message: the commit message (it or message_callback is required)
@@ -262,6 +263,8 @@
:param exclude: None or a list of relative paths to exclude from the
commit. Pending changes to excluded files will be ignored by the
commit.
+ :param lossy: When committing to a foreign VCS, ignore any
+ data that can not be natively represented.
"""
operation = OperationWithCleanups(self._commit)
self.revprops = revprops or {}
@@ -283,12 +286,13 @@
message_callback=message_callback,
recursive=recursive,
exclude=exclude,
- possible_master_transports=possible_master_transports)
+ possible_master_transports=possible_master_transports,
+ lossy=lossy)
def _commit(self, operation, message, timestamp, timezone, committer,
specific_files, rev_id, allow_pointless, strict, verbose,
working_tree, local, reporter, message_callback, recursive,
- exclude, possible_master_transports):
+ exclude, possible_master_transports, lossy):
mutter('preparing to commit')
if working_tree is None:
@@ -400,8 +404,10 @@
# Collect the changes
self._set_progress_stage("Collecting changes", counter=True)
+ self._lossy = lossy
self.builder = self.branch.get_commit_builder(self.parents,
- self.config, timestamp, timezone, committer, self.revprops, rev_id)
+ self.config, timestamp, timezone, committer, self.revprops,
+ rev_id, lossy=lossy)
if not self.builder.supports_record_entry_contents and self.exclude:
self.builder.abort()
raise errors.ExcludesUnsupported(self.branch.repository)
=== modified file 'bzrlib/plugins/weave_fmt/repository.py'
--- a/bzrlib/plugins/weave_fmt/repository.py 2011-04-09 00:13:12 +0000
+++ b/bzrlib/plugins/weave_fmt/repository.py 2011-04-16 12:51:14 +0000
@@ -145,10 +145,10 @@
def get_commit_builder(self, branch, parents, config, timestamp=None,
timezone=None, committer=None, revprops=None,
- revision_id=None):
+ revision_id=None, lossy=False):
self._check_ascii_revisionid(revision_id, self.get_commit_builder)
result = CommitBuilder(self, parents, config, timestamp, timezone,
- committer, revprops, revision_id)
+ committer, revprops, revision_id, lossy=lossy)
self.start_write_group()
return result
@@ -234,10 +234,10 @@
def get_commit_builder(self, branch, parents, config, timestamp=None,
timezone=None, committer=None, revprops=None,
- revision_id=None):
+ revision_id=None, lossy=False):
self._check_ascii_revisionid(revision_id, self.get_commit_builder)
result = CommitBuilder(self, parents, config, timestamp, timezone,
- committer, revprops, revision_id)
+ committer, revprops, revision_id, lossy=lossy)
self.start_write_group()
return result
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2011-04-08 12:28:37 +0000
+++ b/bzrlib/remote.py 2011-04-11 00:18:12 +0000
@@ -1481,14 +1481,15 @@
def get_commit_builder(self, branch, parents, config, timestamp=None,
timezone=None, committer=None, revprops=None,
- revision_id=None):
+ revision_id=None, lossy=False):
# FIXME: It ought to be possible to call this without immediately
# triggering _ensure_real. For now it's the easiest thing to do.
self._ensure_real()
real_repo = self._real_repository
builder = real_repo.get_commit_builder(branch, parents,
config, timestamp=timestamp, timezone=timezone,
- committer=committer, revprops=revprops, revision_id=revision_id)
+ committer=committer, revprops=revprops,
+ revision_id=revision_id, lossy=lossy)
return builder
def add_fallback_repository(self, repository):
=== modified file 'bzrlib/repofmt/groupcompress_repo.py'
--- a/bzrlib/repofmt/groupcompress_repo.py 2011-04-15 11:07:12 +0000
+++ b/bzrlib/repofmt/groupcompress_repo.py 2011-04-16 14:16:50 +0000
@@ -26,7 +26,6 @@
errors,
index as _mod_index,
inventory,
- knit,
osutils,
pack,
revision as _mod_revision,
=== modified file 'bzrlib/repofmt/pack_repo.py'
--- a/bzrlib/repofmt/pack_repo.py 2011-04-15 11:07:12 +0000
+++ b/bzrlib/repofmt/pack_repo.py 2011-04-16 14:16:50 +0000
@@ -80,10 +80,10 @@
def __init__(self, repository, parents, config, timestamp=None,
timezone=None, committer=None, revprops=None,
- revision_id=None):
+ revision_id=None, lossy=False):
CommitBuilder.__init__(self, repository, parents, config,
timestamp=timestamp, timezone=timezone, committer=committer,
- revprops=revprops, revision_id=revision_id)
+ revprops=revprops, revision_id=revision_id, lossy=lossy)
self._file_graph = graph.Graph(
repository._pack_collection.text_index.combined_index)
@@ -101,10 +101,10 @@
def __init__(self, repository, parents, config, timestamp=None,
timezone=None, committer=None, revprops=None,
- revision_id=None):
+ revision_id=None, lossy=False):
CommitBuilder.__init__(self, repository, parents, config,
timestamp=timestamp, timezone=timezone, committer=committer,
- revprops=revprops, revision_id=revision_id)
+ revprops=revprops, revision_id=revision_id, lossy=lossy)
self._file_graph = graph.Graph(
repository._pack_collection.text_index.combined_index)
=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py 2011-04-15 11:07:12 +0000
+++ b/bzrlib/repository.py 2011-04-16 14:16:50 +0000
@@ -93,7 +93,7 @@
def __init__(self, repository, parents, config, timestamp=None,
timezone=None, committer=None, revprops=None,
- revision_id=None):
+ revision_id=None, lossy=False):
"""Initiate a CommitBuilder.
:param repository: Repository to commit to.
@@ -103,8 +103,11 @@
:param committer: Optional committer to set for commit.
:param revprops: Optional dictionary of revision properties.
:param revision_id: Optional revision id.
+ :param lossy: Whether to discard data that can not be natively
+ represented, when pushing to a foreign VCS
"""
self._config = config
+ self._lossy = lossy
if committer is None:
self._committer = self._config.username()
@@ -1782,7 +1785,7 @@
def get_commit_builder(self, branch, parents, config, timestamp=None,
timezone=None, committer=None, revprops=None,
- revision_id=None):
+ revision_id=None, lossy=False):
"""Obtain a CommitBuilder for this repository.
:param branch: Branch to commit to.
@@ -1793,13 +1796,16 @@
:param committer: Optional committer to set for commit.
:param revprops: Optional dictionary of revision properties.
:param revision_id: Optional revision id.
+ :param lossy: Whether to discard data that can not be natively
+ represented, when pushing to a foreign VCS
"""
if self._fallback_repositories and not self._format.supports_chks:
raise errors.BzrError("Cannot commit directly to a stacked branch"
" in pre-2a formats. See "
"https://bugs.launchpad.net/bzr/+bug/375013 for details.")
result = self._commit_builder_class(self, parents, config,
- timestamp, timezone, committer, revprops, revision_id)
+ timestamp, timezone, committer, revprops, revision_id,
+ lossy)
self.start_write_group()
return result
=== modified file 'bzrlib/tests/blackbox/test_commit.py'
--- a/bzrlib/tests/blackbox/test_commit.py 2011-04-07 13:08:39 +0000
+++ b/bzrlib/tests/blackbox/test_commit.py 2011-04-13 02:01:11 +0000
@@ -34,6 +34,7 @@
from bzrlib.bzrdir import BzrDir
from bzrlib.tests import (
probe_bad_non_ascii,
+ test_foreign,
TestSkipped,
UnicodeFilenameFeature,
)
@@ -72,6 +73,20 @@
self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
self.assertEqual('', self.run_bzr('unknowns')[0])
+ def test_commit_lossy_native(self):
+ """A --lossy option to commit is supported."""
+ self.make_branch_and_tree('.')
+ self.run_bzr('commit --lossy --unchanged -m message')
+ self.assertEqual('', self.run_bzr('unknowns')[0])
+
+ def test_commit_lossy_foreign(self):
+ test_foreign.register_dummy_foreign_for_test(self)
+ self.make_branch_and_tree('.',
+ format=test_foreign.DummyForeignVcsDirFormat())
+ self.run_bzr('commit --lossy --unchanged -m message')
+ output = self.run_bzr('revision-info')[0]
+ self.assertTrue(output.startswith('1 dummy-'))
+
def test_commit_with_path(self):
"""Commit tree with path of root specified"""
a_tree = self.make_branch_and_tree('a')
@@ -91,7 +106,6 @@
self.run_bzr('resolved b/a_file')
self.run_bzr(['commit', '-m', 'merge into b', 'b'])
-
def test_10_verbose_commit(self):
"""Add one file and examine verbose commit output"""
tree = self.make_branch_and_tree('.')
=== modified file 'bzrlib/tests/blackbox/test_dpush.py'
--- a/bzrlib/tests/blackbox/test_dpush.py 2011-01-10 22:20:12 +0000
+++ b/bzrlib/tests/blackbox/test_dpush.py 2011-04-16 08:41:33 +0000
@@ -18,17 +18,10 @@
"""Black-box tests for bzr dpush."""
-import os
-
from bzrlib import (
- branch,
- bzrdir,
- foreign,
tests,
- workingtree,
)
from bzrlib.tests import (
- blackbox,
script,
test_foreign,
)
@@ -60,7 +53,9 @@
source_tree = self.make_branch_and_tree("dc")
output, error = self.run_bzr("dpush -d dc dp", retcode=3)
self.assertEquals("", output)
- self.assertContainsRe(error, 'in the same VCS, lossy push not necessary. Please use regular push.')
+ self.assertContainsRe(error,
+ 'in the same VCS, lossy push not necessary. Please use regular '
+ 'push.')
def test_dpush(self):
branch = self.make_dummy_builder('d').get_branch()
@@ -71,6 +66,8 @@
script.run_script(self, """
$ bzr dpush -d dc d
+ 2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
+ 2>This may take some time. Upgrade the repositories to the same format for better performance.
2>Pushed up to revision 2.
$ bzr status dc
""")
@@ -86,6 +83,8 @@
script.run_script(self, '''
$ bzr dpush -d dc d
+ 2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
+ 2>This may take some time. Upgrade the repositories to the same format for better performance.
2>Pushed up to revision 2.
$ bzr revno dc
2
@@ -104,6 +103,8 @@
self.build_tree_contents([("dc/foofile", "blaaaal")])
script.run_script(self, '''
$ bzr dpush -d dc d --no-strict
+ 2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
+ 2>This may take some time. Upgrade the repositories to the same format for better performance.
2>Pushed up to revision 2.
''')
self.assertFileEqual("blaaaal", "dc/foofile")
=== modified file 'bzrlib/tests/per_repository/test_commit_builder.py'
--- a/bzrlib/tests/per_repository/test_commit_builder.py 2011-04-06 11:07:17 +0000
+++ b/bzrlib/tests/per_repository/test_commit_builder.py 2011-04-13 09:45:01 +0000
@@ -118,6 +118,20 @@
finally:
tree.unlock()
+ def test_commit_lossy(self):
+ tree = self.make_branch_and_tree(".")
+ tree.lock_write()
+ try:
+ builder = tree.branch.get_commit_builder([], lossy=True)
+ list(builder.record_iter_changes(tree, tree.last_revision(),
+ tree.iter_changes(tree.basis_tree())))
+ builder.finish_inventory()
+ rev_id = builder.commit('foo bar blah')
+ finally:
+ tree.unlock()
+ rev = tree.branch.repository.get_revision(rev_id)
+ self.assertEqual('foo bar blah', rev.message)
+
def test_commit_message(self):
tree = self.make_branch_and_tree(".")
tree.lock_write()
=== modified file 'bzrlib/tests/test_commit.py'
--- a/bzrlib/tests/test_commit.py 2011-04-14 07:53:38 +0000
+++ b/bzrlib/tests/test_commit.py 2011-04-16 08:18:28 +0000
@@ -28,7 +28,11 @@
from bzrlib.config import BranchConfig
from bzrlib.errors import (PointlessCommit, BzrError, SigningFailed,
LockContention)
-from bzrlib.tests import SymlinkFeature, TestCaseWithTransport
+from bzrlib.tests import (
+ SymlinkFeature,
+ TestCaseWithTransport,
+ test_foreign,
+ )
# TODO: Test commit with some added, and added-but-missing files
@@ -103,6 +107,27 @@
tree2.unlock()
self.assertEqual('version 2', text)
+ def test_commit_lossy_native(self):
+ """Attempt a lossy commit to a native branch."""
+ wt = self.make_branch_and_tree('.')
+ b = wt.branch
+ file('hello', 'w').write('hello world')
+ wt.add('hello')
+ revid = wt.commit(message='add hello', rev_id='revid', lossy=True)
+ self.assertEquals('revid', revid)
+
+ def test_commit_lossy_foreign(self):
+ """Attempt a lossy commit to a foreign branch."""
+ test_foreign.register_dummy_foreign_for_test(self)
+ wt = self.make_branch_and_tree('.',
+ format=test_foreign.DummyForeignVcsDirFormat())
+ b = wt.branch
+ file('hello', 'w').write('hello world')
+ wt.add('hello')
+ revid = wt.commit(message='add hello', lossy=True,
+ timestamp=1302659388, timezone=0)
+ self.assertEquals('dummy-v1:1302659388.0-0-UNKNOWN', revid)
+
def test_missing_commit(self):
"""Test a commit with a missing file"""
wt = self.make_branch_and_tree('.')
@@ -349,7 +374,6 @@
def test_strict_commit_without_unknowns(self):
"""Try and commit with no unknown files and strict = True,
should work."""
- from bzrlib.errors import StrictCommitFailed
wt = self.make_branch_and_tree('.')
b = wt.branch
file('hello', 'w').write('hello world')
@@ -407,7 +431,6 @@
wt.commit("base", allow_pointless=True, rev_id='A')
self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
try:
- from bzrlib.testament import Testament
# monkey patch gpg signing mechanism
bzrlib.gpg.GPGStrategy = bzrlib.gpg.DisabledGPGStrategy
config = MustSignConfig(branch)
=== modified file 'bzrlib/tests/test_foreign.py'
--- a/bzrlib/tests/test_foreign.py 2011-03-10 16:14:09 +0000
+++ b/bzrlib/tests/test_foreign.py 2011-04-16 08:41:33 +0000
@@ -26,11 +26,14 @@
foreign,
lockable_files,
lockdir,
+ repository,
revision,
tests,
trace,
)
+from bzrlib.repofmt import groupcompress_repo
+
# This is the dummy foreign revision control system, used
# mainly here in the testsuite to test the foreign VCS infrastructure.
# It is basically standard Bazaar with some minor modifications to
@@ -92,12 +95,42 @@
self._base = a_bzrdir.transport.base
self._ignore_fallbacks = False
self.bzrdir = a_bzrdir
- foreign.ForeignBranch.__init__(self,
+ foreign.ForeignBranch.__init__(self,
DummyForeignVcsMapping(DummyForeignVcs()))
- branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
+ branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
*args, **kwargs)
+class DummyForeignCommitBuilder(repository.RootCommitBuilder):
+
+ def _generate_revision_if_needed(self):
+ mapping = DummyForeignVcsMapping(DummyForeignVcs())
+ if self._lossy:
+ self._new_revision_id = mapping.revision_id_foreign_to_bzr(
+ (str(self._timestamp), str(self._timezone), "UNKNOWN"))
+ self.random_revid = False
+ else:
+ self._new_revision_id = self._gen_revision_id()
+ self.random_revid = True
+
+
+class DummyForeignVcsRepository(groupcompress_repo.CHKInventoryRepository,
+ foreign.ForeignRepository):
+ """Dummy foreign vcs repository."""
+
+
+class DummyForeignVcsRepositoryFormat(groupcompress_repo.RepositoryFormat2a):
+
+ repository_class = DummyForeignVcsRepository
+ _commit_builder_class = DummyForeignCommitBuilder
+
+ def get_format_string(self):
+ return "Dummy Foreign Vcs Repository"
+
+ def get_format_description(self):
+ return "Dummy Foreign Vcs Repository"
+
+
class InterToDummyVcsBranch(branch.GenericInterBranch,
foreign.InterToForeignBranch):
@@ -208,6 +241,10 @@
def get_branch_format(self):
return DummyForeignVcsBranchFormat()
+ @property
+ def repository_format(self):
+ return DummyForeignVcsRepositoryFormat()
+
def initialize_on_transport(self, transport):
"""Initialize a new bzrdir in the base directory of a Transport."""
# Since we don't have a .bzr directory, inherit the
@@ -240,6 +277,11 @@
self._control_files = lockable_files.LockableFiles(self.transport,
"lock", lockable_files.TransportLock)
+ def create_workingtree(self):
+ # dirstate requires a ".bzr" entry to exist
+ self.root_transport.put_bytes(".bzr", "foo")
+ return super(DummyForeignVcsDir, self).create_workingtree()
+
def open_branch(self, name=None, unsupported=False, ignore_fallbacks=True):
if name is not None:
raise errors.NoColocatedBranchSupport(self)
@@ -265,6 +307,9 @@
controldir.ControlDirFormat.register_prober(DummyForeignProber)
testcase.addCleanup(controldir.ControlDirFormat.unregister_prober,
DummyForeignProber)
+ repository.format_registry.register(DummyForeignVcsRepositoryFormat())
+ testcase.addCleanup(repository.format_registry.remove,
+ DummyForeignVcsRepositoryFormat())
# We need to register the optimiser to make the dummy appears really
# different from a regular bzr repository.
branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
@@ -303,8 +348,9 @@
reg = foreign.ForeignVcsRegistry()
vcs = DummyForeignVcs()
reg.register("dummy", vcs, "Dummy VCS")
- self.assertEquals((("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
- reg.parse_revision_id("dummy-v1:some-foreign-revid"))
+ self.assertEquals((
+ ("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
+ reg.parse_revision_id("dummy-v1:some-foreign-revid"))
class ForeignRevisionTests(tests.TestCase):
=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- a/doc/en/release-notes/bzr-2.4.txt 2011-04-16 10:11:51 +0000
+++ b/doc/en/release-notes/bzr-2.4.txt 2011-04-16 14:16:50 +0000
@@ -20,6 +20,10 @@
.. New commands, options, etc that users may wish to try out.
+* ``bzr commit`` now supports a ``--lossy`` argument that can be used
+ to discard any data that can not be natively represented when committing
+ to a foreign VCS. (Jelmer Vernooij, #587721)
+
Improvements
************
More information about the bazaar-commits
mailing list