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

Function compute_ref_pair_diff

libatomic/src/daemon/services.rs:904–1025  ·  view source on GitHub ↗

The view-to-view diff: a pure read (read-only repository open) over each side's visible file set, unified-diffed with `similar` — the same hunk computation the working-copy diff performs.

(
    root: &std::path::Path,
    from_view: &str,
    to_view: &str,
    stat_only: bool,
)

Source from the content-addressed store, hash-verified

902/// each side's visible file set, unified-diffed with `similar` — the
903/// same hunk computation the working-copy diff performs.
904fn compute_ref_pair_diff(
905 root: &std::path::Path,
906 from_view: &str,
907 to_view: &str,
908 stat_only: bool,
909) -> Result<Vec<DiffChunk>, Status> {
910 let repo = Repository::open_readonly_wait(root, super::state::database_open_wait()).map_err(
911 |error| {
912 domain_status(
913 ErrorCode::Repository,
914 format!("failed to open repository read-only: {error}"),
915 )
916 },
917 )?;
918 for view in [from_view, to_view] {
919 if !repo.view_exists(view).map_err(repository_error)? {
920 return Err(domain_status(
921 ErrorCode::View,
922 format!("view '{view}' not found"),
923 ));
924 }
925 }
926 let from_files = repo
927 .visible_file_paths(from_view)
928 .map_err(repository_error)?;
929 let to_files = repo.visible_file_paths(to_view).map_err(repository_error)?;
930 // Symmetric difference (present on exactly one side) plus the common
931 // paths whose content actually differs.
932 let mut all_paths: Vec<String> = from_files
933 .symmetric_difference(&to_files)
934 .cloned()
935 .collect();
936 for path in from_files.intersection(&to_files) {
937 let differs = match (
938 repo.get_file_content_on_view(path, from_view),
939 repo.get_file_content_on_view(path, to_view),
940 ) {
941 (Ok(Some(a)), Ok(Some(b))) => a != b,
942 _ => true,
943 };
944 if differs {
945 all_paths.push(path.clone());
946 }
947 }
948 all_paths.sort();
949
950 let mut chunks = Vec::new();
951 for path in all_paths {
952 let in_from = from_files.contains(&path);
953 let in_to = to_files.contains(&path);
954 let status = match (in_from, in_to) {
955 (true, true) => "modified",
956 (false, true) => "added",
957 (true, false) => "deleted",
958 (false, false) => continue,
959 };
960 let old = repo
961 .get_file_content_on_view(&path, from_view)

Callers 1

diffMethod · 0.85

Calls 12

database_open_waitFunction · 0.85
domain_statusFunction · 0.85
view_existsMethod · 0.80
visible_file_pathsMethod · 0.80
sortMethod · 0.80
as_refMethod · 0.80
collectMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45
containsMethod · 0.45
tagMethod · 0.45

Tested by

no test coverage detected