pub struct BlameRanges { /* private fields */ }Expand description
A type to represent one or more line ranges to blame in a file.
It handles the conversion between git’s 1-based inclusive ranges and the internal 0-based exclusive ranges used by the blame algorithm.
§Examples
use gix_blame::BlameRanges;
// Blame lines 20 through 40 (inclusive)
let range = BlameRanges::from_range(20..=40);
// Blame multiple ranges
let mut ranges = BlameRanges::new();
ranges.add_range(1..=4); // Lines 1-4
ranges.add_range(10..=14); // Lines 10-14§Line Number Representation
This type uses 1-based inclusive ranges to mirror git’s behaviour:
- A range of
20..=40represents 21 lines, spanning from line 20 up to and including line 40 - This will be converted to
19..40internally as the algorithm uses 0-based ranges that are exclusive at the end
§Empty Ranges
An empty BlameRanges (created via BlameRanges::new() or BlameRanges::default()) means
to blame the entire file, similar to running git blame without line number arguments.
Implementations§
Source§impl BlameRanges
Lifecycle
impl BlameRanges
Lifecycle
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new empty BlameRanges instance.
An empty instance means to blame the entire file.
Sourcepub fn from_range(range: RangeInclusive<u32>) -> Self
pub fn from_range(range: RangeInclusive<u32>) -> Self
Create from a single range.
The range is 1-based, similar to git’s line number format.
Sourcepub fn from_ranges(ranges: Vec<RangeInclusive<u32>>) -> Self
pub fn from_ranges(ranges: Vec<RangeInclusive<u32>>) -> Self
Create from multiple ranges.
All ranges are 1-based. Overlapping or adjacent ranges will be merged.
Source§impl BlameRanges
impl BlameRanges
Sourcepub fn add_range(&mut self, new_range: RangeInclusive<u32>)
pub fn add_range(&mut self, new_range: RangeInclusive<u32>)
Add a single range to blame.
The range should be 1-based inclusive. If the new range overlaps with or is adjacent to an existing range, they will be merged into a single range.
Sourcepub fn to_zero_based_exclusive(
&self,
max_lines: u32,
) -> Result<Vec<Range<u32>>, Error>
pub fn to_zero_based_exclusive( &self, max_lines: u32, ) -> Result<Vec<Range<u32>>, Error>
Convert the 1-based inclusive ranges to 0-based exclusive ranges.
This is used internally by the blame algorithm to convert from git’s line number format to the internal format used for processing.
§Errors
Returns Error::InvalidLineRange if:
- Any range starts at 0 (must be 1-based)
- Any range extends beyond the file’s length
- Any range has the same start and end
Trait Implementations§
Source§impl Clone for BlameRanges
impl Clone for BlameRanges
Source§fn clone(&self) -> BlameRanges
fn clone(&self) -> BlameRanges
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more