Rev 4577: Fix a couple of small bugs in the patch - use specific files with record_iter_changs, and the CLI shouldn't generate a filter of [] for commit. in http://bazaar.launchpad.net/~lifeless/bzr/commit-specific-files
Robert Collins
robertc at robertcollins.net
Tue Aug 25 23:28:25 BST 2009
At http://bazaar.launchpad.net/~lifeless/bzr/commit-specific-files
------------------------------------------------------------
revno: 4577
revision-id: robertc at robertcollins.net-20090825222819-j2goi0fgiuu894xu
parent: robertc at robertcollins.net-20090825214312-1r0d24ahykhn3tx8
committer: Robert Collins <robertc at robertcollins.net>
branch nick: commit-specific-files
timestamp: Wed 2009-08-26 08:28:19 +1000
message:
Fix a couple of small bugs in the patch - use specific files with record_iter_changs, and the CLI shouldn't generate a filter of [] for commit.
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2009-08-24 22:32:53 +0000
+++ b/bzrlib/builtins.py 2009-08-25 22:28:19 +0000
@@ -3029,6 +3029,10 @@
raise errors.BzrCommandError("empty commit message specified")
return my_message
+ # The API permits a commit with a filter of [] to mean 'select nothing'
+ # but the command line should not do that.
+ if not selected_list:
+ selected_list = None
try:
tree.commit(message_callback=get_message,
specific_files=selected_list,
=== modified file 'bzrlib/commit.py'
--- a/bzrlib/commit.py 2009-07-29 06:23:58 +0000
+++ b/bzrlib/commit.py 2009-08-25 22:28:19 +0000
@@ -209,7 +209,8 @@
:param timestamp: if not None, seconds-since-epoch for a
postdated/predated commit.
- :param specific_files: If true, commit only those files.
+ :param specific_files: If not None, commit only those files. An empty
+ list means 'commit no files'.
:param rev_id: If set, use this as the new revision id.
Useful for test or import commands that need to tightly
@@ -264,6 +265,8 @@
self.master_locked = False
self.recursive = recursive
self.rev_id = None
+ # self.specific_files is None to indicate no filter, or any iterable to
+ # indicate a filter - [] means no files at all, as per iter_changes.
if specific_files is not None:
self.specific_files = sorted(
minimum_path_selection(specific_files))
@@ -332,7 +335,7 @@
self._gather_parents()
# After a merge, a selected file commit is not supported.
# See 'bzr help merge' for an explanation as to why.
- if len(self.parents) > 1 and self.specific_files:
+ if len(self.parents) > 1 and self.specific_files is not None:
raise errors.CannotCommitSelectedFileMerge(self.specific_files)
# Excludes are a form of selected file commit.
if len(self.parents) > 1 and self.exclude:
@@ -618,12 +621,13 @@
"""Update the commit builder with the data about what has changed.
"""
exclude = self.exclude
- specific_files = self.specific_files or []
+ specific_files = self.specific_files
mutter("Selecting files for commit with filter %s", specific_files)
self._check_strict()
if self.use_record_iter_changes:
- iter_changes = self.work_tree.iter_changes(self.basis_tree)
+ iter_changes = self.work_tree.iter_changes(self.basis_tree,
+ specific_files=specific_files)
iter_changes = self._filter_iter_changes(iter_changes)
for file_id, path, fs_hash in self.builder.record_iter_changes(
self.work_tree, self.basis_revid, iter_changes):
=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py 2009-08-21 00:04:55 +0000
+++ b/bzrlib/repository.py 2009-08-25 22:28:19 +0000
@@ -807,6 +807,9 @@
seen_root = True
self.new_inventory = None
if len(inv_delta):
+ # This should perhaps be guarded by a check that the basis we
+ # commit against is the basis for the commit and if not do a delta
+ # against the basis.
self._any_changes = True
if not seen_root:
# housekeeping root entry changes do not affect no-change commits.
=== modified file 'bzrlib/tests/blackbox/test_commit.py'
--- a/bzrlib/tests/blackbox/test_commit.py 2009-07-23 15:58:22 +0000
+++ b/bzrlib/tests/blackbox/test_commit.py 2009-08-25 22:28:19 +0000
@@ -273,13 +273,15 @@
self.build_tree_contents([
('branch/foo.c', 'int main() {}'),
('branch/bar.c', 'int main() {}')])
- inner_tree.add('foo.c')
- inner_tree.add('bar.c')
+ inner_tree.add(['foo.c', 'bar.c'])
# can't commit files in different trees; sane error
self.run_bzr('commit -m newstuff branch/foo.c .', retcode=3)
+ # can commit to branch - records foo.c only
self.run_bzr('commit -m newstuff branch/foo.c')
+ # can commit to branch - records bar.c
self.run_bzr('commit -m newstuff branch')
- self.run_bzr('commit -m newstuff branch', retcode=3)
+ # No changes left
+ self.run_bzr_error(["No changes to commit"], 'commit -m newstuff branch')
def test_out_of_date_tree_commit(self):
# check we get an error code and a clear message committing with an out
=== modified file 'bzrlib/tests/blackbox/test_versioning.py'
--- a/bzrlib/tests/blackbox/test_versioning.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/blackbox/test_versioning.py 2009-08-25 22:28:19 +0000
@@ -22,10 +22,10 @@
import os
-from bzrlib.tests import TestCaseInTempDir
from bzrlib.branch import Branch
+from bzrlib.osutils import pathjoin
+from bzrlib.tests import TestCaseInTempDir, TestCaseWithTransport
from bzrlib.trace import mutter
-from bzrlib.osutils import pathjoin
from bzrlib.workingtree import WorkingTree
@@ -122,60 +122,51 @@
check(b, False)
-class SubdirCommit(TestCaseInTempDir):
+class SubdirCommit(TestCaseWithTransport):
def test_subdir_commit(self):
- """Test committing a subdirectory, and committing within a directory."""
- run_bzr = self.run_bzr
- eq = self.assertEqual
-
+ """Test committing a subdirectory, and committing a directory."""
+ tree = self.make_branch_and_tree('.')
+ b = tree.branch
self.build_tree(['a/', 'b/'])
-
- run_bzr('init')
- b = Branch.open(u'.')
-
- for fn in ('a/one', 'b/two', 'top'):
- file(fn, 'w').write('old contents')
-
- run_bzr('add')
- run_bzr(['commit', '-m', 'first revision'])
-
- for fn in ('a/one', 'b/two', 'top'):
- file(fn, 'w').write('new contents')
+ def set_contents(contents):
+ self.build_tree_contents([
+ ('a/one', contents),
+ ('b/two', contents),
+ ('top', contents),
+ ])
+ set_contents('old contents')
+ tree.smart_add(['.'])
+ tree.commit('first revision')
+ set_contents('new contents')
mutter('start selective subdir commit')
- run_bzr(['commit', 'a', '-m', 'commit a only'])
+ self.run_bzr(['commit', 'a', '-m', 'commit a only'])
- old = b.repository.revision_tree(b.get_rev_id(1))
new = b.repository.revision_tree(b.get_rev_id(2))
new.lock_read()
- eq(new.get_file_by_path('b/two').read(), 'old contents')
- eq(new.get_file_by_path('top').read(), 'old contents')
- eq(new.get_file_by_path('a/one').read(), 'new contents')
+ self.assertEqual(new.get_file_by_path('b/two').read(), 'old contents')
+ self.assertEqual(new.get_file_by_path('top').read(), 'old contents')
+ self.assertEqual(new.get_file_by_path('a/one').read(), 'new contents')
new.unlock()
os.chdir('a')
# commit from here should do nothing
- run_bzr(['commit', '.', '-m', 'commit subdir only', '--unchanged'])
+ self.run_bzr(['commit', '.', '-m', 'commit subdir only', '--unchanged'])
v3 = b.repository.revision_tree(b.get_rev_id(3))
v3.lock_read()
- eq(v3.get_file_by_path('b/two').read(), 'old contents')
- eq(v3.get_file_by_path('top').read(), 'old contents')
- eq(v3.get_file_by_path('a/one').read(), 'new contents')
+ self.assertEqual(v3.get_file_by_path('b/two').read(), 'old contents')
+ self.assertEqual(v3.get_file_by_path('top').read(), 'old contents')
+ self.assertEqual(v3.get_file_by_path('a/one').read(), 'new contents')
v3.unlock()
# commit in subdirectory commits whole tree
- run_bzr(['commit', '-m', 'commit whole tree from subdir'])
+ self.run_bzr(['commit', '-m', 'commit whole tree from subdir'])
v4 = b.repository.revision_tree(b.get_rev_id(4))
v4.lock_read()
- eq(v4.get_file_by_path('b/two').read(), 'new contents')
- eq(v4.get_file_by_path('top').read(), 'new contents')
+ self.assertEqual(v4.get_file_by_path('b/two').read(), 'new contents')
+ self.assertEqual(v4.get_file_by_path('top').read(), 'new contents')
v4.unlock()
# TODO: factor out some kind of assert_tree_state() method
-
-
-if __name__ == '__main__':
- import unittest
- unittest.main()
More information about the bazaar-commits
mailing list