summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2022-01-21 19:08:26 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2022-01-22 17:36:30 -0500
commit3b7725a4990c71fd94094d5078fdc49226b59e68 (patch)
tree651153e95fb70bc8e5a45c515565628610ff810c
parentbc9558ddaa6bd7c63c6b8d878d9a501d8cbaf594 (diff)
downloadlibgit2-3b7725a4990c71fd94094d5078fdc49226b59e68.tar.gz
oid: introduce git_oid_raw
We make frequent use of an oid structure that assumes that it's simply 20 bytes of raw data. This will certainly not always be the case. Provide a raw type that is 20 bytes of raw data, so that our public- facing `git_oid` type can be more flexible and possibly learn a type annotation that indicates its size.
-rw-r--r--src/oid.h10
-rw-r--r--tests/object/raw/size.c6
2 files changed, 15 insertions, 1 deletions
diff --git a/src/oid.h b/src/oid.h
index 84231ffca..e1a29ed53 100644
--- a/src/oid.h
+++ b/src/oid.h
@@ -12,6 +12,16 @@
#include "git2/oid.h"
/**
+ * A "raw" object ID without any additional metadata like the type.
+ *
+ * This is useful for internal-facing data structures like commit
+ * graphs and indexes.
+ */
+typedef struct git_oid_raw {
+ unsigned char id[GIT_OID_RAWSZ];
+} git_oid_raw;
+
+/**
* Format a git_oid into a newly allocated c-string.
*
* The c-string is owned by the caller and needs to be manually freed.
diff --git a/tests/object/raw/size.c b/tests/object/raw/size.c
index 930c6de23..df25ab427 100644
--- a/tests/object/raw/size.c
+++ b/tests/object/raw/size.c
@@ -2,12 +2,16 @@
#include "clar_libgit2.h"
#include "odb.h"
+#include "oid.h"
void test_object_raw_size__validate_oid_size(void)
{
git_oid out;
+ git_oid_raw raw;
+
cl_assert(20 == GIT_OID_RAWSZ);
cl_assert(40 == GIT_OID_HEXSZ);
- cl_assert(sizeof(out) == GIT_OID_RAWSZ);
cl_assert(sizeof(out.id) == GIT_OID_RAWSZ);
+ cl_assert(sizeof(raw) == GIT_OID_RAWSZ);
+ cl_assert(sizeof(raw.id) == GIT_OID_RAWSZ);
}