]>
Commit | Line | Data |
---|---|---|
e4af0f00 RB |
1 | /* |
2 | * Copyright (C) the libgit2 contributors. All rights reserved. | |
3 | * | |
4 | * This file is part of libgit2, distributed under the GNU GPL v2 with | |
5 | * a Linking Exception. For full terms see the included COPYING file. | |
6 | */ | |
7 | #ifndef INCLUDE_oid_h__ | |
8 | #define INCLUDE_oid_h__ | |
9 | ||
10 | #include "git2/oid.h" | |
11 | ||
4ca0b566 VM |
12 | /** |
13 | * Format a git_oid into a newly allocated c-string. | |
14 | * | |
15 | * The c-string is owned by the caller and needs to be manually freed. | |
16 | * | |
17 | * @param id the oid structure to format | |
18 | * @return the c-string; NULL if memory is exhausted. Caller must | |
19 | * deallocate the string with git__free(). | |
20 | */ | |
21 | char *git_oid_allocfmt(const git_oid *id); | |
22 | ||
59547ce7 | 23 | GIT_INLINE(int) git_oid__hashcmp(const unsigned char *sha1, const unsigned char *sha2) |
e4af0f00 | 24 | { |
e4af0f00 RB |
25 | int i; |
26 | ||
27 | for (i = 0; i < GIT_OID_RAWSZ; i++, sha1++, sha2++) { | |
28 | if (*sha1 != *sha2) | |
29 | return *sha1 - *sha2; | |
30 | } | |
31 | ||
32 | return 0; | |
33 | } | |
34 | ||
59547ce7 VM |
35 | /* |
36 | * Compare two oid structures. | |
37 | * | |
38 | * @param a first oid structure. | |
39 | * @param b second oid structure. | |
40 | * @return <0, 0, >0 if a < b, a == b, a > b. | |
41 | */ | |
42 | GIT_INLINE(int) git_oid__cmp(const git_oid *a, const git_oid *b) | |
43 | { | |
44 | return git_oid__hashcmp(a->id, b->id); | |
45 | } | |
46 | ||
e4af0f00 | 47 | #endif |