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

Function observe_index

atomic-cli/src/commands/git/observation.rs:877–927  ·  view source on GitHub ↗
(
    repository: &GitRepository,
    index: &git2::Index,
    index_path: &Path,
    head_tree_oid: Option<Oid>,
    head_tree_entries: &[TreeEntryObservation],
)

Source from the content-addressed store, hash-verified

875}
876
877fn observe_index(
878 repository: &GitRepository,
879 index: &git2::Index,
880 index_path: &Path,
881 head_tree_oid: Option<Oid>,
882 head_tree_entries: &[TreeEntryObservation],
883) -> Result<IndexObservation, ObservationError> {
884 let mut entries: Vec<_> = index
885 .iter()
886 .map(|entry| IndexEntryObservation {
887 stage: ((entry.flags >> 12) & 0x3) as u8,
888 path: entry.path,
889 oid: entry.id,
890 mode: entry.mode,
891 flags: entry.flags,
892 flags_extended: entry.flags_extended,
893 })
894 .collect();
895 entries.sort_by(|left, right| {
896 left.path
897 .cmp(&right.path)
898 .then_with(|| left.stage.cmp(&right.stage))
899 .then_with(|| left.oid.as_bytes().cmp(right.oid.as_bytes()))
900 });
901
902 let canonical_digest = digest_index(&entries);
903 let (tree_oid, tree_availability) = compute_index_tree_oid(repository, &entries)?;
904 let head_equivalence =
905 compare_index_to_head(&entries, tree_oid, head_tree_oid, head_tree_entries);
906 let exists = match fs::symlink_metadata(index_path) {
907 Ok(_) => true,
908 Err(error) if error.kind() == io::ErrorKind::NotFound => false,
909 Err(error) => {
910 return Err(ObservationError::new(format!(
911 "cannot inspect Git index path '{}': {error}",
912 index_path.display()
913 )));
914 }
915 };
916
917 Ok(IndexObservation {
918 path: index_path.to_path_buf(),
919 exists,
920 version: index.version(),
921 entries,
922 canonical_digest,
923 tree_oid,
924 tree_availability,
925 head_equivalence,
926 })
927}
928
929#[derive(Default)]
930struct InMemoryIndexTree {

Callers 1

observe_open_repositoryFunction · 0.85

Calls 9

digest_indexFunction · 0.85
compute_index_tree_oidFunction · 0.85
compare_index_to_headFunction · 0.85
versionMethod · 0.80
collectMethod · 0.45
iterMethod · 0.45
cmpMethod · 0.45
as_bytesMethod · 0.45
kindMethod · 0.45

Tested by

no test coverage detected