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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
May 2, 2018 at 00:25 UTC
d8a92ced62f758fedad95a192978b910b1cc498a
2 files changed
+15
cache.h
+3
@@ -1049,6 +1049,9 @@ static inline int is_empty_tree_oid(const struct object_id *oid)
1049
return !oidcmp(oid, the_hash_algo->empty_tree);
1050
}
1051
1052
+const char *empty_tree_oid_hex(void);
1053
+const char *empty_blob_oid_hex(void);
1054
+
1055
/* set default permissions by passing mode arguments to open(2) */
1056
int git_mkstemps_mode(char *pattern, int suffix_len, int mode);
1057
int git_mkstemp_mode(char *pattern, int mode);
sha1_file.c
+12
@@ -100,6 +100,18 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
100
},
101
};
102
103
+const char *empty_tree_oid_hex(void)
104
+{
105
+ static char buf[GIT_MAX_HEXSZ + 1];
106
+ return oid_to_hex_r(buf, the_hash_algo->empty_tree);
107
+}
108
+
109
+const char *empty_blob_oid_hex(void)
110
+{
111
+ static char buf[GIT_MAX_HEXSZ + 1];
112
+ return oid_to_hex_r(buf, the_hash_algo->empty_blob);
113
+}
114
+
115
/*
116
* This is meant to hold a *small* number of objects that you would
117
* want read_sha1_file() to be able to return, but yet you do not want