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

Method build_git_import_file_diffs

atomic-cli/src/commands/diff/helpers.rs:523–628  ·  view source on GitHub ↗
(
        change: &Change,
    )

Source from the content-addressed store, hash-verified

521 }
522
523 pub(crate) fn build_git_import_file_diffs(
524 change: &Change,
525 ) -> Option<(Vec<FileDiff>, DiffStats)> {
526 let diff_files_value = change
527 .unhashed
528 .as_ref()?
529 .get("git")?
530 .get("diff_lines")?
531 .clone();
532
533 let diff_files: Vec<GitMetadataDiffFile> = serde_json::from_value(diff_files_value).ok()?;
534 let mut file_diffs = Vec::new();
535 let mut stats = DiffStats::new();
536
537 for entry in diff_files {
538 let mut insertions = 0usize;
539 let mut deletions = 0usize;
540 let mut hunk_lines = Vec::new();
541 let mut old_start = None;
542 let mut new_start = None;
543
544 for line in entry.lines {
545 let content = String::from_utf8_lossy(&line.content)
546 .trim_end_matches('\n')
547 .to_string();
548 match line.origin {
549 '+' => {
550 let new_num = line.new_lineno.unwrap_or((insertions + 1) as u32) as usize;
551 if new_start.is_none() {
552 new_start = Some(new_num);
553 }
554 hunk_lines.push(HunkLine::added(content, new_num));
555 insertions += 1;
556 }
557 '-' => {
558 let old_num = line.old_lineno.unwrap_or((deletions + 1) as u32) as usize;
559 if old_start.is_none() {
560 old_start = Some(old_num);
561 }
562 hunk_lines.push(HunkLine::removed(content, old_num));
563 deletions += 1;
564 }
565 _ => {}
566 }
567 }
568
569 if hunk_lines.is_empty() {
570 if entry.operation.as_deref() == Some("renamed") {
571 if let Some(old_path) = &entry.old_path {
572 let unproven = change
573 .unhashed
574 .as_ref()
575 .and_then(|value| value.pointer("/git/stream/rename_identity_loss"))
576 .and_then(|value| value.as_array())
577 .is_some_and(|losses| {
578 losses.iter().any(|loss| {
579 loss.get("from").and_then(|v| v.as_str())
580 == Some(old_path.as_str())

Callers

nothing calls this directly

Calls 15

addedFunction · 0.85
removedFunction · 0.85
deletedFunction · 0.85
modifiedFunction · 0.85
as_refMethod · 0.80
is_noneMethod · 0.80
getMethod · 0.65
cloneMethod · 0.45
okMethod · 0.45
pushMethod · 0.45
is_emptyMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected