diff options
author | Aki <please@ignore.pl> | 2024-02-09 22:37:40 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2024-02-09 22:38:46 +0100 |
commit | 0d372922aec1213fc90e48c835eeec2acc3aadb0 (patch) | |
tree | 31485aedb42a216a0a3230c8f6031a46f7e71e22 | |
parent | 9b1f5d2b5554c0ff9f355866d4669b3ffcaa3686 (diff) | |
download | activity-0d372922aec1213fc90e48c835eeec2acc3aadb0.zip activity-0d372922aec1213fc90e48c835eeec2acc3aadb0.tar.gz activity-0d372922aec1213fc90e48c835eeec2acc3aadb0.tar.bz2 |
Added options to filter by author or committer
-rw-r--r-- | activity/git.lua | 27 | ||||
-rwxr-xr-x | generate.lua | 17 |
2 files changed, 37 insertions, 7 deletions
diff --git a/activity/git.lua b/activity/git.lua index 978dfec..160d227 100644 --- a/activity/git.lua +++ b/activity/git.lua @@ -2,16 +2,19 @@ local dates = require "activity.dates" local git = {} -function git.log (dirname, entries) +function git.log (dirname, entries, filter) 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)) + local handle = io.popen(([[git -C %s log --all --format="%%aE;%%cE;%%as"]]):format(dirname)) for line in handle:lines() do - local email, year, month, day = line:match"([^;]*);(%d+)%-(%d+)%-(%d+)" + local author, committer, 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}) + local entry = {author=author, committer=committer, date=date} + if not filter or filter(entry) then + table.insert(entries, entry) + end end local ok, _ = handle:close() if not ok then @@ -21,11 +24,11 @@ function git.log (dirname, entries) end -function git.lookup (repositories) +function git.lookup (repositories, filter) local lookup = {} local entries = {} for _, dirname in pairs(repositories) do - git.log(dirname, entries) + git.log(dirname, entries, filter) end for _, entry in pairs(entries) do local day = dates.day_of_year(entry.date) @@ -39,4 +42,16 @@ function git.lookup (repositories) end +function git.any_value_filter (member, values) + return function (entry) + for _, value in pairs(values) do + if entry[member] == value then + return true + end + end + return false + end +end + + return git diff --git a/generate.lua b/generate.lua index 478bc9d..bc46585 100755 --- a/generate.lua +++ b/generate.lua @@ -4,6 +4,8 @@ Generates activity chart -f (string default 'ansi') Output format of the chart -y (optional number) Year of the chart -R Generate rolling chart + -A... (optional string) Author e-mail addresses to include in chart + -C... (optional string) Committer e-mail addresses to include in chart <repos...> (optional string) Paths to repositories with activity ]] local generators = require "activity.generators" @@ -18,4 +20,17 @@ local maybe_year = args.y if args.R then maybe_year = "rolling" end -io.write(generators.generate_table(maybe_year, git.lookup(args.repos), maybe_format)) +local filter, by_author, by_committer +if #args.A > 0 then + by_author = git.any_value_filter("author", args.A) +end +if #args.C > 0 then + by_committer = git.any_value_filter("committer", args.C) +end +if by_committer and by_author then + function filter (entry) + return by_author(entry) or by_committer(entry) + end +end +filter = filter or by_author or by_committer +io.write(generators.generate_table(maybe_year, git.lookup(args.repos, filter), maybe_format)) |