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