@@ -3,6 +3,7 @@ local config = require("diffview.config")
33local hl = require (" diffview.hl" )
44local utils = require (" diffview.utils" )
55
6+ local fmt = string.format
67local logger = DiffviewGlobal .logger
78local perf = PerfTimer (" [FileHistoryPanel] Render internal" )
89local pl = utils .path
@@ -15,23 +16,32 @@ local function render_files(comp, files)
1516 for i , file in ipairs (files ) do
1617 comp :add_text (i == # files and " └ " or " │ " , " DiffviewNonText" )
1718
18- if file .status then
19- comp :add_text (file .status .. " " , hl .get_git_hl (file .status ))
20- end
19+ if file :is_null_entry () then
20+ comp :add_text (
21+ " No diff" ,
22+ file .active and " DiffviewFilePanelSelected" or " DiffviewFilePanelFileName"
23+ )
24+ else
25+ if file .status then
26+ comp :add_text (file .status .. " " , hl .get_git_hl (file .status ))
27+ else
28+ comp :add_text (" -" .. " " , " DiffviewNonText" )
29+ end
2130
22- local icon , icon_hl = hl .get_file_icon (file .basename , file .extension )
23- comp :add_text (icon , icon_hl )
31+ local icon , icon_hl = hl .get_file_icon (file .basename , file .extension )
32+ comp :add_text (icon , icon_hl )
2433
25- if # file .parent_path > 0 then
26- comp :add_text (file .parent_path .. " /" , " DiffviewFilePanelPath" )
27- end
34+ if # file .parent_path > 0 then
35+ comp :add_text (file .parent_path .. " /" , " DiffviewFilePanelPath" )
36+ end
2837
29- comp :add_text (file .basename , file .active and " DiffviewFilePanelSelected" or " DiffviewFilePanelFileName" )
38+ comp :add_text (file .basename , file .active and " DiffviewFilePanelSelected" or " DiffviewFilePanelFileName" )
3039
31- if file .stats then
32- comp :add_text (" " .. file .stats .additions , " DiffviewFilePanelInsertions" )
33- comp :add_text (" , " )
34- comp :add_text (tostring (file .stats .deletions ), " DiffviewFilePanelDeletions" )
40+ if file .stats then
41+ comp :add_text (" " .. file .stats .additions , " DiffviewFilePanelInsertions" )
42+ comp :add_text (" , " )
43+ comp :add_text (tostring (file .stats .deletions ), " DiffviewFilePanelDeletions" )
44+ end
3545 end
3646
3747 comp :ln ()
4757local function render_entries (panel , parent , entries , updating )
4858 local c = config .get_config ()
4959 local max_num_files = - 1
50- local max_len_stats = 7
60+ local max_len_stats = - 1
5161
5262 for _ , entry in ipairs (entries ) do
5363 if # entry .files > max_num_files then
@@ -72,39 +82,60 @@ local function render_entries(panel, parent, entries, updating)
7282 end
7383
7484 local entry_struct = parent [i ]
75- local comp = entry_struct .commit .comp
85+ local comp = entry_struct .commit .comp --[[ @as RenderComponent ]]
7686
7787 if not entry .single_file then
7888 comp :add_text ((entry .folded and c .signs .fold_closed or c .signs .fold_open ) .. " " , " CursorLineNr" )
7989 end
8090
8191 if entry .status then
8292 comp :add_text (entry .status , hl .get_git_hl (entry .status ))
93+ else
94+ comp :add_text (" -" , " DiffviewNonText" )
8395 end
8496
8597 if not entry .single_file then
86- local counter = " "
87- .. utils .str_left_pad (tostring (# entry .files ), # tostring (max_num_files ))
88- .. (" file%s" ):format (# entry .files > 1 and " s" or " " )
89- comp :add_text (counter , " DiffviewFilePanelCounter" )
98+ local s_num_files = tostring (max_num_files )
99+
100+ if entry .nulled then
101+ comp :add_text (utils .str_center_pad (" empty" , # s_num_files + 7 ), " DiffviewFilePanelCounter" )
102+ else
103+ comp :add_text (
104+ fmt (
105+ " %s file%s" ,
106+ utils .str_left_pad (tostring (# entry .files ), # s_num_files ),
107+ # entry .files > 1 and " s" or " "
108+ ),
109+ " DiffviewFilePanelCounter"
110+ )
111+ end
90112 end
91113
92- if entry .stats then
93- local adds = tostring (entry .stats .additions )
94- local dels = tostring (entry .stats .deletions )
95- comp :add_text (" | " , " DiffviewNonText" )
96- comp :add_text (adds , " DiffviewFilePanelInsertions" )
97- comp :add_text (string.rep (" " , max_len_stats - (# adds + # dels )))
98- comp :add_text (dels , " DiffviewFilePanelDeletions" )
114+ if max_len_stats ~= - 1 then
115+ local adds = { " -" , " DiffviewNonText" }
116+ local dels = { " -" , " DiffviewNonText" }
117+
118+ if entry .stats and entry .stats .additions then
119+ adds = { tostring (entry .stats .additions ), " DiffviewFilePanelInsertions" }
120+ end
121+
122+ if entry .stats and entry .stats .deletions then
123+ dels = { tostring (entry .stats .deletions ), " DiffviewFilePanelDeletions" }
124+ end
125+
99126 comp :add_text (" | " , " DiffviewNonText" )
127+ comp :add_text (unpack (adds ))
128+ comp :add_text (string.rep (" " , max_len_stats - (# adds [1 ] + # dels [1 ])))
129+ comp :add_text (unpack (dels ))
130+ comp :add_text (" |" , " DiffviewNonText" )
100131 end
101132
102133 if entry .commit .hash then
103- comp :add_text (entry .commit .hash :sub (1 , 8 ) .. " " , " DiffviewSecondary" )
134+ comp :add_text (" " .. entry .commit .hash :sub (1 , 8 ), " DiffviewSecondary" )
104135 end
105136
106137 if entry .commit .ref_names then
107- comp :add_text ((" (%s) " ):format (entry .commit .ref_names ), " DiffviewReference" )
138+ comp :add_text ((" (%s)" ):format (entry .commit .ref_names ), " DiffviewReference" )
108139 end
109140
110141 local subject = utils .str_trunc (entry .commit .subject , 72 )
@@ -114,18 +145,18 @@ local function render_entries(panel, parent, entries, updating)
114145 end
115146
116147 comp :add_text (
117- subject .. " " ,
148+ " " .. subject ,
118149 panel .cur_item [1 ] == entry and " DiffviewFilePanelSelected" or " DiffviewFilePanelFileName"
119150 )
120151
121152 if entry .commit then
122153 -- 3 months
123154 local date = (
124- os.difftime (os.time (), entry .commit .time ) > 60 * 60 * 24 * 30 * 3
125- and entry .commit .iso_date
155+ os.difftime (os.time (), entry .commit .time ) > 60 * 60 * 24 * 30 * 3
156+ and entry .commit .iso_date
126157 or entry .commit .rel_date
127- )
128- comp :add_text (entry .commit .author .. " , " .. date , " DiffviewFilePanelPath" )
158+ )
159+ comp :add_text (" " .. entry .commit .author .. " , " .. date , " DiffviewFilePanelPath" )
129160 end
130161
131162 comp :ln ()
0 commit comments