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

Function insert_preview

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

`atomic insert preview` over PreviewMutation (InsertPreview).

(
    from_view: &str,
    to_view: Option<String>,
    up_to_tag: Option<String>,
)

Source from the content-addressed store, hash-verified

4872
4873/// `atomic insert preview` over PreviewMutation (InsertPreview).
4874pub fn insert_preview(
4875 from_view: &str,
4876 to_view: Option<String>,
4877 up_to_tag: Option<String>,
4878) -> CliResult<bool> {
4879 let Some(session) = Service::open()? else {
4880 return Ok(false);
4881 };
4882 let to_view = to_view.unwrap_or_else(|| {
4883 std::fs::read_to_string(
4884 crate::commands::find_repository_root()
4885 .unwrap_or_default()
4886 .join(".atomic")
4887 .join("current_view"),
4888 )
4889 .map(|s| s.trim().to_string())
4890 .unwrap_or_else(|_| "dev".to_string())
4891 });
4892 let insert = pb::InsertPreview {
4893 source: Some(match up_to_tag {
4894 Some(tag) => pb::insert_preview::Source::UpToTag(tag),
4895 None => pb::insert_preview::Source::FromView(from_view.to_string()),
4896 }),
4897 target_view: to_view.clone(),
4898 allow_conflicts: false,
4899 };
4900 let request = pb::PreviewMutationRequest {
4901 repository: Some(session.reference.clone()),
4902 operation: Some(pb::preview_mutation_request::Operation::Insert(insert)),
4903 };
4904 let response = session.preview_mutation(request)?;
4905
4906 println!(" Source view: {from_view}");
4907 println!(" Target view: {to_view}");
4908 println!();
4909 if response.changes.is_empty() {
4910 print_success("No changes to insert - target view is up to date.");
4911 } else {
4912 println!(
4913 "Changes that would be inserted ({}):",
4914 response.changes.len()
4915 );
4916 println!();
4917 for (i, change) in response.changes.iter().enumerate() {
4918 let hash = short_hash(&change.hash);
4919 let message = change.message.clone().unwrap_or_default();
4920 let short_msg: String = message.chars().take(50).collect();
4921 println!(" {}. {} {}", i + 1, hash, short_msg);
4922 }
4923 println!();
4924 print_info(&format!(
4925 "Run 'atomic insert view {from_view}' to insert these changes."
4926 ));
4927 }
4928 Ok(true)
4929}
4930
4931/// `atomic unrecord --dry-run` over PreviewMutation (UnrecordPreview).

Callers 1

runMethod · 0.85

Calls 11

find_repository_rootFunction · 0.85
InsertClass · 0.85
print_successFunction · 0.85
print_infoFunction · 0.85
short_hashFunction · 0.70
openFunction · 0.50
cloneMethod · 0.45
preview_mutationMethod · 0.45
is_emptyMethod · 0.45
iterMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected