MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / apply_line_index_updates

Function apply_line_index_updates

atomic-cli/src/commands/git/parallel.rs:1943–2030  ·  view source on GitHub ↗
(
    line_index: &mut ImportLineIndex,
    change_hash: ContentHash,
    pending: Vec<PendingLineIndexUpdate>,
)

Source from the content-addressed store, hash-verified

1941}
1942
1943fn 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,

Callers 1

write_commitMethod · 0.85

Calls 6

get_mutMethod · 0.80
removeMethod · 0.65
iterMethod · 0.45
insertMethod · 0.45
is_emptyMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected