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

Source from the content-addressed store, hash-verified

3938}
3939
3940fn parse_git_diff_replacements(lines: &[GitDiffLine]) -> Option<Vec<GitReplacementBlock>> {
3941 let mut blocks = Vec::new();
3942 let mut old_start: Option<usize> = None;
3943 let mut new_start: Option<usize> = None;
3944 let mut old_len = 0usize;
3945 let mut new_lines = Vec::new();
3946 let mut old_cursor = 1usize;
3947 let mut new_cursor = 1usize;
3948
3949 let flush = |blocks: &mut Vec<GitReplacementBlock>,
3950 old_start: &mut Option<usize>,
3951 new_start: &mut Option<usize>,
3952 old_len: &mut usize,
3953 new_lines: &mut Vec<Vec<u8>>|
3954 -> Option<()> {
3955 if *old_len > 0 || !new_lines.is_empty() {
3956 let old = old_start.take()?;
3957 let new = new_start.take().unwrap_or(old);
3958 blocks.push(GitReplacementBlock {
3959 old_start: old,
3960 old_len: *old_len,
3961 new_start: new,
3962 new_lines: std::mem::take(new_lines),
3963 });
3964 *old_len = 0;
3965 }
3966 Some(())
3967 };
3968
3969 for line in lines {
3970 match line.origin {
3971 ' ' => {
3972 flush(
3973 &mut blocks,
3974 &mut old_start,
3975 &mut new_start,
3976 &mut old_len,
3977 &mut new_lines,
3978 )?;
3979 old_cursor = line
3980 .old_lineno
3981 .map(|n| n as usize + 1)
3982 .unwrap_or(old_cursor + 1);
3983 new_cursor = line
3984 .new_lineno
3985 .map(|n| n as usize + 1)
3986 .unwrap_or(new_cursor + 1);
3987 }
3988 '-' => {
3989 if old_start.is_none() {
3990 old_start = Some(line.old_lineno.map(|n| n as usize).unwrap_or(old_cursor));
3991 }
3992 old_cursor = line
3993 .old_lineno
3994 .map(|n| n as usize + 1)
3995 .unwrap_or(old_cursor + 1);
3996 old_len += 1;
3997 }

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