(
manifest: &RepositoryManifest,
algorithm: GitHashAlgorithm,
)
| 1003 | } |
| 1004 | |
| 1005 | fn build_git_tree( |
| 1006 | manifest: &RepositoryManifest, |
| 1007 | algorithm: GitHashAlgorithm, |
| 1008 | ) -> Result<GitTree, ProjectTreeError> { |
| 1009 | let mut root_node = DirectoryNode::default(); |
| 1010 | for entry in manifest.included_entries() { |
| 1011 | let components: Vec<_> = entry.path.components().collect(); |
| 1012 | let (name, parents) = components |
| 1013 | .split_last() |
| 1014 | .expect("validated path has a component"); |
| 1015 | let mut directory = &mut root_node; |
| 1016 | for parent in parents { |
| 1017 | if directory.files.contains_key(*parent) { |
| 1018 | return Err(ProjectTreeError::PathCollision(entry.path.clone())); |
| 1019 | } |
| 1020 | directory = directory.directories.entry(parent.to_vec()).or_default(); |
| 1021 | } |
| 1022 | if directory.directories.contains_key(*name) |
| 1023 | || directory |
| 1024 | .files |
| 1025 | .insert(name.to_vec(), entry.clone()) |
| 1026 | .is_some() |
| 1027 | { |
| 1028 | return Err(ProjectTreeError::PathCollision(entry.path.clone())); |
| 1029 | } |
| 1030 | } |
| 1031 | let mut objects = GitObjectDatabase::default(); |
| 1032 | let root = write_directory(&root_node, algorithm, &mut objects)?; |
| 1033 | Ok(GitTree { |
| 1034 | algorithm, |
| 1035 | root, |
| 1036 | objects, |
| 1037 | }) |
| 1038 | } |
| 1039 | |
| 1040 | fn write_directory( |
| 1041 | directory: &DirectoryNode, |
no test coverage detected