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

perf(blame): general improvements #878

Merged
merged 4 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions doc/gitsigns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ For basic setup with all batteries included:

Configuration can be passed to the setup function. Here is an example with most
of the default settings:
>
>lua
require('gitsigns').setup {
signs = {
add = { text = '│' },
Expand Down Expand Up @@ -98,7 +98,7 @@ setup({cfg}) *gitsigns.setup()*
{async}

Parameters: ~
{cfg} (table): Configuration for Gitsigns.
{cfg} (table|nil): Configuration for Gitsigns.
See |gitsigns-usage| for more details.

attach({bufnr}, {ctx}) *gitsigns.attach()*
Expand Down Expand Up @@ -200,7 +200,7 @@ show({revision}) *gitsigns.show()*
If {base} is the index, then the opened buffer is editable and
any written changes will update the index accordingly.

Examples: >
Examples: >vim
" View the index version of the file
:Gitsigns show

Expand All @@ -221,7 +221,7 @@ diffthis({base}, {opts}) *gitsigns.diffthis()*
If {base} is the index, then the opened buffer is editable and
any written changes will update the index accordingly.

Examples: >
Examples: >vim
" Diff against the index
:Gitsigns diffthis

Expand Down Expand Up @@ -261,7 +261,7 @@ change_base({base}, {global}) *gitsigns.change_base()*
Attributes: ~
{async}

Examples: >
Examples: >vim
" Change base to 1 commit behind head
:lua require('gitsigns').change_base('HEAD~1')

Expand Down Expand Up @@ -537,7 +537,7 @@ worktrees *gitsigns-config-worktrees*
If normal attaching fails, then each entry in the table is attempted
with the work tree details set.

Example: >
Example: >lua
worktrees = {
{
toplevel = vim.env.HOME,
Expand All @@ -553,7 +553,7 @@ on_attach *gitsigns-config-on_attach*

This callback can return `false` to prevent attaching to the buffer.

Example: >
Example: >lua
on_attach = function(bufnr)
if vim.api.nvim_buf_get_name(bufnr):match(<PATTERN>) then
-- Don't attach to specific buffers whose name matches a pattern
Expand Down Expand Up @@ -828,6 +828,7 @@ current_line_blame_formatter *gitsigns-config-current_line_blame_formatter*
• `summary`: string
• `previous`: string
• `filename`: string
• `boundary`: true?

Note that the keys map onto the output of:
`git blame --line-porcelain`
Expand Down
2 changes: 1 addition & 1 deletion etc/doc_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ For basic setup with all batteries included:

Configuration can be passed to the setup function. Here is an example with most
of the default settings:
>
>lua
{{SETUP}}
<

Expand Down
16 changes: 9 additions & 7 deletions lua/gitsigns/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -808,12 +808,12 @@ M.get_hunks = function(bufnr)
end

--- @param repo Gitsigns.Repo
--- @param info Gitsigns.BlameInfo
--- @param info Gitsigns.BlameInfoPublic
--- @return Gitsigns.Hunk.Hunk?, integer?, integer
local function get_blame_hunk(repo, info)
local a = {}
-- If no previous so sha of blame added the file
if info.previous then
if info.previous_sha and info.previous_filename then
a = repo:get_show_text(info.previous_sha .. ':' .. info.previous_filename)
end
local b = repo:get_show_text(info.sha .. ':' .. info.filename)
Expand Down Expand Up @@ -884,12 +884,14 @@ M.blame_line = async.void(function(opts)
local buftext = util.buf_lines(bufnr)
local fileformat = vim.bo[bufnr].fileformat
local lnum = api.nvim_win_get_cursor(0)[1]
local result = bcache.git_obj:run_blame(buftext, lnum, opts.ignore_whitespace)
local results = bcache.git_obj:run_blame(buftext, lnum, opts.ignore_whitespace)
pcall(function()
loading:close()
end)

assert(result)
assert(results and results[lnum])

local result = util.convert_blame_info(results[lnum])

local is_committed = result.sha and tonumber('0x' .. result.sha) ~= 0

Expand Down Expand Up @@ -927,7 +929,7 @@ end
--- Attributes: ~
--- {async}
---
--- Examples: >
--- Examples: >vim
--- " Change base to 1 commit behind head
--- :lua require('gitsigns').change_base('HEAD~1')
---
Expand Down Expand Up @@ -995,7 +997,7 @@ end
--- If {base} is the index, then the opened buffer is editable and
--- any written changes will update the index accordingly.
---
--- Examples: >
--- Examples: >vim
--- " Diff against the index
--- :Gitsigns diffthis
---
Expand Down Expand Up @@ -1064,7 +1066,7 @@ CP.diffthis = complete_heads
--- If {base} is the index, then the opened buffer is editable and
--- any written changes will update the index accordingly.
---
--- Examples: >
--- Examples: >vim
--- " View the index version of the file
--- :Gitsigns show
---
Expand Down
1 change: 1 addition & 0 deletions lua/gitsigns/attach.lua
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ local attach_throttled = throttle_by_id(function(cbuf, ctx, aucmd)
end

cache[cbuf] = CacheEntry.new({
bufnr = cbuf,
base = ctx and ctx.base or config.base,
file = file,
commit = commit,
Expand Down
1 change: 1 addition & 0 deletions lua/gitsigns/cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local M = {
-- Timer object watching the gitdir

--- @class Gitsigns.CacheEntry
--- @field bufnr integer
--- @field file string
--- @field base? string
--- @field compare_text? string[]
Expand Down
7 changes: 4 additions & 3 deletions lua/gitsigns/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ M.schema = {
If normal attaching fails, then each entry in the table is attempted
with the work tree details set.

Example: >
Example: >lua
worktrees = {
{
toplevel = vim.env.HOME,
Expand All @@ -265,7 +265,7 @@ M.schema = {
This callback must call its callback argument. The callback argument can
accept an optional table argument with the keys: 'gitdir' and 'toplevel'.

Example: >
Example: >lua
on_attach_pre = function(bufnr, callback)
...
callback {
Expand All @@ -286,7 +286,7 @@ M.schema = {

This callback can return `false` to prevent attaching to the buffer.

Example: >
Example: >lua
on_attach = function(bufnr)
if vim.api.nvim_buf_get_name(bufnr):match(<PATTERN>) then
-- Don't attach to specific buffers whose name matches a pattern
Expand Down Expand Up @@ -658,6 +658,7 @@ M.schema = {
• `summary`: string
• `previous`: string
• `filename`: string
• `boundary`: true?

Note that the keys map onto the output of:
`git blame --line-porcelain`
Expand Down
Loading
Loading