Commit 875bfc5ffcdd21fca616d4f88444d4dcf6fd69ac

Russell Belfer 2012-03-25T21:26:48

Fix error in tree iterator when popping up trees There was an error in the tree iterator where it would delete two tree levels instead of just one when popping up a tree level. Unfortunately the test data for the tree iterator did not have any deep trees with subtrees in the middle of the tree items, so this problem went unnoticed. This contains the 1-line fix plus new test data and tests that reveal the issue.

diff --git a/src/iterator.c b/src/iterator.c
index 001bee7..aa73d31 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -121,7 +121,6 @@ static int tree_iterator__advance(
 			break;
 
 		tree_iterator__pop_frame(ti);
-		git_buf_rtruncate_at_char(&ti->path, '/');
 	}
 
 	if (te && entry_is_tree(te))
diff --git a/tests-clar/diff/iterator.c b/tests-clar/diff/iterator.c
index 3953fd8..60f416f 100644
--- a/tests-clar/diff/iterator.c
+++ b/tests-clar/diff/iterator.c
@@ -139,6 +139,40 @@ void test_diff_iterator__tree_3(void)
 	tree_iterator_test("status", "0017bd4ab1e", 8, expected_tree_3);
 }
 
+/* $ git ls-tree -r --name-only 24fa9a9fc4e202313e24b648087495441dab432b */
+const char *expected_tree_4[] = {
+	"attr0",
+	"attr1",
+	"attr2",
+	"attr3",
+	"binfile",
+	"gitattributes",
+	"macro_bad",
+	"macro_test",
+	"root_test1",
+	"root_test2",
+	"root_test3",
+	"root_test4.txt",
+	"sub/abc",
+	"sub/file",
+	"sub/sub/file",
+	"sub/sub/subsub.txt",
+	"sub/subdir_test1",
+	"sub/subdir_test2.txt",
+	"subdir/.gitattributes",
+	"subdir/abc",
+	"subdir/subdir_test1",
+	"subdir/subdir_test2.txt",
+	"subdir2/subdir2_test1",
+	NULL
+};
+
+void test_diff_iterator__tree_4(void)
+{
+	tree_iterator_test(
+		"attr", "24fa9a9fc4e202313e24b648087495441dab432b",
+		23, expected_tree_4);
+}
 
 /* -- INDEX ITERATOR TESTS -- */
 
@@ -188,6 +222,12 @@ static const char *expected_index_0[] = {
 	"root_test2",
 	"root_test3",
 	"root_test4.txt",
+	"sub/abc",
+	"sub/file",
+	"sub/sub/file",
+	"sub/sub/subsub.txt",
+	"sub/subdir_test1",
+	"sub/subdir_test2.txt",
 	"subdir/.gitattributes",
 	"subdir/abc",
 	"subdir/subdir_test1",
@@ -208,6 +248,12 @@ static const char *expected_index_oids_0[] = {
 	"4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
 	"108bb4e7fd7b16490dc33ff7d972151e73d7166e",
 	"fe773770c5a6cc7185580c9204b1ff18a33ff3fc",
+	"3e42ffc54a663f9401cc25843d6c0e71a33e4249",
+	"45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
+	"45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
+	"9e5bdc47d6a80f2be0ea3049ad74231b94609242",
+	"e563cf4758f0d646f1b14b76016aa17fa9e549a4",
+	"fb5067b1aef3ac1ada4b379dbcb7d17255df7d78",
 	"99eae476896f4907224978b88e5ecaa6c5bb67a9",
 	"3e42ffc54a663f9401cc25843d6c0e71a33e4249",
 	"e563cf4758f0d646f1b14b76016aa17fa9e549a4",
@@ -217,7 +263,7 @@ static const char *expected_index_oids_0[] = {
 
 void test_diff_iterator__index_0(void)
 {
-	index_iterator_test("attr", 17, expected_index_0, expected_index_oids_0);
+	index_iterator_test("attr", 23, expected_index_0, expected_index_oids_0);
 }
 
 static const char *expected_index_1[] = {
diff --git a/tests/resources/attr/.gitted/index b/tests/resources/attr/.gitted/index
index 19fa99d..1d60eab 100644
Binary files a/tests/resources/attr/.gitted/index and b/tests/resources/attr/.gitted/index differ
diff --git a/tests/resources/attr/.gitted/logs/HEAD b/tests/resources/attr/.gitted/logs/HEAD
index 68fcff2..73f00f3 100644
--- a/tests/resources/attr/.gitted/logs/HEAD
+++ b/tests/resources/attr/.gitted/logs/HEAD
@@ -4,3 +4,5 @@
 a5d76cad53f66f1312bd995909a5bab3c0820770 370fe9ec224ce33e71f9e5ec2bd1142ce9937a6a Russell Belfer <arrbee@arrbee.com> 1327611749 -0800	commit: Updating files so we can do diffs
 370fe9ec224ce33e71f9e5ec2bd1142ce9937a6a f5b0af1fb4f5c0cd7aad880711d368a07333c307 Russell Belfer <arrbee@arrbee.com> 1327621027 -0800	commit: Updating test data
 f5b0af1fb4f5c0cd7aad880711d368a07333c307 a97cc019851d401a4f1d091cb91a15890a0dd1ba Russell Belfer <arrbee@arrbee.com> 1328653313 -0800	commit: Some whitespace only changes for testing purposes
+a97cc019851d401a4f1d091cb91a15890a0dd1ba 217878ab49e1314388ea2e32dc6fdb58a1b969e0 Russell Belfer <arrbee@arrbee.com> 1332734901 -0700	commit: added files in sub/sub
+217878ab49e1314388ea2e32dc6fdb58a1b969e0 24fa9a9fc4e202313e24b648087495441dab432b Russell Belfer <arrbee@arrbee.com> 1332735555 -0700	commit: adding more files in sub for tree status
diff --git a/tests/resources/attr/.gitted/logs/refs/heads/master b/tests/resources/attr/.gitted/logs/refs/heads/master
index 68fcff2..73f00f3 100644
--- a/tests/resources/attr/.gitted/logs/refs/heads/master
+++ b/tests/resources/attr/.gitted/logs/refs/heads/master
@@ -4,3 +4,5 @@
 a5d76cad53f66f1312bd995909a5bab3c0820770 370fe9ec224ce33e71f9e5ec2bd1142ce9937a6a Russell Belfer <arrbee@arrbee.com> 1327611749 -0800	commit: Updating files so we can do diffs
 370fe9ec224ce33e71f9e5ec2bd1142ce9937a6a f5b0af1fb4f5c0cd7aad880711d368a07333c307 Russell Belfer <arrbee@arrbee.com> 1327621027 -0800	commit: Updating test data
 f5b0af1fb4f5c0cd7aad880711d368a07333c307 a97cc019851d401a4f1d091cb91a15890a0dd1ba Russell Belfer <arrbee@arrbee.com> 1328653313 -0800	commit: Some whitespace only changes for testing purposes
+a97cc019851d401a4f1d091cb91a15890a0dd1ba 217878ab49e1314388ea2e32dc6fdb58a1b969e0 Russell Belfer <arrbee@arrbee.com> 1332734901 -0700	commit: added files in sub/sub
+217878ab49e1314388ea2e32dc6fdb58a1b969e0 24fa9a9fc4e202313e24b648087495441dab432b Russell Belfer <arrbee@arrbee.com> 1332735555 -0700	commit: adding more files in sub for tree status
diff --git a/tests/resources/attr/.gitted/objects/21/7878ab49e1314388ea2e32dc6fdb58a1b969e0 b/tests/resources/attr/.gitted/objects/21/7878ab49e1314388ea2e32dc6fdb58a1b969e0
new file mode 100644
index 0000000..b537899
--- /dev/null
+++ b/tests/resources/attr/.gitted/objects/21/7878ab49e1314388ea2e32dc6fdb58a1b969e0
@@ -0,0 +1,4 @@
+xQ
+0D)nD#xmvJ߀7cx0Iۺ
-+e"v☝pwcJH1x%HL>Dd
xC\ʤzᔶd0Z#mغڰ
+y
+>{qK
\ No newline at end of file
diff --git a/tests/resources/attr/.gitted/objects/24/fa9a9fc4e202313e24b648087495441dab432b b/tests/resources/attr/.gitted/objects/24/fa9a9fc4e202313e24b648087495441dab432b
new file mode 100644
index 0000000..e7099bb
Binary files /dev/null and b/tests/resources/attr/.gitted/objects/24/fa9a9fc4e202313e24b648087495441dab432b differ
diff --git a/tests/resources/attr/.gitted/objects/45/5a314fa848d52ae1f11d254da4f60858fc97f4 b/tests/resources/attr/.gitted/objects/45/5a314fa848d52ae1f11d254da4f60858fc97f4
new file mode 100644
index 0000000..f90f0d7
Binary files /dev/null and b/tests/resources/attr/.gitted/objects/45/5a314fa848d52ae1f11d254da4f60858fc97f4 differ
diff --git a/tests/resources/attr/.gitted/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 b/tests/resources/attr/.gitted/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057
new file mode 100644
index 0000000..7ca4cee
Binary files /dev/null and b/tests/resources/attr/.gitted/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 differ
diff --git a/tests/resources/attr/.gitted/objects/4e/49ba8c5b6c32ff28cd9dcb60be34df50fcc485 b/tests/resources/attr/.gitted/objects/4e/49ba8c5b6c32ff28cd9dcb60be34df50fcc485
new file mode 100644
index 0000000..6fcc549
Binary files /dev/null and b/tests/resources/attr/.gitted/objects/4e/49ba8c5b6c32ff28cd9dcb60be34df50fcc485 differ
diff --git a/tests/resources/attr/.gitted/objects/93/61f40bb97239cf55811892e14de2e344168ba1 b/tests/resources/attr/.gitted/objects/93/61f40bb97239cf55811892e14de2e344168ba1
new file mode 100644
index 0000000..4b57836
Binary files /dev/null and b/tests/resources/attr/.gitted/objects/93/61f40bb97239cf55811892e14de2e344168ba1 differ
diff --git a/tests/resources/attr/.gitted/objects/9e/5bdc47d6a80f2be0ea3049ad74231b94609242 b/tests/resources/attr/.gitted/objects/9e/5bdc47d6a80f2be0ea3049ad74231b94609242
new file mode 100644
index 0000000..d6385ec
Binary files /dev/null and b/tests/resources/attr/.gitted/objects/9e/5bdc47d6a80f2be0ea3049ad74231b94609242 differ
diff --git a/tests/resources/attr/.gitted/objects/ce/39a97a7fb1fa90bcf5e711249c1e507476ae0e b/tests/resources/attr/.gitted/objects/ce/39a97a7fb1fa90bcf5e711249c1e507476ae0e
new file mode 100644
index 0000000..1005f94
Binary files /dev/null and b/tests/resources/attr/.gitted/objects/ce/39a97a7fb1fa90bcf5e711249c1e507476ae0e differ
diff --git a/tests/resources/attr/.gitted/objects/ec/b97df2a174987475ac816e3847fc8e9f6c596b b/tests/resources/attr/.gitted/objects/ec/b97df2a174987475ac816e3847fc8e9f6c596b
new file mode 100644
index 0000000..44d703b
Binary files /dev/null and b/tests/resources/attr/.gitted/objects/ec/b97df2a174987475ac816e3847fc8e9f6c596b differ
diff --git a/tests/resources/attr/.gitted/refs/heads/master b/tests/resources/attr/.gitted/refs/heads/master
index 7f8bbe3..8768776 100644
--- a/tests/resources/attr/.gitted/refs/heads/master
+++ b/tests/resources/attr/.gitted/refs/heads/master
@@ -1 +1 @@
-a97cc019851d401a4f1d091cb91a15890a0dd1ba
+24fa9a9fc4e202313e24b648087495441dab432b