libgit-thin: Introduces git_revlist_show_merges()
[git/libgit-gsoc.git] / libgit-thin / ltsha1.c
blobbb3af49605310efbb6ae7153eecf274ea77b0e4d
1 /**
2 * @file
3 *
4 * SHA-1 handling related functions
6 * Luiz Fernando N. Capitulino
7 * <lcapitulino@gmail.com>
8 */
9 #include <string.h>
10 #include <errno.h>
12 #include <cache.h>
14 #include "ltsha1.h"
16 /**
17 * Convert a 40-byte hexadecimal string SHA1 representation into
18 * a (raw) 20 byte sequence.
20 * \param hex hexdecimal string to be converted
21 * \param sha1 20-byte array to return the conversion result into
23 * \return 0 on success, -1 otherwise.
25 int git_hex_to_sha1(const char *hex, unsigned char *sha1)
27 if (!hex || !sha1) {
28 errno = EINVAL;
29 return -1;
32 return get_sha1_hex(hex, sha1);
35 /**
36 * Convert a (raw) 20-byte SHA1 sequence into a 40-byte hexadecimal
37 * string representation.
39 * \param sha1 20-byte SHA1 array to be converted
40 * \param hex 41-byte array to be filled with the 40-byte hexadecimal
41 * representation plus the trailing \\0 character
43 * \return 0 on success, -1 otherwise.
45 int git_sha1_to_hex(const unsigned char *sha1, char *hex)
47 char *p;
49 if (!sha1 || !hex) {
50 errno = EINVAL;
51 return -1;
54 p = sha1_to_hex(sha1);
55 if (!p)
56 return -1;
58 strncpy(hex, p, GIT_HEX_LENGTH+1);
59 return 0;