commit 1edd802a51791f31eb7971ff570bbeeb817d8311
parent 1ec569fd785a1fb9b4addf0eccd0d291e57a8287
Author: Chris Bracken <chris@bracken.jp>
Date: Fri, 20 Feb 2026 17:05:53 +0900
git: add support for SHA256
SHA1 requires 40 bytes for the hexadecimal representation.
SHA256 requires 64 bytes.
libgit2 has a nice handy GIT_OID_MAX_HEXSIZE for this so we can
future-proof a bit.
Diffstat:
3 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/git/commit.c b/src/git/commit.c
@@ -10,6 +10,7 @@
#include <git2/types.h>
#include <stdlib.h>
+#include "git/git.h"
#include "git/internal.h"
#include "utils.h"
@@ -23,11 +24,11 @@ GitCommit* gitcommit_create(const git_oid* oid, git_repository* repo) {
}
// Get OID, parent OID.
- commit->oid = ecalloc(GIT_OID_SHA1_HEXSIZE + 1, sizeof(char));
- git_oid_tostr(commit->oid, GIT_OID_SHA1_HEXSIZE + 1, git_commit_id(gcommit));
+ commit->oid = ecalloc(kOidLen, sizeof(char));
+ git_oid_tostr(commit->oid, kOidLen, git_commit_id(gcommit));
if (git_commit_parentcount(gcommit) > 0) {
- commit->parentoid = ecalloc(GIT_OID_SHA1_HEXSIZE + 1, sizeof(char));
- git_oid_tostr(commit->parentoid, GIT_OID_SHA1_HEXSIZE + 1,
+ commit->parentoid = ecalloc(kOidLen, sizeof(char));
+ git_oid_tostr(commit->parentoid, kOidLen,
git_commit_parent_id(gcommit, 0));
} else {
commit->parentoid = NULL;
diff --git a/src/git/commit_tests.c b/src/git/commit_tests.c
@@ -72,7 +72,7 @@ UTEST_F(git_commit_test, CommitParentHandling) {
ASSERT_NE(NULL, child);
ASSERT_NE(NULL, child->parentoid);
- char root_oid_str[GIT_OID_SHA1_HEXSIZE + 1];
+ char root_oid_str[GIT_OID_MAX_HEXSIZE + 1];
git_oid_tostr(root_oid_str, sizeof(root_oid_str), &commit_id);
EXPECT_STREQ(root_oid_str, child->parentoid);
EXPECT_STREQ("Child commit", child->summary);
diff --git a/src/git/git.c b/src/git/git.c
@@ -12,7 +12,7 @@
#include "utils.h"
/* Global const data. */
-const size_t kOidLen = GIT_OID_SHA1_HEXSIZE + 1;
+const size_t kOidLen = GIT_OID_MAX_HEXSIZE + 1;
/* Maximum file size to load into memory, in bytes. */
static const ssize_t kMaxFileSizeBytes = 16 * 1024 * 1024;
@@ -364,7 +364,7 @@ static bool gitrepo_walk_tree_files(git_repository* repo,
git_filemode_t mode = git_tree_entry_filemode(entry);
if (mode == GIT_FILEMODE_COMMIT) {
- char oid_str[GIT_OID_SHA1_HEXSIZE + 1];
+ char oid_str[kOidLen];
git_oid_tostr(oid_str, sizeof(oid_str), git_tree_entry_id(entry));
GitFile* fileinfo =
gitfile_create(kFileTypeSubmodule, "m---------", entrypath,