Struct BlameRanges

Source
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..=40 represents 21 lines, spanning from line 20 up to and including line 40
  • This will be converted to 19..40 internally 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

Source

pub fn new() -> Self

Create a new empty BlameRanges instance.

An empty instance means to blame the entire file.

Source

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.

Source

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

Source

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.

Source

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
Source

pub fn is_empty(&self) -> bool

Returns true if no specific ranges are set (meaning blame entire file)

Trait Implementations§

Source§

impl Clone for BlameRanges

Source§

fn clone(&self) -> BlameRanges

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BlameRanges

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BlameRanges

Source§

fn default() -> BlameRanges

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.