Skip to content

Commit

Permalink
feat: support git blame -C option
Browse files Browse the repository at this point in the history
  • Loading branch information
andrhua committed Mar 11, 2024
1 parent 2c2463d commit 8d9ae82
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lua/gitsigns/cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ 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 ~= '' 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

0 comments on commit 8d9ae82

Please sign in to comment.