(git: &GitRepository, files: &[(&str, &str)])
| 66 | |
| 67 | fn write_tree(git: &GitRepository, files: &[(&str, &str)]) -> git2::Oid { |
| 68 | fn build(git: &GitRepository, files: &[(&str, &str)]) -> git2::Oid { |
| 69 | let mut builder = git.treebuilder(None).unwrap(); |
| 70 | let mut children: BTreeMap<String, Vec<(&str, &str)>> = BTreeMap::new(); |
| 71 | for (path, content) in files { |
| 72 | if let Some((head, rest)) = path.split_once('/') { |
| 73 | children |
| 74 | .entry(head.to_string()) |
| 75 | .or_default() |
| 76 | .push((rest, content)); |
| 77 | } else { |
| 78 | builder |
| 79 | .insert(path, git.blob(content.as_bytes()).unwrap(), 0o100644) |
| 80 | .unwrap(); |
| 81 | } |
| 82 | } |
| 83 | for (name, nested) in children { |
| 84 | builder |
| 85 | .insert(&name, build(git, &nested), 0o040000) |
| 86 | .unwrap(); |
| 87 | } |
| 88 | builder.write().unwrap() |
| 89 | } |
| 90 | build(git, files) |
| 91 | } |
| 92 |
no test coverage detected