forked from mpg/git-info
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-info-helper-l.lua
executable file
·75 lines (67 loc) · 1.83 KB
/
git-info-helper-l.lua
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
#!/usr/bin/env texlua
-- Helper script for git-info
progname = 'git-info-helper-l'
usage = 'Usage: '..arg[0]..' [filename]';
filename = 'git-info.gih'
-- parse arguments
function parse_args()
local n = 0
if arg[1] then
filename = arg[1]
n = 1
end
if #arg > n then
print(usage)
os.exit(1)
end
end
-- return the lines outputed by 'cmd'
function os.capturelines(cmd)
local stream = assert(io.popen(cmd, 'r'))
local lines = {}
for line in stream:lines() do
table.insert(lines, line)
end
stream:close()
return lines
end
do -- restrict the scope of the following variables
-- git commands
local git_ls_tree = 'git ls-tree -r --name-only HEAD'
local git_log = "git log -1 --pretty=format:'%H%n%ct%n%ci%n%ce%n%cn%n' "
-- get the list of files and their informations
function read_file_infos()
local files_infos = {}
local files = os.capturelines(git_ls_tree)
for _, file in ipairs(files) do
local infos = os.capturelines(git_log .. file)
table.insert(files_infos, {
name = file,
commit = infos[1],
timestamp = infos[2],
isodate = infos[3],
mail = infos[4],
author = infos[5],
})
end
return files_infos
end
end -- scope of git_<command>
-- write the list of files and their informations in 'files' to 'outfile'
function write_file_infos(files, outfile)
local out = assert(io.open(outfile, 'w'))
for _, file in ipairs(files) do
out:write(
file.name, '\n',
file.commit, '\n',
file.timestamp, '\n',
file.isodate, '\n',
file.mail, '\n',
file.author, '\n\n')
end
out:close()
end
-- main
parse_args()
write_file_infos(read_file_infos(), filename)
os.exit(0)