@@ -2,7 +2,9 @@ local Ui = require("neogit.lib.ui")
22local Component = require (" neogit.lib.ui.component" )
33local util = require (" neogit.lib.util" )
44local common = require (" neogit.buffers.common" )
5+ local config = require (" neogit.config" )
56local a = require (" plenary.async" )
7+ local state = require (" neogit.lib.state" )
68
79local col = Ui .col
810local row = Ui .row
@@ -323,7 +325,7 @@ local SectionItemCommit = Component.new(function(item)
323325 local ref = {}
324326 local ref_last = {}
325327
326- if item .commit .ref_name ~= " " then
328+ if item .commit .ref_name ~= " " and state . get ({ " NeogitMarginPopup " , " decorate " }, true ) then
327329 -- Render local only branches first
328330 for name , _ in pairs (item .decoration .locals ) do
329331 if name :match (" ^refs/" ) then
@@ -359,6 +361,79 @@ local SectionItemCommit = Component.new(function(item)
359361 end
360362 end
361363
364+ local virtual_text
365+
366+ -- Render author and date in margin, if visible
367+ if state .get ({ " margin" , " visibility" }, false ) then
368+ local margin_date_style = state .get ({ " margin" , " date_style" }, 1 )
369+ local details = state .get ({ " margin" , " details" }, false )
370+
371+ local date
372+ local rel_date
373+ local date_width = 10
374+ local clamp_width = 30 -- to avoid having too much space when relative date is short
375+
376+ -- Render date
377+ if item .commit .rel_date :match (" years?," ) then
378+ rel_date , _ = item .commit .rel_date :gsub (" years?," , " y" )
379+ rel_date = rel_date .. " "
380+ elseif item .commit .rel_date :match (" ^%d " ) then
381+ rel_date = " " .. item .commit .rel_date
382+ else
383+ rel_date = item .commit .rel_date
384+ end
385+
386+ if margin_date_style == 1 then -- relative date (short)
387+ local unpacked = vim .split (rel_date , " " )
388+
389+ -- above, we added a space if the rel_date started with a single number
390+ -- we get the last two elements to deal with that
391+ local date_number = unpacked [# unpacked - 1 ]
392+ local date_quantifier = unpacked [# unpacked ]
393+ if date_quantifier :match (" months?" ) then
394+ date_quantifier = date_quantifier :gsub (" m" , " M" ) -- to distinguish from minutes
395+ end
396+
397+ -- add back the space if we have a single number
398+ local left_pad
399+ if # unpacked > 2 then
400+ left_pad = " "
401+ else
402+ left_pad = " "
403+ end
404+
405+ date = left_pad .. date_number .. date_quantifier :sub (1 , 1 )
406+ date_width = 3
407+ clamp_width = 23
408+ elseif margin_date_style == 2 then -- relative date (long)
409+ date = rel_date
410+ date_width = 10
411+ else -- local iso date
412+ if config .values .log_date_format == nil then
413+ -- we get the unix date to be able to convert the date to the local timezone
414+ date = os.date (" %Y-%m-%d %H:%M" , item .commit .unix_date )
415+ date_width = 16 -- TODO: what should the width be here?
416+ else
417+ date = item .commit .log_date
418+ date_width = 16
419+ end
420+ end
421+
422+ local author_table = { " " }
423+ if details then
424+ author_table = {
425+ util .str_clamp (item .commit .author_name , clamp_width - (# date > date_width and # date or date_width )),
426+ " NeogitGraphAuthor" ,
427+ }
428+ end
429+
430+ virtual_text = {
431+ { " " , " Constant" },
432+ author_table ,
433+ { util .str_min_width (date , date_width ), " Special" },
434+ }
435+ end
436+
362437 return row (
363438 util .merge (
364439 { text .highlight (" NeogitObjectId" )(item .commit .abbreviated_commit ) },
@@ -367,7 +442,12 @@ local SectionItemCommit = Component.new(function(item)
367442 ref_last ,
368443 { text (item .commit .subject ) }
369444 ),
370- { oid = item .commit .oid , yankable = item .commit .oid , item = item }
445+ {
446+ virtual_text = virtual_text ,
447+ oid = item .commit .oid ,
448+ yankable = item .commit .oid ,
449+ item = item ,
450+ }
371451 )
372452end )
373453
0 commit comments