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

Function compute_ref_pair_diff

libatomic/src/daemon/services.rs:903–1024  ·  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

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