MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / commit_tree

Function commit_tree

atomic-repository/src/repository/project_tree.rs:1792–1836  ·  view source on GitHub ↗
(
            git: &git2::Repository,
            signature: &git2::Signature,
            paths: &[(&str, &[u8])],
        )

Source from the content-addressed store, hash-verified

1790 let signature = git2::Signature::now("policy", "policy@example.com").unwrap();
1791
1792 fn commit_tree(
1793 git: &git2::Repository,
1794 signature: &git2::Signature,
1795 paths: &[(&str, &[u8])],
1796 ) {
1797 fn build(git: &git2::Repository, files: &[(&str, &[u8])]) -> git2::Oid {
1798 let mut builder = git.treebuilder(None).unwrap();
1799 let mut directories = std::collections::BTreeMap::<&str, Vec<(&str, &[u8])>>::new();
1800 for &(path, bytes) in files {
1801 if let Some((directory, rest)) = path.split_once('/') {
1802 directories
1803 .entry(directory)
1804 .or_default()
1805 .push((rest, bytes));
1806 } else {
1807 builder
1808 .insert(path, git.blob(bytes).unwrap(), 0o100644)
1809 .unwrap();
1810 }
1811 }
1812 for (directory, children) in directories {
1813 builder
1814 .insert(directory, build(git, &children), 0o040000)
1815 .unwrap();
1816 }
1817 builder.write().unwrap()
1818 }
1819 let tree = git.find_tree(build(git, paths)).unwrap();
1820 let parents: Vec<_> = git
1821 .find_reference("refs/heads/main")
1822 .ok()
1823 .and_then(|reference| reference.peel_to_commit().ok())
1824 .into_iter()
1825 .collect();
1826 git.commit(
1827 Some("refs/heads/main"),
1828 signature,
1829 signature,
1830 "fixture",
1831 &tree,
1832 &parents.iter().collect::<Vec<_>>(),
1833 )
1834 .unwrap();
1835 git.set_head("refs/heads/main").unwrap();
1836 }
1837
1838 fn write_config(root: &Path, text: &str) {
1839 std::fs::create_dir_all(root.join(".atomic")).unwrap();

Calls 7

buildFunction · 0.70
unwrapMethod · 0.45
collectMethod · 0.45
into_iterMethod · 0.45
okMethod · 0.45
commitMethod · 0.45
iterMethod · 0.45