Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/unit-tests/lib-oid.c # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / unit-tests / lib-oid.c` 42 lines ยท 913 bytes Raw Blame History 1 #include "unit-test.h" 2 #include "lib-oid.h" 3 #include "strbuf.h" 4 #include "hex.h" 5 6 int 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 19 static 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 36 void 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 }