|
@@ -44,6 +44,9 @@ from dulwich.tests.utils import (
|
|
|
make_object,
|
|
|
)
|
|
|
|
|
|
+# Shorthand mode for Files.
|
|
|
+F = 0100644
|
|
|
+
|
|
|
|
|
|
class DiffTestCase(TestCase):
|
|
|
|
|
@@ -54,7 +57,12 @@ class DiffTestCase(TestCase):
|
|
|
|
|
|
def commit_tree(self, blobs):
|
|
|
commit_blobs = []
|
|
|
- for path, blob, mode in blobs:
|
|
|
+ for entry in blobs:
|
|
|
+ if len(entry) == 2:
|
|
|
+ path, blob = entry
|
|
|
+ mode = F
|
|
|
+ else:
|
|
|
+ path, blob, mode = entry
|
|
|
self.store.add_object(blob)
|
|
|
commit_blobs.append((path, blob.id, mode))
|
|
|
return self.store[commit_tree(self.store, commit_blobs)]
|
|
@@ -111,15 +119,13 @@ class TreeChangesTest(DiffTestCase):
|
|
|
|
|
|
def test_tree_changes_no_changes(self):
|
|
|
blob = make_object(Blob, data='blob')
|
|
|
- tree = self.commit_tree([('a', blob, 0100644),
|
|
|
- ('b/c', blob, 0100644)])
|
|
|
+ tree = self.commit_tree([('a', blob), ('b/c', blob)])
|
|
|
self.assertChangesEqual([], self.empty_tree, self.empty_tree)
|
|
|
self.assertChangesEqual([], tree, tree)
|
|
|
self.assertChangesEqual(
|
|
|
- [TreeChange(CHANGE_UNCHANGED, ('a', 0100644, blob.id),
|
|
|
- ('a', 0100644, blob.id)),
|
|
|
- TreeChange(CHANGE_UNCHANGED, ('b/c', 0100644, blob.id),
|
|
|
- ('b/c', 0100644, blob.id))],
|
|
|
+ [TreeChange(CHANGE_UNCHANGED, ('a', F, blob.id), ('a', F, blob.id)),
|
|
|
+ TreeChange(CHANGE_UNCHANGED, ('b/c', F, blob.id),
|
|
|
+ ('b/c', F, blob.id))],
|
|
|
tree, tree, want_unchanged=True)
|
|
|
|
|
|
def test_tree_changes_add_delete(self):
|
|
@@ -139,11 +145,11 @@ class TreeChangesTest(DiffTestCase):
|
|
|
def test_tree_changes_modify_contents(self):
|
|
|
blob_a1 = make_object(Blob, data='a1')
|
|
|
blob_a2 = make_object(Blob, data='a2')
|
|
|
- tree1 = self.commit_tree([('a', blob_a1, 0100644)])
|
|
|
- tree2 = self.commit_tree([('a', blob_a2, 0100644)])
|
|
|
+ tree1 = self.commit_tree([('a', blob_a1)])
|
|
|
+ tree2 = self.commit_tree([('a', blob_a2)])
|
|
|
self.assertChangesEqual(
|
|
|
- [TreeChange(CHANGE_MODIFY, ('a', 0100644, blob_a1.id),
|
|
|
- ('a', 0100644, blob_a2.id))], tree1, tree2)
|
|
|
+ [TreeChange(CHANGE_MODIFY, ('a', F, blob_a1.id),
|
|
|
+ ('a', F, blob_a2.id))], tree1, tree2)
|
|
|
|
|
|
def test_tree_changes_modify_mode(self):
|
|
|
blob_a = make_object(Blob, data='a')
|
|
@@ -166,11 +172,11 @@ class TreeChangesTest(DiffTestCase):
|
|
|
def test_tree_changes_to_tree(self):
|
|
|
blob_a = make_object(Blob, data='a')
|
|
|
blob_x = make_object(Blob, data='x')
|
|
|
- tree1 = self.commit_tree([('a', blob_a, 0100644)])
|
|
|
- tree2 = self.commit_tree([('a/x', blob_x, 0100644)])
|
|
|
+ tree1 = self.commit_tree([('a', blob_a)])
|
|
|
+ tree2 = self.commit_tree([('a/x', blob_x)])
|
|
|
self.assertChangesEqual(
|
|
|
- [TreeChange.delete(('a', 0100644, blob_a.id)),
|
|
|
- TreeChange.add(('a/x', 0100644, blob_x.id))],
|
|
|
+ [TreeChange.delete(('a', F, blob_a.id)),
|
|
|
+ TreeChange.add(('a/x', F, blob_x.id))],
|
|
|
tree1, tree2)
|
|
|
|
|
|
def test_tree_changes_complex(self):
|
|
@@ -180,11 +186,11 @@ class TreeChangesTest(DiffTestCase):
|
|
|
blob_by1_1 = make_object(Blob, data='by1_1')
|
|
|
blob_by2_1 = make_object(Blob, data='by2_1')
|
|
|
tree1 = self.commit_tree([
|
|
|
- ('a', blob_a_1, 0100644),
|
|
|
- ('b/x/1', blob_bx1_1, 0100644),
|
|
|
- ('b/x/2', blob_bx2_1, 0100644),
|
|
|
- ('b/y/1', blob_by1_1, 0100644),
|
|
|
- ('b/y/2', blob_by2_1, 0100644),
|
|
|
+ ('a', blob_a_1),
|
|
|
+ ('b/x/1', blob_bx1_1),
|
|
|
+ ('b/x/2', blob_bx2_1),
|
|
|
+ ('b/y/1', blob_by1_1),
|
|
|
+ ('b/y/2', blob_by2_1),
|
|
|
])
|
|
|
|
|
|
blob_a_2 = make_object(Blob, data='a1_2')
|
|
@@ -192,52 +198,42 @@ class TreeChangesTest(DiffTestCase):
|
|
|
blob_by_2 = make_object(Blob, data='by_2')
|
|
|
blob_c_2 = make_object(Blob, data='c_2')
|
|
|
tree2 = self.commit_tree([
|
|
|
- ('a', blob_a_2, 0100644),
|
|
|
- ('b/x/1', blob_bx1_2, 0100644),
|
|
|
- ('b/y', blob_by_2, 0100644),
|
|
|
- ('c', blob_c_2, 0100644),
|
|
|
+ ('a', blob_a_2),
|
|
|
+ ('b/x/1', blob_bx1_2),
|
|
|
+ ('b/y', blob_by_2),
|
|
|
+ ('c', blob_c_2),
|
|
|
])
|
|
|
|
|
|
self.assertChangesEqual(
|
|
|
- [TreeChange(CHANGE_MODIFY, ('a', 0100644, blob_a_1.id),
|
|
|
- ('a', 0100644, blob_a_2.id)),
|
|
|
- TreeChange.delete(('b/x/2', 0100644, blob_bx2_1.id)),
|
|
|
- TreeChange.add(('b/y', 0100644, blob_by_2.id)),
|
|
|
- TreeChange.delete(('b/y/1', 0100644, blob_by1_1.id)),
|
|
|
- TreeChange.delete(('b/y/2', 0100644, blob_by2_1.id)),
|
|
|
- TreeChange.add(('c', 0100644, blob_c_2.id))],
|
|
|
+ [TreeChange(CHANGE_MODIFY, ('a', F, blob_a_1.id),
|
|
|
+ ('a', F, blob_a_2.id)),
|
|
|
+ TreeChange.delete(('b/x/2', F, blob_bx2_1.id)),
|
|
|
+ TreeChange.add(('b/y', F, blob_by_2.id)),
|
|
|
+ TreeChange.delete(('b/y/1', F, blob_by1_1.id)),
|
|
|
+ TreeChange.delete(('b/y/2', F, blob_by2_1.id)),
|
|
|
+ TreeChange.add(('c', F, blob_c_2.id))],
|
|
|
tree1, tree2)
|
|
|
|
|
|
def test_tree_changes_name_order(self):
|
|
|
blob = make_object(Blob, data='a')
|
|
|
- tree1 = self.commit_tree([
|
|
|
- ('a', blob, 0100644),
|
|
|
- ('a.', blob, 0100644),
|
|
|
- ('a..', blob, 0100644),
|
|
|
- ])
|
|
|
+ tree1 = self.commit_tree([('a', blob), ('a.', blob), ('a..', blob)])
|
|
|
# Tree order is the reverse of this, so if we used tree order, 'a..'
|
|
|
# would not be merged.
|
|
|
- tree2 = self.commit_tree([
|
|
|
- ('a/x', blob, 0100644),
|
|
|
- ('a./x', blob, 0100644),
|
|
|
- ('a..', blob, 0100644),
|
|
|
- ])
|
|
|
+ tree2 = self.commit_tree([('a/x', blob), ('a./x', blob), ('a..', blob)])
|
|
|
|
|
|
self.assertChangesEqual(
|
|
|
- [TreeChange.delete(('a', 0100644, blob.id)),
|
|
|
- TreeChange.add(('a/x', 0100644, blob.id)),
|
|
|
- TreeChange.delete(('a.', 0100644, blob.id)),
|
|
|
- TreeChange.add(('a./x', 0100644, blob.id))],
|
|
|
+ [TreeChange.delete(('a', F, blob.id)),
|
|
|
+ TreeChange.add(('a/x', F, blob.id)),
|
|
|
+ TreeChange.delete(('a.', F, blob.id)),
|
|
|
+ TreeChange.add(('a./x', F, blob.id))],
|
|
|
tree1, tree2)
|
|
|
|
|
|
def test_tree_changes_prune(self):
|
|
|
blob_a1 = make_object(Blob, data='a1')
|
|
|
blob_a2 = make_object(Blob, data='a2')
|
|
|
blob_x = make_object(Blob, data='x')
|
|
|
- tree1 = self.commit_tree([('a', blob_a1, 0100644),
|
|
|
- ('b/x', blob_x, 0100644)])
|
|
|
- tree2 = self.commit_tree([('a', blob_a2, 0100644),
|
|
|
- ('b/x', blob_x, 0100644)])
|
|
|
+ tree1 = self.commit_tree([('a', blob_a1), ('b/x', blob_x)])
|
|
|
+ tree2 = self.commit_tree([('a', blob_a2), ('b/x', blob_x)])
|
|
|
# Remove identical items so lookups will fail unless we prune.
|
|
|
subtree = self.store[tree1['b'][1]]
|
|
|
for entry in subtree.iteritems():
|
|
@@ -245,8 +241,8 @@ class TreeChangesTest(DiffTestCase):
|
|
|
del self.store[subtree.id]
|
|
|
|
|
|
self.assertChangesEqual(
|
|
|
- [TreeChange(CHANGE_MODIFY, ('a', 0100644, blob_a1.id),
|
|
|
- ('a', 0100644, blob_a2.id))],
|
|
|
+ [TreeChange(CHANGE_MODIFY, ('a', F, blob_a1.id),
|
|
|
+ ('a', F, blob_a2.id))],
|
|
|
tree1, tree2)
|
|
|
|
|
|
|