|
Packit |
ae9e2a |
/*
|
|
Packit |
ae9e2a |
* Copyright (C) the libgit2 contributors. All rights reserved.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
|
Packit |
ae9e2a |
* a Linking Exception. For full terms see the included COPYING file.
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
#ifndef INCLUDE_oid_h__
|
|
Packit |
ae9e2a |
#define INCLUDE_oid_h__
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
#include "git2/oid.h"
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* Format a git_oid into a newly allocated c-string.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* The c-string is owned by the caller and needs to be manually freed.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* @param id the oid structure to format
|
|
Packit |
ae9e2a |
* @return the c-string; NULL if memory is exhausted. Caller must
|
|
Packit |
ae9e2a |
* deallocate the string with git__free().
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
char *git_oid_allocfmt(const git_oid *id);
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
GIT_INLINE(int) git_oid__hashcmp(const unsigned char *sha1, const unsigned char *sha2)
|
|
Packit |
ae9e2a |
{
|
|
Packit |
ae9e2a |
int i;
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
for (i = 0; i < GIT_OID_RAWSZ; i++, sha1++, sha2++) {
|
|
Packit |
ae9e2a |
if (*sha1 != *sha2)
|
|
Packit |
ae9e2a |
return *sha1 - *sha2;
|
|
Packit |
ae9e2a |
}
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
return 0;
|
|
Packit |
ae9e2a |
}
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/*
|
|
Packit |
ae9e2a |
* Compare two oid structures.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* @param a first oid structure.
|
|
Packit |
ae9e2a |
* @param b second oid structure.
|
|
Packit |
ae9e2a |
* @return <0, 0, >0 if a < b, a == b, a > b.
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
GIT_INLINE(int) git_oid__cmp(const git_oid *a, const git_oid *b)
|
|
Packit |
ae9e2a |
{
|
|
Packit |
ae9e2a |
return git_oid__hashcmp(a->id, b->id);
|
|
Packit |
ae9e2a |
}
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
GIT_INLINE(void) git_oid__cpy_prefix(
|
|
Packit |
ae9e2a |
git_oid *out, const git_oid *id, size_t len)
|
|
Packit |
ae9e2a |
{
|
|
Packit |
ae9e2a |
memcpy(&out->id, id->id, (len + 1) / 2);
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
if (len & 1)
|
|
Packit |
ae9e2a |
out->id[len / 2] &= 0xF0;
|
|
Packit |
ae9e2a |
}
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
#endif
|