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

Function working_copy_census_class

atomic-cli/src/commands/git/census.rs:148–225  ·  view source on GitHub ↗

Every working-copy record names an existing view; the CURRENT working copy's staleness is the durable layer's verdict, and other working copies' stale records are enumerated informationally (an owner reconciles them; they are not corruption).

(repo: &Repository, current_view: &str)

Source from the content-addressed store, hash-verified

146/// copies' stale records are enumerated informationally (an owner
147/// reconciles them; they are not corruption).
148fn working_copy_census_class(repo: &Repository, current_view: &str) -> CensusClass {
149 let name = "census/working-copies";
150 let class = (|| -> Result<CensusClass, String> {
151 let txn = repo.pristine().read_txn().map_err(|e| e.to_string())?;
152 let records = atomic_core::pristine::WorkingCopyTxnT::list_working_copies(&txn)
153 .map_err(|e| e.to_string())?;
154 let total = records.len();
155 let mut broken: Vec<String> = Vec::new();
156 let mut stale: Vec<String> = Vec::new();
157 for record in &records {
158 // Resolve the desired view id to its name for the report.
159 let view_state =
160 atomic_core::pristine::ViewTxnT::get_view_by_id(&txn, record.desired_view)
161 .map_err(|e| e.to_string())?;
162 let Some(view_state) = view_state else {
163 broken.push(format!(
164 "{} desires missing view id {}",
165 record.id.as_ulid(),
166 record.desired_view
167 ));
168 continue;
169 };
170 if view_state.state != record.desired_state {
171 if view_state.name == current_view {
172 // The current working copy's staleness is the durable
173 // layer's failure; the census does not double-report it.
174 continue;
175 }
176 stale.push(format!(
177 "{} desires '{}' at {} (view is at {})",
178 record.id.as_ulid(),
179 view_state.name,
180 &record.desired_state.to_base32()[..12],
181 &view_state.state.to_base32()[..12]
182 ));
183 }
184 }
185 let _ = repo;
186 if broken.is_empty() {
187 if stale.is_empty() {
188 Ok(CensusClass {
189 name,
190 clean: true,
191 detail: format!("{total} working-copy record(s) consistent"),
192 })
193 } else {
194 Ok(CensusClass {
195 name,
196 clean: true,
197 detail: format!(
198 "{total} working-copy record(s) consistent; {} stale OTHER record(s) \
199 (informational, owner-reconciled): {}",
200 stale.len(),
201 stale.join("; ")
202 ),
203 })
204 }
205 } else {

Callers

nothing calls this directly

Calls 5

read_txnMethod · 0.80
pristineMethod · 0.80
lenMethod · 0.45
pushMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected