Skip to content

Commit 6baa30d

Browse files
committed
feat(file-history): Show ref-names in the history panel. (fixes #195)
1 parent 5798159 commit 6baa30d

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

lua/diffview/git/commit.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ local M = {}
1616
---@field time_offset number
1717
---@field date string
1818
---@field rel_date string
19+
---@field ref_names string
1920
---@field subject string
2021
---@field body string
2122
local Commit = oop.create_class("Commit")
@@ -25,6 +26,7 @@ function Commit:init(opt)
2526
self.author = opt.author
2627
self.time = opt.time
2728
self.rel_date = opt.rel_date
29+
self.ref_names = opt.ref_names ~= "" and opt.ref_names or nil
2830
self.subject = opt.subject
2931
self.body = opt.body
3032

lua/diffview/git/utils.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,9 @@ local function structure_fh_data(namestat_data, numstat_data)
589589
time = tonumber(time),
590590
time_offset = time_offset,
591591
rel_date = namestat_data[4],
592-
subject = namestat_data[5]:sub(3),
593-
namestat = utils.vec_slice(namestat_data, 6),
592+
ref_names = namestat_data[5]:sub(3),
593+
subject = namestat_data[6]:sub(3),
594+
namestat = utils.vec_slice(namestat_data, 7),
594595
numstat = numstat_data,
595596
}
596597
end
@@ -663,7 +664,7 @@ local incremental_fh_data = async.void(function(state, callback)
663664
git_args(),
664665
"log",
665666
rev_range,
666-
"--pretty=format:%x00%n%H %P%n%an%n%ad%n%ar%n %s",
667+
"--pretty=format:%x00%n%H %P%n%an%n%ad%n%ar%n %D%n %s",
667668
"--date=raw",
668669
"--name-status",
669670
state.prepared_log_opts.flags,
@@ -781,7 +782,7 @@ local incremental_line_trace_data = async.void(function(state, callback)
781782
rev_range,
782783
"--color=never",
783784
"--no-ext-diff",
784-
"--pretty=format:%x00%n%H %P%n%an%n%ad%n%ar%n %s",
785+
"--pretty=format:%x00%n%H %P%n%an%n%ad%n%ar%n %D%n %s",
785786
"--date=raw",
786787
state.prepared_log_opts.flags,
787788
"--"
@@ -1112,6 +1113,7 @@ local function file_history_worker(thread, ctx, log_opt, opt, co_state, callback
11121113
time = tonumber(state.cur.time),
11131114
time_offset = state.cur.time_offset,
11141115
rel_date = state.cur.rel_date,
1116+
ref_names = state.cur.ref_names,
11151117
subject = state.cur.subject,
11161118
})
11171119

lua/diffview/hl.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ M.hl_links = {
411411
FilePanelConflicts = "DiagnosticSignWarn",
412412
FolderName = "Directory",
413413
FolderSign = "PreProc",
414+
Reference = "Function",
414415
StatusAdded = "diffAdded",
415416
StatusUntracked = "diffAdded",
416417
StatusModified = "diffChanged",

lua/diffview/scene/views/file_history/render.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ local function render_entries(parent, entries, updating)
151151
s = s .. hash .. " "
152152
end
153153

154+
offset = #s
155+
if entry.commit.ref_names then
156+
local ref_names = ("(%s) "):format(entry.commit.ref_names)
157+
comp:add_hl("DiffviewReference", line_idx, offset, offset + #ref_names)
158+
s = s .. ref_names
159+
end
160+
154161
offset = #s
155162
local subject = utils.str_shorten(entry.commit.subject, 72)
156163
if subject == "" then

0 commit comments

Comments
 (0)