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

Function current_state_replacements

atomic-cli/src/commands/git/parallel.rs:3899–3938  ·  view source on GitHub ↗
(
    indexed: &ImportIndexedFile,
    new_content: &[u8],
)

Source from the content-addressed store, hash-verified

3897}
3898
3899fn current_state_replacements(
3900 indexed: &ImportIndexedFile,
3901 new_content: &[u8],
3902) -> Vec<GitReplacementBlock> {
3903 let old_lines = &indexed.lines;
3904 let new_lines: Vec<Vec<u8>> = split_graph_first_lines(new_content)
3905 .into_iter()
3906 .map(|line| line.to_vec())
3907 .collect();
3908
3909 let mut prefix = 0usize;
3910 while prefix < old_lines.len()
3911 && prefix < new_lines.len()
3912 && old_lines[prefix].content == new_lines[prefix]
3913 {
3914 prefix += 1;
3915 }
3916
3917 let mut suffix = 0usize;
3918 while suffix < old_lines.len().saturating_sub(prefix)
3919 && suffix < new_lines.len().saturating_sub(prefix)
3920 && old_lines[old_lines.len() - 1 - suffix].content
3921 == new_lines[new_lines.len() - 1 - suffix]
3922 {
3923 suffix += 1;
3924 }
3925
3926 let old_mid_len = old_lines.len().saturating_sub(prefix + suffix);
3927 let new_mid_end = new_lines.len().saturating_sub(suffix);
3928 if old_mid_len == 0 && prefix == new_mid_end {
3929 return Vec::new();
3930 }
3931
3932 vec![GitReplacementBlock {
3933 old_start: if old_mid_len == 0 { prefix } else { prefix + 1 },
3934 old_len: old_mid_len,
3935 new_start: prefix + 1,
3936 new_lines: new_lines[prefix..new_mid_end].to_vec(),
3937 }]
3938}
3939
3940fn parse_git_diff_replacements(lines: &[GitDiffLine]) -> Option<Vec<GitReplacementBlock>> {
3941 let mut blocks = Vec::new();

Callers 1

build_graph_first_changeFunction · 0.85

Calls 4

split_graph_first_linesFunction · 0.85
collectMethod · 0.45
into_iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected