(
indexed: &ImportIndexedFile,
new_content: &[u8],
)
| 1814 | } |
| 1815 | |
| 1816 | fn current_state_replacements( |
| 1817 | indexed: &ImportIndexedFile, |
| 1818 | new_content: &[u8], |
| 1819 | ) -> Vec<GitReplacementBlock> { |
| 1820 | let old_lines = &indexed.lines; |
| 1821 | let new_lines: Vec<Vec<u8>> = split_graph_first_lines(new_content) |
| 1822 | .into_iter() |
| 1823 | .map(|line| line.to_vec()) |
| 1824 | .collect(); |
| 1825 | |
| 1826 | let mut prefix = 0usize; |
| 1827 | while prefix < old_lines.len() |
| 1828 | && prefix < new_lines.len() |
| 1829 | && old_lines[prefix].content == new_lines[prefix] |
| 1830 | { |
| 1831 | prefix += 1; |
| 1832 | } |
| 1833 | |
| 1834 | let mut suffix = 0usize; |
| 1835 | while suffix < old_lines.len().saturating_sub(prefix) |
| 1836 | && suffix < new_lines.len().saturating_sub(prefix) |
| 1837 | && old_lines[old_lines.len() - 1 - suffix].content |
| 1838 | == new_lines[new_lines.len() - 1 - suffix] |
| 1839 | { |
| 1840 | suffix += 1; |
| 1841 | } |
| 1842 | |
| 1843 | let old_mid_len = old_lines.len().saturating_sub(prefix + suffix); |
| 1844 | let new_mid_end = new_lines.len().saturating_sub(suffix); |
| 1845 | if old_mid_len == 0 && prefix == new_mid_end { |
| 1846 | return Vec::new(); |
| 1847 | } |
| 1848 | |
| 1849 | vec![GitReplacementBlock { |
| 1850 | old_start: if old_mid_len == 0 { prefix } else { prefix + 1 }, |
| 1851 | old_len: old_mid_len, |
| 1852 | new_start: prefix + 1, |
| 1853 | new_lines: new_lines[prefix..new_mid_end].to_vec(), |
| 1854 | }] |
| 1855 | } |
| 1856 | |
| 1857 | fn parse_git_diff_replacements(lines: &[GitDiffLine]) -> Option<Vec<GitReplacementBlock>> { |
| 1858 | let mut blocks = Vec::new(); |
no test coverage detected