Commit f00db9ed67423b04976f8d20b0de2ee1fb7c3993

Carlos Martín Nieto 2018-07-27T12:00:37

tree: rename from_tree to validate and clarify the tree in the test

diff --git a/src/tree.c b/src/tree.c
index 96426c9..fd8e7b0 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -448,15 +448,15 @@ static int append_entry(
 	const char *filename,
 	const git_oid *id,
 	git_filemode_t filemode,
-	bool from_tree)
+	bool validate)
 {
 	git_tree_entry *entry;
 	int error = 0;
 
-	if (!from_tree && !valid_entry_name(bld->repo, filename))
+	if (validate && !valid_entry_name(bld->repo, filename))
 		return tree_error("failed to insert entry: invalid name for a tree entry", filename);
 
-	if (!from_tree && git_oid_iszero(id))
+	if (validate && git_oid_iszero(id))
 		return tree_error("failed to insert entry: invalid null OID for a tree entry", filename);
 
 	entry = alloc_entry(filename, strlen(filename), id);
@@ -554,12 +554,12 @@ static int write_tree(
 				last_comp = subdir;
 			}
 
-			error = append_entry(bld, last_comp, &sub_oid, S_IFDIR, false);
+			error = append_entry(bld, last_comp, &sub_oid, S_IFDIR, true);
 			git__free(subdir);
 			if (error < 0)
 				goto on_error;
 		} else {
-			error = append_entry(bld, filename, &entry->id, entry->mode, false);
+			error = append_entry(bld, filename, &entry->id, entry->mode, true);
 			if (error < 0)
 				goto on_error;
 		}
@@ -658,7 +658,7 @@ int git_treebuilder_new(
 				bld, entry_src->filename,
 				entry_src->oid,
 				entry_src->attr,
-				true) < 0)
+				false) < 0)
 				goto on_error;
 		}
 	}
diff --git a/tests/object/tree/update.c b/tests/object/tree/update.c
index 167faec..41b50f3 100644
--- a/tests/object/tree/update.c
+++ b/tests/object/tree/update.c
@@ -293,6 +293,7 @@ void test_object_tree_update__remove_invalid_submodule(void)
 		{GIT_TREE_UPDATE_REMOVE, {{0}}, GIT_FILEMODE_BLOB, "submodule"},
 	};
 
+	/* This tree contains a submodule with an all-zero commit for a submodule named 'submodule' */
 	cl_git_pass(git_oid_fromstr(&baseline_id, "396c7f1adb7925f51ba13a75f48252f44c5a14a2"));
 	cl_git_pass(git_tree_lookup(&baseline, g_repo, &baseline_id));
 	cl_git_pass(git_tree_create_updated(&updated_tree_id, g_repo, baseline, 1, updates));