oid: introduce `git_oid_raw_cpy` Now that oids are type-aware, they use their type to understand how many bytes to copy. Some callers may need to copy the raw bytes of the object id. This is equivalent to a memcpy that is a little more semantic.
diff --git a/src/libgit2/oid.c b/src/libgit2/oid.c
index 9a21aac..fb92174 100644
--- a/src/libgit2/oid.c
+++ b/src/libgit2/oid.c
@@ -187,8 +187,7 @@ int git_oid_fromraw(git_oid *out, const unsigned char *raw)
int git_oid_cpy(git_oid *out, const git_oid *src)
{
- memcpy(out->id, src->id, sizeof(out->id));
- return 0;
+ return git_oid_raw_cpy(out->id, src->id);
}
int git_oid_cmp(const git_oid *a, const git_oid *b)
diff --git a/src/libgit2/oid.h b/src/libgit2/oid.h
index bce0a27..abae9a4 100644
--- a/src/libgit2/oid.h
+++ b/src/libgit2/oid.h
@@ -55,6 +55,14 @@ GIT_INLINE(int) git_oid_raw_cmp(
return memcmp(sha1, sha2, GIT_OID_RAWSZ);
}
+GIT_INLINE(int) git_oid_raw_cpy(
+ unsigned char *dst,
+ const unsigned char *src)
+{
+ memcpy(dst, src, GIT_OID_RAWSZ);
+ return 0;
+}
+
/*
* Compare two oid structures.
*