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:2012–2099  ·  view source on GitHub ↗
(
    line_index: &mut ImportLineIndex,
    change_hash: ContentHash,
    pending: Vec<PendingLineIndexUpdate>,
)

Source from the content-addressed store, hash-verified

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