Git fork
1#include "unit-test.h"
2#include "lib-oid.h"
3#include "strbuf.h"
4#include "hex.h"
5
6int cl_setup_hash_algo(void)
7{
8 static int algo = -1;
9
10 if (algo < 0) {
11 const char *algo_name = getenv("GIT_TEST_DEFAULT_HASH");
12 algo = algo_name ? hash_algo_by_name(algo_name) : GIT_HASH_SHA1;
13
14 cl_assert(algo != GIT_HASH_UNKNOWN);
15 }
16 return algo;
17}
18
19static void cl_parse_oid(const char *hex, struct object_id *oid,
20 const struct git_hash_algo *algop)
21{
22 size_t sz = strlen(hex);
23 struct strbuf buf = STRBUF_INIT;
24
25 cl_assert(sz <= algop->hexsz);
26
27 strbuf_add(&buf, hex, sz);
28 strbuf_addchars(&buf, '0', algop->hexsz - sz);
29
30 cl_assert_equal_i(get_oid_hex_algop(buf.buf, oid, algop), 0);
31
32 strbuf_release(&buf);
33}
34
35
36void cl_parse_any_oid(const char *hex, struct object_id *oid)
37{
38 int hash_algo = cl_setup_hash_algo();
39
40 cl_assert(hash_algo != GIT_HASH_UNKNOWN);
41 cl_parse_oid(hex, oid, &hash_algos[hash_algo]);
42}