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:1970–2054  ·  view source on GitHub ↗
(lines: &[GitDiffLine])

Source from the content-addressed store, hash-verified

1968}
1969
1970fn parse_git_diff_replacements(lines: &[GitDiffLine]) -> Option<Vec<GitReplacementBlock>> {
1971 let mut blocks = Vec::new();
1972 let mut old_start: Option<usize> = None;
1973 let mut new_start: Option<usize> = None;
1974 let mut old_len = 0usize;
1975 let mut new_lines = Vec::new();
1976 let mut old_cursor = 1usize;
1977 let mut new_cursor = 1usize;
1978
1979 let flush = |blocks: &mut Vec<GitReplacementBlock>,
1980 old_start: &mut Option<usize>,
1981 new_start: &mut Option<usize>,
1982 old_len: &mut usize,
1983 new_lines: &mut Vec<Vec<u8>>|
1984 -> Option<()> {
1985 if *old_len > 0 || !new_lines.is_empty() {
1986 let old = old_start.take()?;
1987 let new = new_start.take().unwrap_or(old);
1988 blocks.push(GitReplacementBlock {
1989 old_start: old,
1990 old_len: *old_len,
1991 new_start: new,
1992 new_lines: std::mem::take(new_lines),
1993 });
1994 *old_len = 0;
1995 }
1996 Some(())
1997 };
1998
1999 for line in lines {
2000 match line.origin {
2001 ' ' => {
2002 flush(
2003 &mut blocks,
2004 &mut old_start,
2005 &mut new_start,
2006 &mut old_len,
2007 &mut new_lines,
2008 )?;
2009 old_cursor = line
2010 .old_lineno
2011 .map(|n| n as usize + 1)
2012 .unwrap_or(old_cursor + 1);
2013 new_cursor = line
2014 .new_lineno
2015 .map(|n| n as usize + 1)
2016 .unwrap_or(new_cursor + 1);
2017 }
2018 '-' => {
2019 if old_start.is_none() {
2020 old_start = Some(line.old_lineno.map(|n| n as usize).unwrap_or(old_cursor));
2021 }
2022 old_cursor = line
2023 .old_lineno
2024 .map(|n| n as usize + 1)
2025 .unwrap_or(old_cursor + 1);
2026 old_len += 1;
2027 }

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