Repository navigation
Expand file tree
/
Copy pathgit.lua
More file actions
95 lines (77 loc) · 2.45 KB
/
Copy pathgit.lua
File metadata and controls
95 lines (77 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
local log = require('gitgraph.log')
local config = require('gitgraph').config
local M = {}
---@class I.RawCommit
---@field hash string
---@field parents string[]
---@field msg string
---@field branch_names string[]
---@field tags string[]
---@field author_date string
---@field author_name string
---@param args I.GitLogArgs
---@param date_format string
---@return I.RawCommit[]
function M.git_log_pretty(args, date_format)
local start = os.clock()
-- you cannot use both all and range at the same time
if args.all and args.revision_range then
args.revision_range = nil
end
local cli = config.git_cmd .. [[ log %s %s --pretty="%s" --date="%s" %s %s --date-order]]
local cli_args = {
args.revision_range or '', -- revision range
args.all and '--all' or '', -- all branches?
-- 'format:%s%x00(%D)%x00%ad%x00%an%x00%H%x00%P', -- format makes it easy to extract info
'format:%s%x00(%D)%x00%ad%x00%an%x00%h%x00%p', -- format makes it easy to extract info
'format:' .. date_format, -- date format
args.max_count and ('--max-count=%d'):format(args.max_count) or '', -- max count
args.skip and ('--skip=%d'):format(args.skip) or '', -- skip
}
local git_cmd = (cli):format(unpack(cli_args))
local io_handle = io.popen(git_cmd)
if not io_handle then
log.error('FATAL: no io handle to git_cmd result')
return {}
end
---@type string
local git_cmd_out = io_handle:read('*a')
io_handle:close()
---@type I.RawCommit[]
local data = {}
for line in git_cmd_out:gmatch('[^\r\n]+') do
local iter = line:gmatch('([^%z]+)')
local msg = iter()
local describers = iter():gsub('[%(%)]', '') -- tags, branch names etc
local author_date = iter()
local author_name = iter()
local hash = iter()
local parent_iter = (iter() or ''):gmatch('[^%s]+')
local branch_names = {}
local tags = {}
for desc in describers:gsub(', ', '\0'):gmatch('[^%z]+') do
if desc:match('tag:.+') then
tags[#tags + 1] = desc
else
branch_names[#branch_names + 1] = desc
end
end
local parents = {}
for p in parent_iter do
parents[#parents + 1] = p
end
data[#data + 1] = {
msg = msg,
branch_names = branch_names,
tags = tags,
author_date = author_date,
author_name = author_name,
hash = hash,
parents = parents,
}
end
local dur = os.clock() - start
log.info('cli duration:', dur * 1000, 'ms')
return data
end
return M