Skip to content

Commit 3218c2d

Browse files
committed
feat: git log
1 parent 54d5ff1 commit 3218c2d

File tree

7 files changed

+82
-5
lines changed

7 files changed

+82
-5
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tt.lua

lua/lazy/manager.lua

+11
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ function M.run(operation, opts, filter)
5353
runner:add(Task.new(plugin, "run"))
5454
end
5555
plugin.dirty = false
56+
if operation == "update" then
57+
runner:add(Task.new(plugin, "log"))
58+
end
5659
end
5760
-- wait for post-install to finish
5861
runner:wait(on_done)
@@ -85,6 +88,14 @@ function M.update(opts)
8588
end)
8689
end
8790

91+
---@param opts? ManagerOpts
92+
function M.log(opts)
93+
---@param plugin LazyPlugin
94+
M.run("log", opts, function(plugin)
95+
return plugin.uri and plugin.installed
96+
end)
97+
end
98+
8899
---@param opts? ManagerOpts
89100
function M.clean(opts)
90101
opts = opts or {}

lua/lazy/task.lua

+24-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local Util = require("lazy.util")
88
---@field running boolean
99
local Task = {}
1010

11-
---@alias TaskType "update"|"install"|"run"|"clean"
11+
---@alias TaskType "update"|"install"|"run"|"clean"|"log"
1212

1313
---@param plugin LazyPlugin
1414
---@param type TaskType
@@ -27,7 +27,6 @@ end
2727

2828
function Task:_done()
2929
self.running = false
30-
3130
vim.cmd("do User LazyRender")
3231
end
3332

@@ -54,7 +53,7 @@ function Task:clean()
5453
end
5554

5655
self.plugin.installed = false
57-
self.running = false
56+
self:_done()
5857
end
5958

6059
function Task:install()
@@ -161,14 +160,36 @@ function Task:start()
161160
self:run()
162161
elseif self.type == "clean" then
163162
self:clean()
163+
elseif self.type == "log" then
164+
self:log()
164165
end
165166
end)
166167

167168
if not ok then
168169
self.error = err or "failed"
170+
self:_done()
171+
end
172+
end
169173

174+
function Task:log()
175+
if not Util.file_exists(self.plugin.dir .. "/.git") then
170176
self:_done()
177+
return
171178
end
179+
180+
local args = {
181+
"log",
182+
"--pretty=format:%h %s (%cr)",
183+
"--abbrev-commit",
184+
"--decorate",
185+
"--date=short",
186+
"--color=never",
187+
"--since='7 days ago'",
188+
}
189+
self:spawn("git", {
190+
args = args,
191+
cwd = self.plugin.dir,
192+
})
172193
end
173194

174195
function Task:update()
@@ -180,7 +201,6 @@ function Task:update()
180201
})
181202
vim.opt.runtimepath:append(self.plugin.uri)
182203
end
183-
184204
self:_done()
185205
else
186206
local args = {

lua/lazy/view/commands.lua

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ M.commands = {
2121
install = function()
2222
Manager.install({ clear = true, show = true })
2323
end,
24+
log = function()
25+
Manager.log({ clear = true, show = true })
26+
end,
2427
show = function()
2528
View.show()
2629
end,

lua/lazy/view/render.lua

+19
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,25 @@ function M:plugin(plugin)
119119
self:nl()
120120
end
121121
end
122+
elseif task.type == "log" then
123+
local log = vim.trim(task.output)
124+
if log ~= "" then
125+
local lines = vim.split(log, "\n")
126+
for l, line in ipairs(lines) do
127+
if l == 1 then
128+
self:nl()
129+
end
130+
local ref, msg, time = line:match("^(%w+) (.*) (%(.*%))$")
131+
self:append(" " .. ref .. " ", "@variable.builtin")
132+
local col = self:col()
133+
self:append(msg)
134+
-- string.gsub
135+
self:append(" " .. time, "Comment")
136+
if l ~= #lines then
137+
self:nl()
138+
end
139+
end
140+
end
122141
end
123142
end
124143
end

lua/lazy/view/sections.lua

+8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ return {
5151
end,
5252
title = "Running",
5353
},
54+
{
55+
filter = function(plugin)
56+
return has_task(plugin, function(task)
57+
return task.type == "log" and vim.trim(task.output) ~= ""
58+
end)
59+
end,
60+
title = "Log",
61+
},
5462
{
5563
filter = function(plugin)
5664
return plugin.installed and not plugin.uri

lua/lazy/view/text.lua

+16-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function Text.new()
1616
end
1717

1818
---@param str string
19-
---@param hl string|table
19+
---@param hl? string|table
2020
function Text:append(str, hl)
2121
if #self._lines == 0 then
2222
self:nl()
@@ -84,4 +84,19 @@ function Text:trim()
8484
end
8585
end
8686

87+
function Text:row()
88+
return #self._lines == 0 and 1 or #self._lines
89+
end
90+
91+
function Text:col()
92+
if #self._lines == 0 then
93+
return 0
94+
end
95+
local width = 0
96+
for _, segment in ipairs(self._lines[#self._lines]) do
97+
width = width + vim.fn.strlen(segment.str)
98+
end
99+
return width
100+
end
101+
87102
return Text

0 commit comments

Comments
 (0)