]>
git.proxmox.com Git - libgit2.git/blob - src/oid.h
2 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
7 #ifndef INCLUDE_oid_h__
8 #define INCLUDE_oid_h__
15 * Format a git_oid into a newly allocated c-string.
17 * The c-string is owned by the caller and needs to be manually freed.
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().
23 char *git_oid_allocfmt(const git_oid
*id
);
25 GIT_INLINE(int) git_oid__hashcmp(const unsigned char *sha1
, const unsigned char *sha2
)
27 return memcmp(sha1
, sha2
, GIT_OID_RAWSZ
);
31 * Compare two oid structures.
33 * @param a first oid structure.
34 * @param b second oid structure.
35 * @return <0, 0, >0 if a < b, a == b, a > b.
37 GIT_INLINE(int) git_oid__cmp(const git_oid
*a
, const git_oid
*b
)
39 return git_oid__hashcmp(a
->id
, b
->id
);
42 GIT_INLINE(void) git_oid__cpy_prefix(
43 git_oid
*out
, const git_oid
*id
, size_t len
)
45 memcpy(&out
->id
, id
->id
, (len
+ 1) / 2);
48 out
->id
[len
/ 2] &= 0xF0;