| 2002 | } |
| 2003 | |
| 2004 | fn apply_line_index_updates( |
| 2005 | line_index: &mut ImportLineIndex, |
| 2006 | change_hash: ContentHash, |
| 2007 | pending: Vec<PendingLineIndexUpdate>, |
| 2008 | ) { |
| 2009 | for update in pending { |
| 2010 | match update { |
| 2011 | PendingLineIndexUpdate::Add { |
| 2012 | path, |
| 2013 | inode_pos, |
| 2014 | new_ranges, |
| 2015 | new_lines, |
| 2016 | } => { |
| 2017 | let inode_pos = Position { |
| 2018 | change: Some(change_hash), |
| 2019 | pos: inode_pos.pos, |
| 2020 | }; |
| 2021 | let lines = new_ranges |
| 2022 | .iter() |
| 2023 | .zip(new_lines) |
| 2024 | .map(|(&(start, end), content)| ImportLine { |
| 2025 | change: change_hash, |
| 2026 | start, |
| 2027 | end, |
| 2028 | incoming_by: change_hash, |
| 2029 | content, |
| 2030 | }) |
| 2031 | .collect(); |
| 2032 | line_index.files.insert( |
| 2033 | path, |
| 2034 | ImportIndexedFile { |
| 2035 | inode_pos, |
| 2036 | lines, |
| 2037 | imported_commits: 1, |
| 2038 | }, |
| 2039 | ); |
| 2040 | } |
| 2041 | PendingLineIndexUpdate::Modify { path, replacements } => { |
| 2042 | let Some(indexed) = line_index.files.get_mut(&path) else { |
| 2043 | continue; |
| 2044 | }; |
| 2045 | if !replacements.is_empty() { |
| 2046 | indexed.imported_commits += 1; |
| 2047 | } |
| 2048 | |
| 2049 | let mut offset: isize = 0; |
| 2050 | for replacement in replacements { |
| 2051 | let adjusted_start = (replacement.start_idx as isize + offset).max(0) as usize; |
| 2052 | let adjusted_end = adjusted_start |
| 2053 | .saturating_add(replacement.old_len) |
| 2054 | .min(indexed.lines.len()); |
| 2055 | let new_lines: Vec<ImportLine> = replacement |
| 2056 | .new_ranges |
| 2057 | .iter() |
| 2058 | .zip(replacement.new_lines) |
| 2059 | .map(|(&(start, end), content)| ImportLine { |
| 2060 | change: change_hash, |
| 2061 | start, |