pub struct DiffIndex { /* private fields */ }Expand description
Parsed, command-neutral index of files and added lines in a unified diff.
Keys are exactly the paths the diff names in its +++ b/<path> headers,
so they live in whatever namespace produced the diff — for git diff,
relative to the repository toplevel. DiffIndex::base records the
directory those keys are relative to, so a finding’s absolute path can be
mapped into the same namespace before lookup. Without it, an analysis root
below the toplevel silently misses every key.
Implementations§
Source§impl DiffIndex
impl DiffIndex
Sourcepub fn from_unified_diff(diff: &str) -> Self
pub fn from_unified_diff(diff: &str) -> Self
Parse a unified diff into an index of changed files and added lines.
Indexes at most MAX_ADDED_LINES added lines; totals used by
DiffIndex::net_lines keep counting past the cap.
Sourcepub fn old_path_for(&self, head_path: &str) -> Option<&str>
pub fn old_path_for(&self, head_path: &str) -> Option<&str>
Pre-rename path for head_path, in the diff’s key namespace, when the
diff renamed it.
Sourcepub fn added_line_count(&self) -> usize
pub fn added_line_count(&self) -> usize
Number of indexed added lines, capped at MAX_ADDED_LINES.
Sourcepub fn hunk_count(&self) -> usize
pub fn hunk_count(&self) -> usize
Number of parsed unified-diff hunk headers.
Sourcepub fn net_lines(&self) -> i64
pub fn net_lines(&self) -> i64
Total added lines minus total removed lines, independent of the added line indexing cap.
Sourcepub fn changes_path(&self, path: &str) -> bool
pub fn changes_path(&self, path: &str) -> bool
Whether this diff changes the path, including when the path is deleted.
Sourcepub fn changed_paths(&self) -> impl Iterator<Item = &str>
pub fn changed_paths(&self) -> impl Iterator<Item = &str>
Paths changed by the diff, using the old path for deleted files.
Sourcepub fn touches_file(&self, path: &str) -> bool
pub fn touches_file(&self, path: &str) -> bool
Whether this diff touches an analyzable path in the head tree.
Sourcepub fn range_overlaps_added(&self, path: &str, start: u64, end: u64) -> bool
pub fn range_overlaps_added(&self, path: &str, start: u64, end: u64) -> bool
Whether any added line in path falls inside the inclusive 1-based
start..=end range.
Sourcepub fn line_is_added(&self, path: &str, line: u64) -> bool
pub fn line_is_added(&self, path: &str, line: u64) -> bool
Whether the 1-based line in path was added by this diff.
Sourcepub fn line_within_added_context(
&self,
path: &str,
line: u64,
radius: u64,
) -> bool
pub fn line_within_added_context( &self, path: &str, line: u64, radius: u64, ) -> bool
Whether line sits within radius lines of any added line in path.
Sourcepub fn added_lines_in(&self, path: &str) -> Option<&FxHashSet<u64>>
pub fn added_lines_in(&self, path: &str) -> Option<&FxHashSet<u64>>
Set of 1-based added line numbers for path, when the diff added any.
Sourcepub fn with_base(self, base: impl Into<PathBuf>) -> Self
pub fn with_base(self, base: impl Into<PathBuf>) -> Self
Declare the directory this diff’s paths are relative to (the git
toplevel for git diff output).
Sourcepub fn with_root_offset(self, offset: impl Into<String>) -> Self
pub fn with_root_offset(self, offset: impl Into<String>) -> Self
Declare where the analysis root sits below DiffIndex::base, as a
forward-slashed relative path (empty when they are the same directory).
Findings are addressed relative to the analysis root; this diff’s keys are relative to its base. Everything that looks a finding up in this index has to cross that gap, so the index carries the offset rather than making each caller rediscover it.
Sourcepub fn root_offset(&self) -> &str
pub fn root_offset(&self) -> &str
Relative path of the analysis root below DiffIndex::base; empty
when they coincide.
Sourcepub fn key_for_root_relative<'a>(&self, rel: &'a str) -> Cow<'a, str>
pub fn key_for_root_relative<'a>(&self, rel: &'a str) -> Cow<'a, str>
Lift an analysis-root-relative path into this diff’s key namespace.
Sourcepub fn root_relative_from_key<'a>(&self, key: &'a str) -> Option<Cow<'a, str>>
pub fn root_relative_from_key<'a>(&self, key: &'a str) -> Option<Cow<'a, str>>
Lower one of this diff’s keys back to an analysis-root-relative path.
None when the key names a file outside the analysis root.
Sourcepub fn old_path_for_root_relative<'a>(
&'a self,
rel: &str,
) -> Option<Cow<'a, str>>
pub fn old_path_for_root_relative<'a>( &'a self, rel: &str, ) -> Option<Cow<'a, str>>
The pre-rename path of an analysis-root-relative path, itself analysis-root-relative. Crosses into the diff’s key namespace and back, so a monorepo package below the diff’s base resolves its renames.
Sourcepub fn base(&self) -> Option<&Path>
pub fn base(&self) -> Option<&Path>
Directory this diff’s keys are relative to, when declared via
DiffIndex::with_base.
Sourcepub fn touched_files(&self) -> impl Iterator<Item = &str>
pub fn touched_files(&self) -> impl Iterator<Item = &str>
Analyzable head-tree paths this diff touches, in the diff’s key namespace.
Sourcepub fn key_for(&self, path: &Path, fallback_root: &Path) -> Option<String>
pub fn key_for(&self, path: &Path, fallback_root: &Path) -> Option<String>
Map a finding’s path into this diff’s key namespace.
Relativizes against DiffIndex::base when one was declared, else
against fallback_root. When base == fallback_root (the analysis
root is the repository toplevel) both agree, so behavior is unchanged.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DiffIndex
impl RefUnwindSafe for DiffIndex
impl Send for DiffIndex
impl Sync for DiffIndex
impl Unpin for DiffIndex
impl UnsafeUnpin for DiffIndex
impl UnwindSafe for DiffIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more