From 97e1a4168d9fab4554251823ba37c6bc540194f0 Mon Sep 17 00:00:00 2001 From: Nik Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Wed, 19 Mar 2025 17:42:28 +0000 Subject: [PATCH] refactor: rename `blame` -> `blame_line` _ _ --- helix-term/src/handlers/blame.rs | 7 +------ helix-vcs/src/git/blame.rs | 14 ++++++-------- helix-vcs/src/lib.rs | 16 ++++------------ 3 files changed, 11 insertions(+), 26 deletions(-) diff --git a/helix-term/src/handlers/blame.rs b/helix-term/src/handlers/blame.rs index a5cf4037..0be7815b 100644 --- a/helix-term/src/handlers/blame.rs +++ b/helix-term/src/handlers/blame.rs @@ -44,12 +44,7 @@ impl helix_event::AsyncHook for BlameHandler { let worker = tokio::spawn(async move { diff_providers - .blame( - &file, - cursor_line..cursor_line, - added_lines_count, - removed_lines_count, - ) + .blame(&file, cursor_line, added_lines_count, removed_lines_count) .map(|s| s.parse_format(&blame_format)) }); self.worker = Some(worker); diff --git a/helix-vcs/src/git/blame.rs b/helix-vcs/src/git/blame.rs index 02fadfb6..0ee4deed 100644 --- a/helix-vcs/src/git/blame.rs +++ b/helix-vcs/src/git/blame.rs @@ -1,6 +1,6 @@ use anyhow::Context as _; use gix::bstr::BStr; -use std::{collections::HashMap, ops::Range, path::Path}; +use std::{collections::HashMap, path::Path}; use super::{get_repo_dir, open_repo}; @@ -116,10 +116,10 @@ impl BlameInformation { } } -/// `git blame` a range in a file -pub fn blame( +/// `git blame` a single line in a file +pub fn blame_line( file: &Path, - range: Range<u32>, + line: u32, added_lines_count: u32, removed_lines_count: u32, ) -> anyhow::Result<BlameInformation> { @@ -134,9 +134,7 @@ pub fn blame( // So when our cursor is on the 10th added line or earlier, blame_line will be 0. This means // the blame will be incorrect. But that's fine, because when the cursor_line is on some hunk, // we can show to the user nothing at all - let normalize = |line: u32| line.saturating_sub(added_lines_count) + removed_lines_count; - - let blame_range = normalize(range.start)..normalize(range.end); + let blame_line = line.saturating_sub(added_lines_count) + removed_lines_count; let repo_dir = get_repo_dir(file)?; let repo = open_repo(repo_dir) @@ -168,7 +166,7 @@ pub fn blame( traverse_all_commits, &mut resource_cache, BStr::new(relative_path), - Some(blame_range), + Some(blame_line..blame_line), )? .entries .first() diff --git a/helix-vcs/src/lib.rs b/helix-vcs/src/lib.rs index 619d18ef..c63558c0 100644 --- a/helix-vcs/src/lib.rs +++ b/helix-vcs/src/lib.rs @@ -2,7 +2,6 @@ use anyhow::Context as _; use anyhow::{anyhow, bail, Result}; use arc_swap::ArcSwap; use git::BlameInformation; -use std::ops::Range; use std::{ path::{Path, PathBuf}, sync::Arc, @@ -55,20 +54,13 @@ impl DiffProviderRegistry { pub fn blame( &self, file: &Path, - range: Range<u32>, + line: u32, added_lines_count: u32, removed_lines_count: u32, ) -> anyhow::Result<BlameInformation> { self.providers .iter() - .map(|provider| { - provider.blame( - file, - range.start..range.end, - added_lines_count, - removed_lines_count, - ) - }) + .map(|provider| provider.blame(file, line, added_lines_count, removed_lines_count)) .next() .context("No provider found")? } @@ -136,13 +128,13 @@ impl DiffProvider { fn blame( &self, file: &Path, - range: Range<u32>, + line: u32, added_lines_count: u32, removed_lines_count: u32, ) -> Result<BlameInformation> { match self { #[cfg(feature = "git")] - Self::Git => git::blame(file, range, added_lines_count, removed_lines_count), + Self::Git => git::blame_line(file, line, added_lines_count, removed_lines_count), Self::None => bail!("No blame support compiled in"), } }