From 2e4dc676034c7753c455e7018145e0a1891fe5c0 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 31 Aug 2023 23:12:05 +0200 Subject: Implemented naive email based git log reader --- activity/git.lua | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 activity/git.lua diff --git a/activity/git.lua b/activity/git.lua new file mode 100644 index 0000000..2054835 --- /dev/null +++ b/activity/git.lua @@ -0,0 +1,45 @@ +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 function ensure (target, member, default) + if target[member] == nil then + target[member] = default + end + return target[member] + end + + for _, dirname in pairs(repositories) do + for _, entry in pairs(git.log(dirname)) do + local year = ensure(lookup, entry.date.year, {}) + local month = ensure(year, entry.date.month, {}) + local day = ensure(month, entry.date.day, {}) + day[entry.email] = ensure(day, entry.email, 0) + 1 + end + end + return lookup -- TODO: Days of year by year as the format: {year={[1]=1, [2]=1, [3]=6, ...}, ...} +end + + +return git -- cgit v1.1