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

Function insert_preview

atomic-cli/src/commands/rpc.rs:4834–4889  ·  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

4832
4833/// `atomic insert preview` over PreviewMutation (InsertPreview).
4834pub fn insert_preview(
4835 from_view: &str,
4836 to_view: Option<String>,
4837 up_to_tag: Option<String>,
4838) -> CliResult<bool> {
4839 let Some(session) = Service::open()? else {
4840 return Ok(false);
4841 };
4842 let to_view = to_view.unwrap_or_else(|| {
4843 std::fs::read_to_string(
4844 crate::commands::find_repository_root()
4845 .unwrap_or_default()
4846 .join(".atomic")
4847 .join("current_view"),
4848 )
4849 .map(|s| s.trim().to_string())
4850 .unwrap_or_else(|_| "dev".to_string())
4851 });
4852 let insert = pb::InsertPreview {
4853 source: Some(match up_to_tag {
4854 Some(tag) => pb::insert_preview::Source::UpToTag(tag),
4855 None => pb::insert_preview::Source::FromView(from_view.to_string()),
4856 }),
4857 target_view: to_view.clone(),
4858 allow_conflicts: false,
4859 };
4860 let request = pb::PreviewMutationRequest {
4861 repository: Some(session.reference.clone()),
4862 operation: Some(pb::preview_mutation_request::Operation::Insert(insert)),
4863 };
4864 let response = session.preview_mutation(request)?;
4865
4866 println!(" Source view: {from_view}");
4867 println!(" Target view: {to_view}");
4868 println!();
4869 if response.changes.is_empty() {
4870 print_success("No changes to insert - target view is up to date.");
4871 } else {
4872 println!(
4873 "Changes that would be inserted ({}):",
4874 response.changes.len()
4875 );
4876 println!();
4877 for (i, change) in response.changes.iter().enumerate() {
4878 let hash = short_hash(&change.hash);
4879 let message = change.message.clone().unwrap_or_default();
4880 let short_msg: String = message.chars().take(50).collect();
4881 println!(" {}. {} {}", i + 1, hash, short_msg);
4882 }
4883 println!();
4884 print_info(&format!(
4885 "Run 'atomic insert view {from_view}' to insert these changes."
4886 ));
4887 }
4888 Ok(true)
4889}
4890
4891/// `atomic unrecord --dry-run` over PreviewMutation (UnrecordPreview).

Callers 1

runMethod · 0.85

Calls 11

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

Tested by

no test coverage detected