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

Function observe_worktree

atomic-repository/src/repository/git_observation.rs:475–608  ·  view source on GitHub ↗

Observe physical worktree state without following symlinks. Gitlink directories are retained as single explicit entries when identified by the index; their contents are never traversed.

(
    root: &Path,
    index: Option<&GitIndexState>,
    filter: &dyn ContentFilter,
    policy: &ConversionPolicy,
)

Source from the content-addressed store, hash-verified

473/// Gitlink directories are retained as single explicit entries when identified
474/// by the index; their contents are never traversed.
475pub fn observe_worktree(
476 root: &Path,
477 index: Option<&GitIndexState>,
478 filter: &dyn ContentFilter,
479 policy: &ConversionPolicy,
480) -> Result<WorktreeObservation, ObservationError> {
481 if !cfg!(unix) || !policy.platform.lossless_unix_paths {
482 return Err(ObservationError::UnsupportedPlatform);
483 }
484 let platform = detect_platform_capabilities(root, policy)?;
485 if platform != policy.platform {
486 return Err(ObservationError::PlatformMismatch {
487 expected: format!("{:?}", policy.platform),
488 observed: format!("{platform:?}"),
489 });
490 }
491 let stage_zero: BTreeMap<RepoPath, &GitIndexEntry> = index
492 .into_iter()
493 .flat_map(|state| state.entries.iter())
494 .filter(|entry| entry.stage == 0)
495 .map(|entry| (entry.path.clone(), entry))
496 .collect();
497 let gitlinks: BTreeSet<RepoPath> = stage_zero
498 .iter()
499 .filter(|(_, entry)| entry.mode == 0o160000)
500 .map(|(path, _)| path.clone())
501 .collect();
502 let mut entries = Vec::new();
503 let mut walker = WalkDir::new(root).follow_links(false).into_iter();
504 while let Some(next) = walker.next() {
505 let entry = next.map_err(|error| ObservationError::WorktreeIo {
506 path: error.path().unwrap_or(root).display().to_string(),
507 message: error.to_string(),
508 })?;
509 if entry.path() == root {
510 continue;
511 }
512 let relative =
513 entry
514 .path()
515 .strip_prefix(root)
516 .map_err(|error| ObservationError::WorktreeIo {
517 path: entry.path().display().to_string(),
518 message: error.to_string(),
519 })?;
520 let path = RepoPath::from_native(relative)
521 .map_err(|error| ObservationError::InvalidPath(error.to_string()))?;
522 let first = path.components().next().unwrap_or_default();
523 if first == b".git" || first == b".atomic" {
524 if entry.file_type().is_dir() {
525 walker.skip_current_dir();
526 }
527 continue;
528 }
529 let metadata =
530 fs::symlink_metadata(entry.path()).map_err(|error| ObservationError::WorktreeIo {
531 path: path.escaped(),
532 message: error.to_string(),

Calls 15

symlink_target_bytesFunction · 0.85
unix_modeFunction · 0.85
content_keyFunction · 0.85
displayMethod · 0.80
componentsMethod · 0.80
is_dirMethod · 0.80
escapedMethod · 0.80
exclusionMethod · 0.80
getMethod · 0.65
readFunction · 0.50
collectMethod · 0.45