diff --git a/doc/gitsigns.txt b/doc/gitsigns.txt index 120157f00..96656d33b 100644 --- a/doc/gitsigns.txt +++ b/doc/gitsigns.txt @@ -302,6 +302,8 @@ blame_line({opts}) *gitsigns.blame_line()* Display full commit message with hunk. • {ignore_whitespace}: (boolean) Ignore whitespace when running blame. + • {hide_hunks}: (boolean) + Do not show hunks when running with full = true. Attributes: ~ {async} diff --git a/lua/gitsigns/actions.lua b/lua/gitsigns/actions.lua index 11e3cb38d..533c1d35e 100644 --- a/lua/gitsigns/actions.lua +++ b/lua/gitsigns/actions.lua @@ -45,6 +45,7 @@ local current_buf = api.nvim_get_current_buf + local M = {QFListOpts = {}, } @@ -842,7 +843,7 @@ local function get_blame_hunk(repo, info) return hunk, i, #hunks end -local function create_blame_fmt(is_committed, full) +local function create_blame_fmt(is_committed, full, hide_hunks) if not is_committed then return { { { '', 'Label' } }, @@ -856,12 +857,32 @@ local function create_blame_fmt(is_committed, full) { ':', 'NormalFloat' }, } + local body = { + { '', 'NormalFloat' }, + } + + local hunk_header = { + { 'Hunk of ', 'Title' }, + { ' ', 'LineNr' }, + } + + local hunk = { + { '', 'NormalFloat' }, + } + if full then + if hide_hunks then + return { + header, + body, + } + end + return { header, - { { '', 'NormalFloat' } }, - { { 'Hunk of ', 'Title' }, { ' ', 'LineNr' } }, - { { '', 'NormalFloat' } }, + body, + hunk_header, + hunk, } end @@ -882,6 +903,8 @@ end --- Display full commit message with hunk. --- • {ignore_whitespace}: (boolean) --- Ignore whitespace when running blame. +--- • {hide_hunks}: (boolean) +--- Do not show hunks when running with full = true. --- --- Attributes: ~ --- {async} @@ -911,20 +934,24 @@ M.blame_line = void(function(opts) local is_committed = result.sha and tonumber('0x' .. result.sha) ~= 0 - local blame_fmt = create_blame_fmt(is_committed, opts.full) + local blame_fmt = create_blame_fmt(is_committed, opts.full, opts.hide_hunks) local info = result if is_committed and opts.full then info.body = bcache.git_obj:command({ 'show', '-s', '--format=%B', result.sha }) - local hunk + if opts.hide_hunks then + table.remove(info.body) + else + local hunk - hunk, info.hunk_no, info.num_hunks = get_blame_hunk(bcache.git_obj.repo, result) + hunk, info.hunk_no, info.num_hunks = get_blame_hunk(bcache.git_obj.repo, result) - info.hunk = gs_hunks.patch_lines(hunk, fileformat) - info.hunk_head = hunk.head - insert_hunk_hlmarks(blame_fmt, hunk) + info.hunk = gs_hunks.patch_lines(hunk, fileformat) + info.hunk_head = hunk.head + insert_hunk_hlmarks(blame_fmt, hunk) + end end scheduler() diff --git a/teal/gitsigns/actions.tl b/teal/gitsigns/actions.tl index af4c1f466..9f3849896 100644 --- a/teal/gitsigns/actions.tl +++ b/teal/gitsigns/actions.tl @@ -37,6 +37,7 @@ end local record BlameOpts full: boolean ignore_whitespace: boolean + hide_hunks: boolean end local record StageHunkOpts @@ -842,7 +843,7 @@ local function get_blame_hunk(repo: git.Repo, info: git.BlameInfo): Hunk, intege return hunk, i, #hunks end -local function create_blame_fmt(is_committed: boolean, full: boolean): popup.LinesSpec +local function create_blame_fmt(is_committed: boolean, full: boolean, hide_hunks: boolean): popup.LinesSpec if not is_committed then return { {{'', 'Label'}}, @@ -856,12 +857,32 @@ local function create_blame_fmt(is_committed: boolean, full: boolean): popup.Lin {':', 'NormalFloat'} } + local body = { + {'', 'NormalFloat'} + } + + local hunk_header = { + {'Hunk of ', 'Title'}, + {' ', 'LineNr'} + } + + local hunk = { + {'', 'NormalFloat'} + } + if full then + if hide_hunks then + return { + header, + body + } + end + return { header, - {{'', 'NormalFloat'}}, - {{'Hunk of ', 'Title'}, {' ', 'LineNr'}}, - {{'', 'NormalFloat'}} + body, + hunk_header, + hunk } end @@ -882,6 +903,8 @@ end --- Display full commit message with hunk. --- • {ignore_whitespace}: (boolean) --- Ignore whitespace when running blame. +--- • {hide_hunks}: (boolean) +--- Do not show hunks when running with full = true. --- --- Attributes: ~ --- {async} @@ -911,20 +934,24 @@ M.blame_line = void(function(opts: BlameOpts) local is_committed = result.sha and tonumber('0x'..result.sha) ~= 0 - local blame_fmt = create_blame_fmt(is_committed, opts.full) + local blame_fmt = create_blame_fmt(is_committed, opts.full, opts.hide_hunks) local info = result as util.FmtInfo if is_committed and opts.full then info.body = bcache.git_obj:command{ 'show', '-s', '--format=%B', result.sha } as string - local hunk: Hunk + if opts.hide_hunks then + table.remove(info.body as {string}) + else + local hunk: Hunk - hunk, info.hunk_no, info.num_hunks = get_blame_hunk(bcache.git_obj.repo, result) + hunk, info.hunk_no, info.num_hunks = get_blame_hunk(bcache.git_obj.repo, result) - info.hunk = gs_hunks.patch_lines(hunk, fileformat) - info.hunk_head = hunk.head - insert_hunk_hlmarks(blame_fmt, hunk) + info.hunk = gs_hunks.patch_lines(hunk, fileformat) + info.hunk_head = hunk.head + insert_hunk_hlmarks(blame_fmt, hunk) + end end scheduler()