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

Function current_state_replacements

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

Source from the content-addressed store, hash-verified

1883}
1884
1885fn current_state_replacements(
1886 indexed: &ImportIndexedFile,
1887 new_content: &[u8],
1888) -> Vec<GitReplacementBlock> {
1889 let old_lines = &indexed.lines;
1890 let new_lines: Vec<Vec<u8>> = split_graph_first_lines(new_content)
1891 .into_iter()
1892 .map(|line| line.to_vec())
1893 .collect();
1894
1895 let mut prefix = 0usize;
1896 while prefix < old_lines.len()
1897 && prefix < new_lines.len()
1898 && old_lines[prefix].content == new_lines[prefix]
1899 {
1900 prefix += 1;
1901 }
1902
1903 let mut suffix = 0usize;
1904 while suffix < old_lines.len().saturating_sub(prefix)
1905 && suffix < new_lines.len().saturating_sub(prefix)
1906 && old_lines[old_lines.len() - 1 - suffix].content
1907 == new_lines[new_lines.len() - 1 - suffix]
1908 {
1909 suffix += 1;
1910 }
1911
1912 let old_mid_len = old_lines.len().saturating_sub(prefix + suffix);
1913 let new_mid_end = new_lines.len().saturating_sub(suffix);
1914 if old_mid_len == 0 && prefix == new_mid_end {
1915 return Vec::new();
1916 }
1917
1918 vec![GitReplacementBlock {
1919 old_start: if old_mid_len == 0 { prefix } else { prefix + 1 },
1920 old_len: old_mid_len,
1921 new_start: prefix + 1,
1922 new_lines: new_lines[prefix..new_mid_end].to_vec(),
1923 }]
1924}
1925
1926fn parse_git_diff_replacements(lines: &[GitDiffLine]) -> Option<Vec<GitReplacementBlock>> {
1927 let mut blocks = Vec::new();

Callers 1

build_graph_first_changeFunction · 0.85

Calls 3

split_graph_first_linesFunction · 0.85
into_iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected