summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-08-31 23:12:05 +0200
committerAki <please@ignore.pl>2023-08-31 23:12:05 +0200
commit2e4dc676034c7753c455e7018145e0a1891fe5c0 (patch)
tree844b8b838488b4f09777cb08703fa2acea284971
parent2170ddb2079d1dc4f529094268c47f3e35aa84e3 (diff)
downloadactivity-2e4dc676034c7753c455e7018145e0a1891fe5c0.zip
activity-2e4dc676034c7753c455e7018145e0a1891fe5c0.tar.gz
activity-2e4dc676034c7753c455e7018145e0a1891fe5c0.tar.bz2
Implemented naive email based git log reader
-rw-r--r--activity/git.lua45
1 files changed, 45 insertions, 0 deletions
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