From d8a92ced62f758fedad95a192978b910b1cc498a Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Wed, 2 May 2018 00:25:54 +0000 Subject: [PATCH] sha1-file: add functions for hex empty tree and blob OIDs Oftentimes, we'll want to refer to an empty tree or empty blob by its hex name without having to call oid_to_hex or explicitly refer to the_hash_algo. Add helper functions that format these values into static buffers and return them for easy use. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- cache.h | 3 +++ sha1_file.c | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/cache.h b/cache.h index 9ad1dd2ddc3c39..14690c84a277a0 100644 --- a/cache.h +++ b/cache.h @@ -1049,6 +1049,9 @@ static inline int is_empty_tree_oid(const struct object_id *oid) return !oidcmp(oid, the_hash_algo->empty_tree); } +const char *empty_tree_oid_hex(void); +const char *empty_blob_oid_hex(void); + /* set default permissions by passing mode arguments to open(2) */ int git_mkstemps_mode(char *pattern, int suffix_len, int mode); int git_mkstemp_mode(char *pattern, int mode); diff --git a/sha1_file.c b/sha1_file.c index 4328c6128566d4..11598b43eba73f 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -100,6 +100,18 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = { }, }; +const char *empty_tree_oid_hex(void) +{ + static char buf[GIT_MAX_HEXSZ + 1]; + return oid_to_hex_r(buf, the_hash_algo->empty_tree); +} + +const char *empty_blob_oid_hex(void) +{ + static char buf[GIT_MAX_HEXSZ + 1]; + return oid_to_hex_r(buf, the_hash_algo->empty_blob); +} + /* * This is meant to hold a *small* number of objects that you would * want read_sha1_file() to be able to return, but yet you do not want