Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support git blame -C option #953

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lua/gitsigns/cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ function CacheEntry:run_blame(lnum, opts)
local tick = vim.b[self.bufnr].changedtick
local lnum0 = #buftext > BLAME_THRESHOLD_LEN and lnum or nil
-- TODO(lewis6991): Cancel blame on changedtick
blame_cache = self.git_obj:run_blame(buftext, lnum0, opts.ignore_whitespace)
blame_cache =
self.git_obj:run_blame(buftext, lnum0, opts.ignore_whitespace, opts.detect_move_or_copy)
async.scheduler_if_buf_valid(self.bufnr)
until vim.b[self.bufnr].changedtick == tick
return blame_cache
Expand Down
1 change: 1 addition & 0 deletions lua/gitsigns/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
--- @field virt_text_pos 'eol'|'overlay'|'right_align'
--- @field delay integer
--- @field ignore_whitespace boolean
--- @field detect_move_or_copy 'C'|'CC'|'CCC'
--- @field virt_text_priority integer

--- @class (exact) Gitsigns.Config
Expand Down
7 changes: 6 additions & 1 deletion lua/gitsigns/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,9 @@ end
--- @param lines string[]
--- @param lnum? integer
--- @param ignore_whitespace? boolean
--- @param detect_move_or_copy? string
--- @return table<integer,Gitsigns.BlameInfo?>?
function Obj:run_blame(lines, lnum, ignore_whitespace)
function Obj:run_blame(lines, lnum, ignore_whitespace, detect_move_or_copy)
local ret = {} --- @type table<integer,Gitsigns.BlameInfo>

if not self.object_name or self.repo.abbrev_head == '' then
Expand Down Expand Up @@ -636,6 +637,10 @@ function Obj:run_blame(lines, lnum, ignore_whitespace)
args[#args + 1] = '-w'
end

if detect_move_or_copy ~= nil and detect_move_or_copy ~= '' then
args[#args + 1] = '-' .. detect_move_or_copy
end

local ignore_file = self.repo.toplevel .. '/.git-blame-ignore-revs'
if uv.fs_stat(ignore_file) then
vim.list_extend(args, { '--ignore-revs-file', ignore_file })
Expand Down