pub enum BlameRanges {
WholeFile,
PartialFile(Vec<Range<u32>>),
}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_one_based_inclusive_range(20..=40);
// Blame multiple ranges
let mut ranges = BlameRanges::from_one_based_inclusive_ranges(vec![
1..=4, // Lines 1-4
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
You can blame the entire file by calling BlameRanges::default(), or by passing an empty vector to from_one_based_inclusive_ranges.
Variants§
WholeFile
Blame the entire file.
PartialFile(Vec<Range<u32>>)
Blame ranges in 0-based exclusive format.
Implementations§
Source§impl BlameRanges
Lifecycle
impl BlameRanges
Lifecycle
Sourcepub fn from_one_based_inclusive_range(
range: RangeInclusive<u32>,
) -> Result<Self, Error>
pub fn from_one_based_inclusive_range( range: RangeInclusive<u32>, ) -> Result<Self, Error>
Create from a single 0-based range.
Note that the input range is 1-based inclusive, as used by git, and
the output is a zero-based BlameRanges instance.
Sourcepub fn from_one_based_inclusive_ranges(
ranges: Vec<RangeInclusive<u32>>,
) -> Result<Self, Error>
pub fn from_one_based_inclusive_ranges( ranges: Vec<RangeInclusive<u32>>, ) -> Result<Self, Error>
Create from multiple 0-based ranges.
Note that the input ranges are 1-based inclusive, as used by git, and
the output is a zero-based BlameRanges instance.
If the input vector is empty, the result will be WholeFile.
Source§impl BlameRanges
impl BlameRanges
Sourcepub fn add_one_based_inclusive_range(
&mut self,
new_range: RangeInclusive<u32>,
) -> Result<(), Error>
pub fn add_one_based_inclusive_range( &mut self, new_range: RangeInclusive<u32>, ) -> Result<(), Error>
Add a single range to blame.
The new range will be merged with any overlapping existing ranges.
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