diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2022-01-22 08:48:43 -0500 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2022-04-10 15:56:57 -0400 |
| commit | 9ffa33a1a39cdee6d1a86fedb797cd30e69529a4 (patch) | |
| tree | 0884949756e85e3063404937b36af00c4066b8ae /src | |
| parent | 6d8c7cabd6c0435cc7d05380d766a6e0483df67c (diff) | |
| download | libgit2-9ffa33a1a39cdee6d1a86fedb797cd30e69529a4.tar.gz | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libgit2/oid.c | 3 | ||||
| -rw-r--r-- | src/libgit2/oid.h | 8 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/libgit2/oid.c b/src/libgit2/oid.c index 9a21aac29..fb92174ab 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 bce0a27b9..abae9a4b2 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. * |
