(
manifest: &RepositoryManifest,
algorithm: GitHashAlgorithm,
)
| 1025 | } |
| 1026 | |
| 1027 | fn build_git_tree( |
| 1028 | manifest: &RepositoryManifest, |
| 1029 | algorithm: GitHashAlgorithm, |
| 1030 | ) -> Result<GitTree, ProjectTreeError> { |
| 1031 | let mut root_node = DirectoryNode::default(); |
| 1032 | for entry in manifest.included_entries() { |
| 1033 | let components: Vec<_> = entry.path.components().collect(); |
| 1034 | let (name, parents) = components |
| 1035 | .split_last() |
| 1036 | .expect("validated path has a component"); |
| 1037 | let mut directory = &mut root_node; |
| 1038 | for parent in parents { |
| 1039 | if directory.files.contains_key(*parent) { |
| 1040 | return Err(ProjectTreeError::PathCollision(entry.path.clone())); |
| 1041 | } |
| 1042 | directory = directory.directories.entry(parent.to_vec()).or_default(); |
| 1043 | } |
| 1044 | if directory.directories.contains_key(*name) |
| 1045 | || directory |
| 1046 | .files |
| 1047 | .insert(name.to_vec(), entry.clone()) |
| 1048 | .is_some() |
| 1049 | { |
| 1050 | return Err(ProjectTreeError::PathCollision(entry.path.clone())); |
| 1051 | } |
| 1052 | } |
| 1053 | let mut objects = GitObjectDatabase::default(); |
| 1054 | let root = write_directory(&root_node, algorithm, &mut objects)?; |
| 1055 | Ok(GitTree { |
| 1056 | algorithm, |
| 1057 | root, |
| 1058 | objects, |
| 1059 | }) |
| 1060 | } |
| 1061 | |
| 1062 | fn write_directory( |
| 1063 | directory: &DirectoryNode, |
no test coverage detected