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

Function revise

atomic-cli/src/commands/rpc.rs:4456–4659  ·  view source on GitHub ↗

`atomic revise` over Revise — every form. The reference (@/@~N/hash prefix) resolves through the daemon's Log exactly as the local `resolve_reference` does (newest-first: "@" is the last change, "@~N" N back, a prefix case-insensitively with an ambiguity refusal). The message composes client-side — an explicit `-m`, or the SAME editor flow the local body runs, seeded with the change's current mess

(args: &super::revise::Revise)

Source from the content-addressed store, hash-verified

4454/// `--dry-run` renders the same preview the local body prints, over the
4455/// wire's log entries.
4456pub fn revise(args: &super::revise::Revise) -> CliResult<bool> {
4457 let Some(session) = Service::open()? else {
4458 return Ok(false);
4459 };
4460
4461 // Resolve the reference through the daemon's Log (newest first) to
4462 // the full hash plus the change's current message — the editor's
4463 // seed — and its sequence.
4464 let parsed = super::revise::ChangeRef::parse(&args.reference);
4465 let entries = log_entries(&session, "")?;
4466 let target = match &parsed {
4467 super::revise::ChangeRef::Last => {
4468 if entries.is_empty() {
4469 return Err(CliError::Internal(anyhow::anyhow!(
4470 "Cannot revise: view '{}' is empty",
4471 current_view_name()?
4472 )));
4473 }
4474 entries.first().cloned()
4475 }
4476 super::revise::ChangeRef::Relative(offset) => {
4477 let offset = *offset as usize;
4478 match entries.get(offset) {
4479 Some(entry) => Some(entry.clone()),
4480 None => {
4481 return Err(CliError::Internal(anyhow::anyhow!(
4482 "Reference @~{} is out of range (view has {} changes)",
4483 offset,
4484 entries.len()
4485 )))
4486 }
4487 }
4488 }
4489 super::revise::ChangeRef::Hash(prefix) => {
4490 let prefix_lower = prefix.to_lowercase();
4491 let matches: Vec<_> = entries
4492 .iter()
4493 .filter(|e| {
4494 e.hash
4495 .as_ref()
4496 .and_then(|h| h.value.clone().try_into().ok())
4497 .map(|bytes: [u8; 32]| {
4498 Merkle(bytes)
4499 .to_base32()
4500 .to_lowercase()
4501 .starts_with(&prefix_lower)
4502 })
4503 .unwrap_or(false)
4504 })
4505 .collect();
4506 match matches.as_slice() {
4507 [] => {
4508 return Err(CliError::ChangeNotFound {
4509 hash: prefix.to_string(),
4510 })
4511 }
4512 [single] => Some((*single).clone()),
4513 _ => {

Callers 1

runMethod · 0.85

Calls 15

openFunction · 0.85
log_entriesFunction · 0.85
MerkleClass · 0.85
print_warningFunction · 0.85
print_hintFunction · 0.85
print_successFunction · 0.85
as_refMethod · 0.80
is_noneMethod · 0.80
getMethod · 0.65
parseFunction · 0.50
is_emptyMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected