Skip to content

Commit 30ec2bb

Browse files
9999yearslewis6991
authored andcommitted
feat(actions.blame): add BlameOpts parameter
This makes the `blame` action match the `blame_line` action.
1 parent b2094c6 commit 30ec2bb

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

doc/gitsigns.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ change_base({base}, {global}, {callback?}) *gitsigns.change_base()*
283283
{base} (string|nil): The object/revision to diff against.
284284
{global} (boolean|nil): Change the base of all buffers.
285285

286-
blame({callback?}) *gitsigns.blame()*
286+
blame({opts}, {callback?}) *gitsigns.blame()*
287287
Run git-blame on the current file and open the results
288288
in a scroll-bound vertical split.
289289

@@ -298,6 +298,13 @@ blame({callback?}) *gitsigns.blame()*
298298
Attributes: ~
299299
{async}
300300

301+
Parameters: ~
302+
{opts} (table|nil): Additional options:
303+
• {ignore_whitespace}: (boolean)
304+
Ignore whitespace when running blame.
305+
• {extra_opts}: (string[])
306+
Extra options passed to `git-blame`.
307+
301308
blame_line({opts}, {callback?}) *gitsigns.blame_line()*
302309
Run git blame on the current line and show the results in a
303310
floating window. If already open, calling this will cause the

lua/gitsigns/actions.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,8 +642,14 @@ end
642642
---
643643
--- Attributes: ~
644644
--- {async}
645-
M.blame = async.create(0, function()
646-
require('gitsigns.actions.blame').blame()
645+
---
646+
--- @param opts table|nil Additional options:
647+
--- • {ignore_whitespace}: (boolean)
648+
--- Ignore whitespace when running blame.
649+
--- • {extra_opts}: (string[])
650+
--- Extra options passed to `git-blame`.
651+
M.blame = async.create(1, function(opts)
652+
require('gitsigns.actions.blame').blame(opts)
647653
end)
648654

649655
--- @async

lua/gitsigns/actions/blame.lua

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,12 @@ local function render(blame, win, main_win, buf_sha)
164164
end
165165

166166
--- @async
167+
--- @param opts Gitsigns.BlameOpts?
167168
--- @param blame table<integer,Gitsigns.BlameInfo?>
168169
--- @param win integer
169170
--- @param revision? string
170171
--- @param parent? boolean
171-
local function reblame(blame, win, revision, parent)
172+
local function reblame(opts, blame, win, revision, parent)
172173
local blm_win = api.nvim_get_current_win()
173174
local lnum = api.nvim_win_get_cursor(blm_win)[1]
174175
local sha = assert(blame[lnum]).commit.sha
@@ -187,7 +188,7 @@ local function reblame(blame, win, revision, parent)
187188
return
188189
end
189190
async.schedule()
190-
M.blame()
191+
M.blame(opts)
191192
end
192193

193194
--- @async
@@ -329,7 +330,8 @@ local function pmap(mode, lhs, cb, opts)
329330
end
330331

331332
--- @async
332-
function M.blame()
333+
--- @param opts Gitsigns.BlameOpts?
334+
function M.blame(opts)
333335
local __FUNC__ = 'blame'
334336
local bufnr = api.nvim_get_current_buf()
335337
local win = api.nvim_get_current_win()
@@ -339,7 +341,8 @@ function M.blame()
339341
return
340342
end
341343

342-
bcache:get_blame()
344+
local lnum = nil
345+
bcache:get_blame(lnum, opts)
343346
local blame = assert(bcache.blame)
344347

345348
-- Save position to align 'scrollbind'
@@ -406,7 +409,7 @@ function M.blame()
406409
})
407410

408411
pmap('n', 'r', function()
409-
async.run(reblame, blame.entries, win, bcache.git_obj.revision):raise_on_error()
412+
async.run(reblame, opts, blame.entries, win, bcache.git_obj.revision):raise_on_error()
410413
end, {
411414
desc = 'Reblame at commit',
412415
buffer = blm_bufnr,
@@ -420,7 +423,7 @@ function M.blame()
420423
})
421424

422425
pmap('n', 'R', function()
423-
async.run(reblame, blame.entries, win, bcache.git_obj.revision, true):raise_on_error()
426+
async.run(reblame, opts, blame.entries, win, bcache.git_obj.revision, true):raise_on_error()
424427
end, {
425428
desc = 'Reblame at commit parent',
426429
buffer = blm_bufnr,

0 commit comments

Comments
 (0)