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

Function current_state_replacements

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

Source from the content-addressed store, hash-verified

1927}
1928
1929fn current_state_replacements(
1930 indexed: &ImportIndexedFile,
1931 new_content: &[u8],
1932) -> Vec<GitReplacementBlock> {
1933 let old_lines = &indexed.lines;
1934 let new_lines: Vec<Vec<u8>> = split_graph_first_lines(new_content)
1935 .into_iter()
1936 .map(|line| line.to_vec())
1937 .collect();
1938
1939 let mut prefix = 0usize;
1940 while prefix < old_lines.len()
1941 && prefix < new_lines.len()
1942 && old_lines[prefix].content == new_lines[prefix]
1943 {
1944 prefix += 1;
1945 }
1946
1947 let mut suffix = 0usize;
1948 while suffix < old_lines.len().saturating_sub(prefix)
1949 && suffix < new_lines.len().saturating_sub(prefix)
1950 && old_lines[old_lines.len() - 1 - suffix].content
1951 == new_lines[new_lines.len() - 1 - suffix]
1952 {
1953 suffix += 1;
1954 }
1955
1956 let old_mid_len = old_lines.len().saturating_sub(prefix + suffix);
1957 let new_mid_end = new_lines.len().saturating_sub(suffix);
1958 if old_mid_len == 0 && prefix == new_mid_end {
1959 return Vec::new();
1960 }
1961
1962 vec![GitReplacementBlock {
1963 old_start: if old_mid_len == 0 { prefix } else { prefix + 1 },
1964 old_len: old_mid_len,
1965 new_start: prefix + 1,
1966 new_lines: new_lines[prefix..new_mid_end].to_vec(),
1967 }]
1968}
1969
1970fn parse_git_diff_replacements(lines: &[GitDiffLine]) -> Option<Vec<GitReplacementBlock>> {
1971 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