Blame src/oid.h

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