]>
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 | ||
eae0bfdc PP |
10 | #include "common.h" |
11 | ||
e4af0f00 RB |
12 | #include "git2/oid.h" |
13 | ||
4ca0b566 VM |
14 | /** |
15 | * Format a git_oid into a newly allocated c-string. | |
16 | * | |
17 | * The c-string is owned by the caller and needs to be manually freed. | |
18 | * | |
19 | * @param id the oid structure to format | |
20 | * @return the c-string; NULL if memory is exhausted. Caller must | |
21 | * deallocate the string with git__free(). | |
22 | */ | |
23 | char *git_oid_allocfmt(const git_oid *id); | |
24 | ||
59547ce7 | 25 | GIT_INLINE(int) git_oid__hashcmp(const unsigned char *sha1, const unsigned char *sha2) |
e4af0f00 | 26 | { |
eae0bfdc | 27 | return memcmp(sha1, sha2, GIT_OID_RAWSZ); |
e4af0f00 RB |
28 | } |
29 | ||
59547ce7 VM |
30 | /* |
31 | * Compare two oid structures. | |
32 | * | |
33 | * @param a first oid structure. | |
34 | * @param b second oid structure. | |
35 | * @return <0, 0, >0 if a < b, a == b, a > b. | |
36 | */ | |
37 | GIT_INLINE(int) git_oid__cmp(const git_oid *a, const git_oid *b) | |
38 | { | |
39 | return git_oid__hashcmp(a->id, b->id); | |
40 | } | |
41 | ||
fa4b93a6 ET |
42 | GIT_INLINE(void) git_oid__cpy_prefix( |
43 | git_oid *out, const git_oid *id, size_t len) | |
44 | { | |
45 | memcpy(&out->id, id->id, (len + 1) / 2); | |
46 | ||
47 | if (len & 1) | |
48 | out->id[len / 2] &= 0xF0; | |
49 | } | |
50 | ||
e4af0f00 | 51 | #endif |