| 1941 | } |
| 1942 | |
| 1943 | fn apply_line_index_updates( |
| 1944 | line_index: &mut ImportLineIndex, |
| 1945 | change_hash: ContentHash, |
| 1946 | pending: Vec<PendingLineIndexUpdate>, |
| 1947 | ) { |
| 1948 | for update in pending { |
| 1949 | match update { |
| 1950 | PendingLineIndexUpdate::Add { |
| 1951 | path, |
| 1952 | inode_pos, |
| 1953 | new_ranges, |
| 1954 | new_lines, |
| 1955 | } => { |
| 1956 | let inode_pos = Position { |
| 1957 | change: Some(change_hash), |
| 1958 | pos: inode_pos.pos, |
| 1959 | }; |
| 1960 | let lines = new_ranges |
| 1961 | .iter() |
| 1962 | .zip(new_lines) |
| 1963 | .map(|(&(start, end), content)| ImportLine { |
| 1964 | change: change_hash, |
| 1965 | start, |
| 1966 | end, |
| 1967 | incoming_by: change_hash, |
| 1968 | content, |
| 1969 | }) |
| 1970 | .collect(); |
| 1971 | line_index.files.insert( |
| 1972 | path, |
| 1973 | ImportIndexedFile { |
| 1974 | inode_pos, |
| 1975 | lines, |
| 1976 | imported_commits: 1, |
| 1977 | }, |
| 1978 | ); |
| 1979 | } |
| 1980 | PendingLineIndexUpdate::Modify { path, replacements } => { |
| 1981 | let Some(indexed) = line_index.files.get_mut(&path) else { |
| 1982 | continue; |
| 1983 | }; |
| 1984 | if !replacements.is_empty() { |
| 1985 | indexed.imported_commits += 1; |
| 1986 | } |
| 1987 | |
| 1988 | let mut offset: isize = 0; |
| 1989 | for replacement in replacements { |
| 1990 | let adjusted_start = (replacement.start_idx as isize + offset).max(0) as usize; |
| 1991 | let adjusted_end = adjusted_start |
| 1992 | .saturating_add(replacement.old_len) |
| 1993 | .min(indexed.lines.len()); |
| 1994 | let new_lines: Vec<ImportLine> = replacement |
| 1995 | .new_ranges |
| 1996 | .iter() |
| 1997 | .zip(replacement.new_lines) |
| 1998 | .map(|(&(start, end), content)| ImportLine { |
| 1999 | change: change_hash, |
| 2000 | start, |