Skip to content

Commit d8a92ce

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f6d27d2 commit d8a92ce

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

cache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,9 @@ static inline int is_empty_tree_oid(const struct object_id *oid)
10491049
return !oidcmp(oid, the_hash_algo->empty_tree);
10501050
}
10511051

1052+
const char *empty_tree_oid_hex(void);
1053+
const char *empty_blob_oid_hex(void);
1054+
10521055
/* set default permissions by passing mode arguments to open(2) */
10531056
int git_mkstemps_mode(char *pattern, int suffix_len, int mode);
10541057
int git_mkstemp_mode(char *pattern, int mode);

sha1_file.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
100100
},
101101
};
102102

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+
103115
/*
104116
* This is meant to hold a *small* number of objects that you would
105117
* want read_sha1_file() to be able to return, but yet you do not want

0 commit comments

Comments
 (0)