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

Function get_change_impl

libatomic/src/daemon/services_query.rs:309–553  ·  view source on GitHub ↗
(
    state: &Arc<DaemonState>,
    request: Request<GetChangeRequest>,
)

Source from the content-addressed store, hash-verified

307}
308
309pub async fn get_change_impl(
310 state: &Arc<DaemonState>,
311 request: Request<GetChangeRequest>,
312) -> Result<Response<GetChangeResponse>, Status> {
313 let request = request.into_inner();
314 let handle = state.resolve(request.repository.as_ref().unwrap())?;
315 state.log_rpc("GetChange", Some(&handle));
316 let reference = request
317 .r#ref
318 .and_then(|r| r.kind)
319 .ok_or_else(|| domain_status(ErrorCode::InvalidArgument, "change ref required"))?;
320 let view = request
321 .view
322 .as_ref()
323 .map(|v| v.name.clone().unwrap_or_default());
324
325 let gate_handle = handle.clone();
326 let _gate = gate_handle.exclusive().await;
327 let handle_for_task = handle.clone();
328 let wants_bundle = request.includes.as_ref().is_some_and(|i| i.metadata);
329 let wants_file_contents = request.include_file_contents;
330 let wants_blast_radius = request.includes.as_ref().is_some_and(|i| i.blast_radius);
331 let change = tokio::task::spawn_blocking(move || {
332 // A query: read-only open with the read-concurrency wait.
333 let repo = handle_for_task.repository_readonly()?;
334 let (hash, sequence) = match reference {
335 change_ref::Kind::Hash(hash) => {
336 let mut bytes = [0u8; 32];
337 if hash.value.len() != 32 {
338 return Err(domain_status(
339 ErrorCode::InvalidArgument,
340 "hash must be 32 bytes",
341 ));
342 }
343 bytes.copy_from_slice(&hash.value);
344 (atomic_core::types::Merkle(bytes), None)
345 }
346 change_ref::Kind::Sequence(sequence) => {
347 let view_name = view
348 .clone()
349 .unwrap_or_else(|| repo.current_view().to_string());
350 let txn = repo
351 .pristine()
352 .read_txn()
353 .map_err(|error| domain_status(ErrorCode::Repository, error.to_string()))?;
354 let view_state = txn
355 .get_view(&view_name)
356 .map_err(|error| domain_status(ErrorCode::View, error.to_string()))?
357 .ok_or_else(|| {
358 domain_status(ErrorCode::View, format!("view '{view_name}' not found"))
359 })?;
360 let entry =
361 atomic_repository::history::get_change_at_sequence(&txn, &view_state, sequence)
362 .map_err(|error| domain_status(ErrorCode::NotFound, error.to_string()))?;
363 (entry.hash, Some(sequence))
364 }
365 change_ref::Kind::Prefix(prefix) => {
366 // Case-insensitive unique-prefix resolution over the whole

Callers 1

get_changeMethod · 0.85

Calls 15

domain_statusFunction · 0.85
MerkleClass · 0.85
change_intent_projectionFunction · 0.85
get_files_in_changeFunction · 0.85
as_refMethod · 0.80
log_rpcMethod · 0.80
exclusiveMethod · 0.80
repository_readonlyMethod · 0.80
read_txnMethod · 0.80
pristineMethod · 0.80
find_change_by_prefixMethod · 0.80

Tested by

no test coverage detected