| 2054 | } |
| 2055 | |
| 2056 | fn apply_line_index_updates( |
| 2057 | line_index: &mut ImportLineIndex, |
| 2058 | change_hash: ContentHash, |
| 2059 | pending: Vec<PendingLineIndexUpdate>, |
| 2060 | ) { |
| 2061 | for update in pending { |
| 2062 | match update { |
| 2063 | PendingLineIndexUpdate::Add { |
| 2064 | path, |
| 2065 | inode_pos, |
| 2066 | new_ranges, |
| 2067 | new_lines, |
| 2068 | } => { |
| 2069 | let inode_pos = Position { |
| 2070 | change: Some(change_hash), |
| 2071 | pos: inode_pos.pos, |
| 2072 | }; |
| 2073 | let lines = new_ranges |
| 2074 | .iter() |
| 2075 | .zip(new_lines) |
| 2076 | .map(|(&(start, end), content)| ImportLine { |
| 2077 | change: change_hash, |
| 2078 | start, |
| 2079 | end, |
| 2080 | incoming_by: change_hash, |
| 2081 | content, |
| 2082 | }) |
| 2083 | .collect(); |
| 2084 | line_index.files.insert( |
| 2085 | path, |
| 2086 | ImportIndexedFile { |
| 2087 | inode_pos, |
| 2088 | lines, |
| 2089 | imported_commits: 1, |
| 2090 | }, |
| 2091 | ); |
| 2092 | } |
| 2093 | PendingLineIndexUpdate::Modify { path, replacements } => { |
| 2094 | let Some(indexed) = line_index.files.get_mut(&path) else { |
| 2095 | continue; |
| 2096 | }; |
| 2097 | if !replacements.is_empty() { |
| 2098 | indexed.imported_commits += 1; |
| 2099 | } |
| 2100 | |
| 2101 | let mut offset: isize = 0; |
| 2102 | for replacement in replacements { |
| 2103 | let adjusted_start = (replacement.start_idx as isize + offset).max(0) as usize; |
| 2104 | let adjusted_end = adjusted_start |
| 2105 | .saturating_add(replacement.old_len) |
| 2106 | .min(indexed.lines.len()); |
| 2107 | let new_lines: Vec<ImportLine> = replacement |
| 2108 | .new_ranges |
| 2109 | .iter() |
| 2110 | .zip(replacement.new_lines) |
| 2111 | .map(|(&(start, end), content)| ImportLine { |
| 2112 | change: change_hash, |
| 2113 | start, |