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

Function compute_working_copy_diff

libatomic/src/daemon/services_query.rs:65–186  ·  view source on GitHub ↗

Compute the working-copy diff chunks: recorded graph content (via `get_file_content_on_view`) against the on-disk bytes, unified-diffed with `similar` — the same comparison the CLI's local path performs.

(
    handle: &super::state::RepoHandle,
    paths: &[String],
    include_untracked: bool,
    stat_only: bool,
)

Source from the content-addressed store, hash-verified

63/// `get_file_content_on_view`) against the on-disk bytes, unified-diffed
64/// with `similar` — the same comparison the CLI's local path performs.
65fn compute_working_copy_diff(
66 handle: &super::state::RepoHandle,
67 paths: &[String],
68 include_untracked: bool,
69 stat_only: bool,
70) -> Result<Vec<DiffChunk>, Status> {
71 // Observation-only service read, after any CLI Git reconciliation.
72 let (repo, workspace) =
73 handle.workspace_repository(atomic_repository::WorkspaceTxnMode::Observe)?;
74 let working_copy = workspace.working_copy();
75 let view = workspace.view().name.clone();
76 let status = repo
77 .status(working_copy, StatusOptions::default())
78 .map_err(repository_error)?;
79
80 let mut targets: Vec<(std::path::PathBuf, DomainFileStatus)> = Vec::new();
81 for entry in status.entries() {
82 let entry_status = entry.status();
83 let wanted = match entry_status {
84 DomainFileStatus::Modified
85 | DomainFileStatus::Added
86 | DomainFileStatus::Deleted
87 | DomainFileStatus::PendingUntrack
88 | DomainFileStatus::TypeChanged
89 | DomainFileStatus::PermissionsChanged => true,
90 DomainFileStatus::Untracked => include_untracked,
91 _ => false,
92 };
93 if !wanted {
94 continue;
95 }
96 if !paths.is_empty() && !paths.iter().any(|p| entry.path().starts_with(p)) {
97 continue;
98 }
99 targets.push((entry.path().to_path_buf(), entry_status));
100 }
101
102 let mut chunks = Vec::new();
103 for (path, file_status) in targets {
104 let path_str = path.display().to_string();
105 let old_content: Vec<u8> = match file_status {
106 DomainFileStatus::Added | DomainFileStatus::Untracked => Vec::new(),
107 _ => repo
108 .get_file_content_on_view(&path, &view)
109 .map_err(repository_error)?
110 .unwrap_or_default(),
111 };
112 let new_content: Option<Vec<u8>> = match file_status {
113 DomainFileStatus::Deleted => None,
114 _ => Some(
115 working_copy_diff_bytes(&handle.root.join(&path)).map_err(|error| {
116 domain_status(
117 ErrorCode::Repository,
118 format!("cannot read {}: {error}", path.display()),
119 )
120 })?,
121 ),
122 };

Callers 1

diff_working_copy_implFunction · 0.85

Calls 15

working_copy_diff_bytesFunction · 0.85
domain_statusFunction · 0.85
diff_status_stringFunction · 0.85
workspace_repositoryMethod · 0.80
entriesMethod · 0.80
displayMethod · 0.80
as_refMethod · 0.80
working_copyMethod · 0.45
cloneMethod · 0.45
viewMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected