Skip to content

Commit

Permalink
Log updated packages commits titles.
Browse files Browse the repository at this point in the history
  • Loading branch information
wviana authored and savq committed May 1, 2022
1 parent b0954c1 commit c945152
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions lua/paq.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ local function new_counter()
end)
end

local function call_proc(process, args, cwd, cb)
local function call_proc(process, args, cwd, cb, print_stdout)
local log = uv.fs_open(LOGFILE, "a+", 0x1A4)
local stderr = uv.new_pipe(false)
stderr:open(log)
local handle, pid
handle, pid = uv.spawn(
process,
{ args = args, cwd = cwd, stdio = { nil, nil, stderr }, env = env },
{ args = args, cwd = cwd, stdio = { nil, print_stdout and stderr, stderr }, env = env },
vim.schedule_wrap(function(code)
uv.fs_close(log)
stderr:close()
Expand All @@ -73,6 +73,12 @@ local function call_proc(process, args, cwd, cb)
end
end

local function log(message)
local log = uv.fs_open(LOGFILE, "a+", 0x1A4)
uv.fs_write(log, message .. '\n')
uv.fs_close(log)
end

local function run_hook(pkg, counter, sync)
local t = type(pkg.run)
if t == "function" then
Expand Down Expand Up @@ -125,15 +131,20 @@ local function get_git_hash(dir)
end

local function pull(pkg, counter, sync)
local hash = get_git_hash(pkg.dir)
local prev_hash = get_git_hash(pkg.dir)
call_proc("git", { "pull", "--recurse-submodules", "--update-shallow" }, pkg.dir, function(ok)
if not ok then
counter(pkg.name, "err", sync)
elseif get_git_hash(pkg.dir) ~= hash then
pkg.status = "updated"
return pkg.run and run_hook(pkg, counter, sync) or counter(pkg.name, "ok", sync)
else
counter(pkg.name, "nop", sync)
local cur_hash = get_git_hash(pkg.dir)
if cur_hash ~= prev_hash then
log(pkg.name .. " updating...")
call_proc("git", { "log", "--pretty=format:* %s", prev_hash .. ".." .. cur_hash }, pkg.dir, function(ok) end, true)
pkg.status = "updated"
return pkg.run and run_hook(pkg, counter, sync) or counter(pkg.name, "ok", sync)
else
counter(pkg.name, "nop", sync)
end
end
end)
end
Expand Down

0 comments on commit c945152

Please sign in to comment.