commit-heatmap-gen

commit heatmap generator
git clone git://brookjeynes.dev/bjeynes/commit-heatmap-gen.git
Log | Files | Refs | README

commit 8ff234c24d132d371aa89b497aacf5ffaa9a1152
parent 2e1164be74a2a69f59973a6572b22f36f2479b8e
Author: brookjeynes <me@brookjeynes.dev>
Date:   Thu, 18 Jun 2026 08:33:39 +1000

feat: commits per day

Signed-off-by: brookjeynes <me@brookjeynes.dev>

Diffstat:
Mmain.c | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 64 insertions(+), 4 deletions(-)

diff --git a/main.c b/main.c @@ -5,6 +5,11 @@ #include <string.h> #include <time.h> +typedef struct { + char date[11]; // "YYYY-MM-DD\0" + int count; +} commits_by_date; + int main(int argc, char *argv[]) { int error; @@ -12,9 +17,11 @@ int main(int argc, char *argv[]) { fprintf(stderr, "err: author email required\n"); exit(1); } - char *author_email = argv[1]; + commits_by_date commit_tracker[365]; + int unique_dates = 0; + git_libgit2_init(); git_repository *repo = NULL; @@ -60,18 +67,71 @@ int main(int argc, char *argv[]) { exit(error); } - const char *message = git_commit_message(commit); const git_signature *author = git_commit_author(commit); + if (strcmp(author_email, author->email) != 0) { + continue; + } + if (author->when.time < year_behind) { break; } - if (strcmp(author_email, author->email) == 0) { - printf("%s <%s> -> %s\n", author->name, author->email, message); + struct tm *lt; + char buf[11]; + + lt = localtime(&author->when.time); + if (strftime(buf, sizeof(buf), "%Y-%m-%d", lt) == 0) { + fprintf(stderr, "err: failed to get print time\n"); + exit(1); + } + + int found = 0; + for (int j = 0; j < unique_dates; j++) { + if (strcmp(commit_tracker[j].date, buf) == 0) { + commit_tracker[j].count++; + found = 1; + break; + } + } + + if (found == 0) { + if (unique_dates < 365) { + strcpy(commit_tracker[unique_dates].date, buf); + commit_tracker[unique_dates].count = 1; + unique_dates++; + } } } + time_t curr_day = now; + while (curr_day > year_behind) { + struct tm *lt; + char buf[11]; + + lt = localtime(&curr_day); + if (strftime(buf, sizeof(buf), "%Y-%m-%d", lt) == 0) { + fprintf(stderr, "err: failed to get print time\n"); + exit(1); + } + + int found = -1; + for (int j = 0; j < unique_dates; j++) { + if (strcmp(commit_tracker[j].date, buf) == 0) { + found = j; + break; + } + } + + if (found == -1) { + printf("%s: 0\n", buf); + } else { + printf("%s: %d\n", buf, commit_tracker[found].count); + } + + curr_day -= (24 * 60 * 60); + } + git_libgit2_shutdown(); return 0;