From 7350d609085a23a011a613fdec1a2ae2757a1f02 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Thu, 03 Apr 2025 15:35:05 +0800 Subject: [PATCH] git2d: Clean up commit author date/etc handling, and add email --- git2d/main.c | 26 ++++++++++++++------------ diff --git a/git2d/main.c b/git2d/main.c index a7956955404ceb0d952e70d9e1cdd3be253dc6af..5301a67470f4483032df3505ff90be2681310ac0 100644 --- a/git2d/main.c +++ b/git2d/main.c @@ -152,13 +152,6 @@ break; const char *msg = git_commit_summary(commit); const git_signature *author = git_commit_author(commit); - time_t time = git_commit_time(commit); - char timebuf[64]; - struct tm *tm = localtime(&time); - if (tm) - strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm); - else - strcpy(timebuf, "unknown"); /* ID */ bare_put_data(&writer, oid.id, GIT_OID_RAWSZ); @@ -167,14 +160,23 @@ /* Title */ size_t msg_len = msg ? strlen(msg) : 0; bare_put_data(&writer, (const uint8_t *)(msg ? msg : ""), msg_len); - /* Author */ + /* Author's name */ const char *author_name = author ? author->name : ""; - size_t author_len = strlen(author_name); - bare_put_data(&writer, (const uint8_t *)author_name, author_len); + bare_put_data(&writer, (const uint8_t *)author_name, strlen(author_name)); + + /* Author's email */ + const char *author_email = author ? author->email : ""; + bare_put_data(&writer, (const uint8_t *)author_email, strlen(author_email)); /* Author's date */ - size_t time_len = strlen(timebuf); - bare_put_data(&writer, (const uint8_t *)timebuf, time_len); + time_t time = git_commit_time(commit); + char timebuf[64]; + struct tm *tm = localtime(&time); + if (tm) + strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm); + else + strcpy(timebuf, "unknown"); + bare_put_data(&writer, (const uint8_t *)timebuf, strlen(timebuf)); git_commit_free(commit); count++; -- 2.48.1