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

Function parse_git_diff_replacements

atomic-cli/src/commands/git/parallel.rs:1857–1941  ·  view source on GitHub ↗
(lines: &[GitDiffLine])

Source from the content-addressed store, hash-verified

1855}
1856
1857fn parse_git_diff_replacements(lines: &[GitDiffLine]) -> Option<Vec<GitReplacementBlock>> {
1858 let mut blocks = Vec::new();
1859 let mut old_start: Option<usize> = None;
1860 let mut new_start: Option<usize> = None;
1861 let mut old_len = 0usize;
1862 let mut new_lines = Vec::new();
1863 let mut old_cursor = 1usize;
1864 let mut new_cursor = 1usize;
1865
1866 let flush = |blocks: &mut Vec<GitReplacementBlock>,
1867 old_start: &mut Option<usize>,
1868 new_start: &mut Option<usize>,
1869 old_len: &mut usize,
1870 new_lines: &mut Vec<Vec<u8>>|
1871 -> Option<()> {
1872 if *old_len > 0 || !new_lines.is_empty() {
1873 let old = old_start.take()?;
1874 let new = new_start.take().unwrap_or(old);
1875 blocks.push(GitReplacementBlock {
1876 old_start: old,
1877 old_len: *old_len,
1878 new_start: new,
1879 new_lines: std::mem::take(new_lines),
1880 });
1881 *old_len = 0;
1882 }
1883 Some(())
1884 };
1885
1886 for line in lines {
1887 match line.origin {
1888 ' ' => {
1889 flush(
1890 &mut blocks,
1891 &mut old_start,
1892 &mut new_start,
1893 &mut old_len,
1894 &mut new_lines,
1895 )?;
1896 old_cursor = line
1897 .old_lineno
1898 .map(|n| n as usize + 1)
1899 .unwrap_or(old_cursor + 1);
1900 new_cursor = line
1901 .new_lineno
1902 .map(|n| n as usize + 1)
1903 .unwrap_or(new_cursor + 1);
1904 }
1905 '-' => {
1906 if old_start.is_none() {
1907 old_start = Some(line.old_lineno.map(|n| n as usize).unwrap_or(old_cursor));
1908 }
1909 old_cursor = line
1910 .old_lineno
1911 .map(|n| n as usize + 1)
1912 .unwrap_or(old_cursor + 1);
1913 old_len += 1;
1914 }

Callers 1

build_graph_first_changeFunction · 0.85

Calls 4

is_noneMethod · 0.80
is_emptyMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected