blob: c1219adbfabf83e366e4640529af4b6fcd034302 (
plain)
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
|
local dates = require "activity.dates"
local git = {}
function git.log (dirname, entries)
entries = entries or {}
if not dirname then
error "did not provide repo"
end
local handle = io.popen(([[git -C %s log --format="%%aE;%%as"]]):format(dirname))
for line in handle:lines() do
local email, year, month, day = line:match"([^;]*);(%d+)%-(%d+)%-(%d+)"
local date = {year=tonumber(year), month=tonumber(month), day=tonumber(day)}
table.insert(entries, {email=email, date=date})
end
local ok, _ = handle:close()
if not ok then
error "git log closed unexpectedly"
end
return entries
end
function git.lookup (repositories)
local lookup = {}
local entries = {}
for _, dirname in pairs(repositories) do
git.log(dirname, entries)
end
for _, entry in pairs(entries) do
local day = dates.day_of_year(entry.date)
local year = entry.date.year
lookup[year] = lookup[year] or {}
lookup[year][day] = (lookup[year][day] or 0) + 1
end
return lookup
end
return git
|