Skip to content

Commit

Permalink
feat(blame): add rev option to blame_line()
Browse files Browse the repository at this point in the history
Resolves #952
  • Loading branch information
lewis6991 committed Apr 3, 2024
1 parent 50577f0 commit 0994d89
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
2 changes: 2 additions & 0 deletions doc/gitsigns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ blame_line({opts}, {callback?}) *gitsigns.blame_line()*
Display full commit message with hunk.
• {ignore_whitespace}: (boolean)
Ignore whitespace when running blame.
{rev}: (string)
Revision to blame against.

get_hunks({bufnr}) *gitsigns.get_hunks()*
Get hunk array for specified buffer.
Expand Down
5 changes: 4 additions & 1 deletion lua/gitsigns/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -898,11 +898,14 @@ end
--- Display full commit message with hunk.
--- • {ignore_whitespace}: (boolean)
--- Ignore whitespace when running blame.
--- • {rev}: (string)
--- Revision to blame against.
M.blame_line = async.create(1, function(opts)
if popup.focus_open('blame') then
return
end

--- @type Gitsigns.LineBlameOpts
opts = opts or {}

local bufnr = current_buf()
Expand All @@ -926,7 +929,7 @@ M.blame_line = async.create(1, function(opts)
loading:close()
end)

if not api.nvim_buf_is_valid(bufnr) then
if not manager.schedule(bufnr) then
return
end

Expand Down
9 changes: 7 additions & 2 deletions lua/gitsigns/cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ local BLAME_THRESHOLD_LEN = 1000000

--- @private
--- @param lnum integer
--- @param opts Gitsigns.CurrentLineBlameOpts
--- @param opts Gitsigns.BlameOpts
--- @return table<integer,Gitsigns.BlameInfo?>?
function CacheEntry:run_blame(lnum, opts)
local bufnr = self.bufnr
Expand Down Expand Up @@ -124,9 +124,14 @@ local function get_blame_nc(file, lnum)
end

--- @param lnum integer
--- @param opts Gitsigns.CurrentLineBlameOpts
--- @param opts Gitsigns.BlameOpts
--- @return Gitsigns.BlameInfo?
function CacheEntry:get_blame(lnum, opts)
if opts.rev then
local buftext = util.buf_lines(self.bufnr)
return self.git_obj:run_blame(buftext, lnum, opts.ignore_whitespace)[lnum]
end

local blame_cache = self.blame

if not blame_cache or not blame_cache[lnum] then
Expand Down
24 changes: 15 additions & 9 deletions lua/gitsigns/config.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
--- @class (exact) Gitsigns.SchemaElem.Deprecated
---
--- Used for renaming fields.
--- @field new_field string
--- @field new_field? string
---
--- Documentation for deprecation. Will be added to the help file and used in
--- the notification if `hard = true`.
--- @field message string
--- @field message? string
---
--- Emit a message via vim.notify
--- @field hard boolean
--- @field hard? boolean

--- @class (exact) Gitsigns.SchemaElem
--- @field type string|string[]
Expand Down Expand Up @@ -50,12 +50,18 @@

--- @alias Gitsigns.CurrentLineBlameFmtFun fun(user: string, info: table<string,any>, opts: Gitsigns.CurrentLineBlameFmtOpts): {[1]:string,[2]:string}[]

--- @class (exact) Gitsigns.CurrentLineBlameOpts
--- @field virt_text boolean
--- @field virt_text_pos 'eol'|'overlay'|'right_align'
--- @field delay integer
--- @field ignore_whitespace boolean
--- @field virt_text_priority integer
--- @class (exact) Gitsigns.CurrentLineBlameOpts : Gitsigns.BlameOpts
--- @field virt_text? boolean
--- @field virt_text_pos? 'eol'|'overlay'|'right_align'
--- @field delay? integer
--- @field virt_text_priority? integer

--- @class (exact) Gitsigns.BlameOpts
--- @field ignore_whitespace? boolean
--- @field rev? string

--- @class (exact) Gitsigns.LineBlameOpts : Gitsigns.BlameOpts
--- @field full? boolean

--- @class (exact) Gitsigns.Config
--- @field debug_mode boolean
Expand Down
2 changes: 1 addition & 1 deletion lua/gitsigns/diffthis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ local function bufread(bufnr, dbufnr, base)

local modifiable = vim.bo[dbufnr].modifiable
vim.bo[dbufnr].modifiable = true
Status:update(dbufnr, {head = comp_rev})
Status:update(dbufnr, { head = comp_rev })

util.set_lines(dbufnr, 0, -1, text)

Expand Down

0 comments on commit 0994d89

Please sign in to comment.