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

Function collect_git_tree

atomic-cli/src/commands/git/shim.rs:3257–3311  ·  view source on GitHub ↗
(
    git: &GitRepository,
    tree: &git2::Tree<'_>,
    prefix: &str,
    files: &mut BTreeMap<String, Vec<u8>>,
)

Source from the content-addressed store, hash-verified

3255}
3256
3257fn collect_git_tree(
3258 git: &GitRepository,
3259 tree: &git2::Tree<'_>,
3260 prefix: &str,
3261 files: &mut BTreeMap<String, Vec<u8>>,
3262) -> CliResult<()> {
3263 for entry in tree.iter() {
3264 let name = entry
3265 .name()
3266 .map_err(|error| git_error(format!("Git tree contains a non-UTF-8 path: {error}")))?;
3267 let path = if prefix.is_empty() {
3268 name.to_string()
3269 } else {
3270 format!("{prefix}/{name}")
3271 };
3272 if excluded_path(&path) {
3273 continue;
3274 }
3275
3276 match (entry.kind(), entry.filemode()) {
3277 (Some(ObjectType::Tree), 0o040000) => {
3278 let child = git.find_tree(entry.id()).map_err(|error| {
3279 git_error(format!("cannot read Git tree '{path}': {error}"))
3280 })?;
3281 collect_git_tree(git, &child, &path, files)?;
3282 }
3283 (Some(ObjectType::Blob), 0o100644 | 0o100755) => {
3284 let blob = git.find_blob(entry.id()).map_err(|error| {
3285 git_error(format!("cannot read Git blob '{path}': {error}"))
3286 })?;
3287 files.insert(path, blob.content().to_vec());
3288 }
3289 // A symlink is a path like any other for collision planning; its
3290 // blob holds the link target. The `.claude/skills/<name>` layout
3291 // made every switch refuse with "unsupported Git entry".
3292 (Some(ObjectType::Blob), 0o120000) => {
3293 let blob = git.find_blob(entry.id()).map_err(|error| {
3294 git_error(format!("cannot read Git symlink '{path}': {error}"))
3295 })?;
3296 files.insert(path, blob.content().to_vec());
3297 }
3298 // A gitlink occupies its path without content of its own.
3299 (Some(ObjectType::Commit), 0o160000) => {
3300 files.insert(path, Vec::new());
3301 }
3302 _ => {
3303 return Err(git_error(format!(
3304 "unsupported Git entry '{path}' with mode {:o}",
3305 entry.filemode()
3306 )));
3307 }
3308 }
3309 }
3310 Ok(())
3311}
3312
3313fn excluded_path(path: &str) -> bool {
3314 path == ".git"

Callers 1

read_git_treeFunction · 0.85

Calls 9

excluded_pathFunction · 0.85
git_errorFunction · 0.70
iterMethod · 0.45
nameMethod · 0.45
is_emptyMethod · 0.45
kindMethod · 0.45
idMethod · 0.45
insertMethod · 0.45
contentMethod · 0.45

Tested by

no test coverage detected