Skip to content

Commit c50b280

Browse files
committed
oid: provide an oid type to hash type map
We intentionally separate oid types from hash types; a hash is a generic hunk of bytes, an object id has meaning and backs an object on disk. As a result of this separation, we need a 1:1 mapping.
1 parent 1479806 commit c50b280

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/libgit2/oid.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "common.h"
1111

1212
#include "git2/oid.h"
13+
#include "hash.h"
1314

1415
#define GIT_OID_NONE { 0, { 0 } }
1516

@@ -40,6 +41,18 @@ GIT_INLINE(size_t) git_oid_hexsize(git_oid_t type)
4041
return 0;
4142
}
4243

44+
GIT_INLINE(git_hash_algorithm_t) git_oid_algorithm(git_oid_t type)
45+
{
46+
switch (type) {
47+
case GIT_OID_SHA1:
48+
return GIT_HASH_ALGORITHM_SHA1;
49+
case GIT_OID_SHA256:
50+
return GIT_HASH_ALGORITHM_SHA256;
51+
}
52+
53+
return 0;
54+
}
55+
4356
/**
4457
* Format a git_oid into a newly allocated c-string.
4558
*

0 commit comments

Comments
 (0)