Skip to content

Commit

Permalink
Only shift one specific suspect's line range
Browse files Browse the repository at this point in the history
  • Loading branch information
cruessler committed Sep 29, 2024
1 parent 20e5911 commit b2bd2cb
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions gix-blame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,10 @@ impl UnblamedHunk {
}
}

fn shift_by(&self, offset: Offset) -> Self {
let new_suspects = self
.suspects
.iter()
.map(|(suspect, range)| (*suspect, range.shift_by(offset)))
.collect();
fn shift_by(mut self, suspect: ObjectId, offset: Offset) -> Self {
self.suspects.entry(suspect).and_modify(|e| *e = e.shift_by(offset));

Self {
range_in_blamed_file: self.range_in_blamed_file.clone(),
suspects: new_suspects,
}
self
}

fn split_at(self, suspect: ObjectId, line_number_in_destination: u32) -> Either<Self, (Self, Self)> {
Expand Down Expand Up @@ -365,7 +358,7 @@ pub fn process_change(
// <--------> (hunk)
// <-------> (unchanged)

new_hunks_to_blame.push(hunk.shift_by(*offset_in_destination));
new_hunks_to_blame.push(hunk.shift_by(suspect, *offset_in_destination));

(None, Some(Change::Unchanged(unchanged)))
}
Expand All @@ -392,7 +385,7 @@ pub fn process_change(
// <---> (hunk)
// <----------> (unchanged)

new_hunks_to_blame.push(hunk.shift_by(*offset_in_destination));
new_hunks_to_blame.push(hunk.shift_by(suspect, *offset_in_destination));

(None, Some(Change::Unchanged(unchanged.clone())))
}
Expand All @@ -417,7 +410,7 @@ pub fn process_change(
let new_hunk = match hunk.split_at(suspect, added.start) {
Either::Left(hunk) => hunk,
Either::Right((before, after)) => {
new_hunks_to_blame.push(before.shift_by(*offset_in_destination));
new_hunks_to_blame.push(before.shift_by(suspect, *offset_in_destination));

after
}
Expand Down Expand Up @@ -446,7 +439,7 @@ pub fn process_change(
let new_hunk = match hunk.split_at(suspect, added.start) {
Either::Left(hunk) => hunk,
Either::Right((before, after)) => {
new_hunks_to_blame.push(before.shift_by(*offset_in_destination));
new_hunks_to_blame.push(before.shift_by(suspect, *offset_in_destination));

after
}
Expand Down Expand Up @@ -507,7 +500,7 @@ pub fn process_change(
// <--> (hunk)
// <----> (added)

new_hunks_to_blame.push(hunk.shift_by(*offset_in_destination));
new_hunks_to_blame.push(hunk.shift_by(suspect, *offset_in_destination));

(None, Some(Change::Added(added.clone(), number_of_lines_deleted)))
} else {
Expand Down Expand Up @@ -543,7 +536,7 @@ pub fn process_change(
let new_hunk = match hunk.split_at(suspect, line_number_in_destination) {
Either::Left(hunk) => hunk,
Either::Right((before, after)) => {
new_hunks_to_blame.push(before.shift_by(*offset_in_destination));
new_hunks_to_blame.push(before.shift_by(suspect, *offset_in_destination));

after
}
Expand All @@ -556,7 +549,7 @@ pub fn process_change(
// <---> (hunk)
// | (line_number_in_destination)

new_hunks_to_blame.push(hunk.shift_by(*offset_in_destination));
new_hunks_to_blame.push(hunk.shift_by(suspect, *offset_in_destination));

(
None,
Expand All @@ -565,7 +558,7 @@ pub fn process_change(
}
}
(Some(hunk), None) => {
new_hunks_to_blame.push(hunk.shift_by(*offset_in_destination));
new_hunks_to_blame.push(hunk.shift_by(suspect, *offset_in_destination));

(None, None)
}
Expand Down

0 comments on commit b2bd2cb

Please sign in to comment.