120
def test_commit_lossy(self):
121
tree = self.make_branch_and_tree(".")
124
builder = tree.branch.get_commit_builder([], lossy=True)
125
list(builder.record_iter_changes(tree, tree.last_revision(),
126
tree.iter_changes(tree.basis_tree())))
127
builder.finish_inventory()
128
rev_id = builder.commit('foo bar blah')
131
rev = tree.branch.repository.get_revision(rev_id)
132
self.assertEqual('foo bar blah', rev.message)
115
134
def test_commit_message(self):
116
135
tree = self.make_branch_and_tree(".")
117
136
tree.lock_write()
119
138
builder = tree.branch.get_commit_builder([])
120
self.record_root(builder, tree)
139
list(builder.record_iter_changes(tree, tree.last_revision(),
140
tree.iter_changes(tree.basis_tree())))
121
141
builder.finish_inventory()
122
142
rev_id = builder.commit('foo bar blah')
274
303
# pointless commit.
275
304
self.assertFalse(builder.any_changes())
276
305
builder.finish_inventory()
277
new_root = tree.branch.repository.get_inventory(
278
builder._new_revision_id).root
306
builder_tree = builder.revision_tree()
307
new_root_id = builder_tree.get_root_id()
308
new_root_revision = builder_tree.get_file_revision(new_root_id)
279
309
if tree.branch.repository.supports_rich_root():
280
310
# We should not have seen a new root revision
281
self.assertEqual(old_revision_id, new_root.revision)
311
self.assertEqual(old_revision_id, new_root_revision)
283
313
# We should see a new root revision
284
self.assertNotEqual(old_revision_id, new_root.revision)
314
self.assertNotEqual(old_revision_id, new_root_revision)
289
def test_commit(self):
319
def test_commit_record_entry_contents(self):
290
320
tree = self.make_branch_and_tree(".")
291
321
tree.lock_write()
293
323
builder = tree.branch.get_commit_builder([])
324
if not builder.supports_record_entry_contents:
325
raise tests.TestNotApplicable("CommitBuilder doesn't "
326
"support record_entry_contents")
294
327
self.record_root(builder, tree)
295
328
builder.finish_inventory()
296
329
rev_id = builder.commit('foo bar')
794
842
# record_entry_contents.
795
843
parent_ids = tree.get_parent_ids()
796
844
builder = tree.branch.get_commit_builder(parent_ids)
797
parent_tree = tree.basis_tree()
798
parent_tree.lock_read()
799
self.addCleanup(parent_tree.unlock)
800
parent_invs = [parent_tree.inventory]
801
for parent_id in parent_ids[1:]:
802
parent_invs.append(tree.branch.repository.revision_tree(
803
parent_id).inventory)
805
builder.record_entry_contents(
806
inventory.make_entry('directory', '', None,
807
tree.get_root_id()), parent_invs, '', tree,
808
tree.path_content_summary(''))
809
def commit_id(file_id):
810
old_ie = tree.inventory[file_id]
811
path = tree.id2path(file_id)
812
ie = inventory.make_entry(tree.kind(file_id), old_ie.name,
813
old_ie.parent_id, file_id)
814
content_summary = tree.path_content_summary(path)
815
if content_summary[0] == 'tree-reference':
816
content_summary = content_summary[:3] + (
817
tree.get_reference_revision(file_id),)
818
return builder.record_entry_contents(ie, parent_invs, path,
819
tree, content_summary)
846
if not builder.supports_record_entry_contents:
847
raise tests.TestNotApplicable("CommitBuilder doesn't "
848
"support record_entry_contents")
849
parent_tree = tree.basis_tree()
850
parent_tree.lock_read()
851
self.addCleanup(parent_tree.unlock)
852
parent_invs = [parent_tree.inventory]
853
for parent_id in parent_ids[1:]:
854
parent_invs.append(tree.branch.repository.revision_tree(
855
parent_id).inventory)
857
builder.record_entry_contents(
858
inventory.make_entry('directory', '', None,
859
tree.get_root_id()), parent_invs, '', tree,
860
tree.path_content_summary(''))
861
def commit_id(file_id):
862
old_ie = tree.inventory[file_id]
863
path = tree.id2path(file_id)
864
ie = inventory.make_entry(tree.kind(file_id), old_ie.name,
865
old_ie.parent_id, file_id)
866
content_summary = tree.path_content_summary(path)
867
if content_summary[0] == 'tree-reference':
868
content_summary = content_summary[:3] + (
869
tree.get_reference_revision(file_id),)
870
return builder.record_entry_contents(ie, parent_invs, path,
871
tree, content_summary)
821
file_id = tree.path2id(new_name)
822
parent_id = tree.inventory[file_id].parent_id
823
if parent_id != tree.get_root_id():
825
# because a change of some sort is meant to have occurred,
826
# recording the entry must return True.
827
delta, version_recorded, fs_hash = commit_id(file_id)
829
self.assertTrue(version_recorded)
831
self.assertFalse(version_recorded)
833
tree_file_stat = tree.get_file_with_stat(file_id)
834
tree_file_stat[0].close()
835
self.assertEqual(2, len(fs_hash))
836
self.assertEqual(tree.get_file_sha1(file_id), fs_hash[0])
837
self.assertEqualStat(tree_file_stat[1], fs_hash[1])
839
self.assertEqual(None, fs_hash)
840
new_entry = builder.new_inventory[file_id]
841
if delta_against_basis:
842
expected_delta = (name, new_name, file_id, new_entry)
843
# The delta should be recorded
844
self.assertEqual(expected_delta, builder._basis_delta[-1])
846
expected_delta = None
847
self.assertEqual(expected_delta, delta)
848
builder.finish_inventory()
849
rev2 = builder.commit('')
873
file_id = tree.path2id(new_name)
874
parent_id = tree.inventory[file_id].parent_id
875
if parent_id != tree.get_root_id():
877
# because a change of some sort is meant to have occurred,
878
# recording the entry must return True.
879
delta, version_recorded, fs_hash = commit_id(file_id)
881
self.assertTrue(version_recorded)
883
self.assertFalse(version_recorded)
885
tree_file_stat = tree.get_file_with_stat(file_id)
886
tree_file_stat[0].close()
887
self.assertEqual(2, len(fs_hash))
888
self.assertEqual(tree.get_file_sha1(file_id), fs_hash[0])
889
self.assertEqualStat(tree_file_stat[1], fs_hash[1])
891
self.assertEqual(None, fs_hash)
892
new_entry = builder.new_inventory[file_id]
893
if delta_against_basis:
894
expected_delta = (name, new_name, file_id, new_entry)
895
# The delta should be recorded
896
self.assertEqual(expected_delta, builder._basis_delta[-1])
898
expected_delta = None
899
self.assertEqual(expected_delta, delta)
900
builder.finish_inventory()
905
rev2 = builder.commit('')