Skip to content

Commit 8576fde

Browse files
jacob-kellergitster
authored andcommitted
cache: add empty_tree_oid object and helper function
Similar to is_null_oid(), and is_empty_blob_sha1() add an empty_tree_oid along with helper function is_empty_tree_oid(). For completeness, also add an "is_empty_tree_sha1()", "is_empty_blob_sha1()", "is_empty_tree_oid()" and "is_empty_blob_oid()" helpers. To ensure we only get one singleton, implement EMPTY_BLOB_SHA1_BIN as simply getting the hash of empty_blob_oid structure. Signed-off-by: Jacob Keller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a42d7b6 commit 8576fde

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

cache.h

+21-4
Original file line numberDiff line numberDiff line change
@@ -953,22 +953,39 @@ static inline void oidclr(struct object_id *oid)
953953
#define EMPTY_TREE_SHA1_BIN_LITERAL \
954954
"\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" \
955955
"\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04"
956-
#define EMPTY_TREE_SHA1_BIN \
957-
((const unsigned char *) EMPTY_TREE_SHA1_BIN_LITERAL)
956+
extern const struct object_id empty_tree_oid;
957+
#define EMPTY_TREE_SHA1_BIN (empty_tree_oid.hash)
958958

959959
#define EMPTY_BLOB_SHA1_HEX \
960960
"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
961961
#define EMPTY_BLOB_SHA1_BIN_LITERAL \
962962
"\xe6\x9d\xe2\x9b\xb2\xd1\xd6\x43\x4b\x8b" \
963963
"\x29\xae\x77\x5a\xd8\xc2\xe4\x8c\x53\x91"
964-
#define EMPTY_BLOB_SHA1_BIN \
965-
((const unsigned char *) EMPTY_BLOB_SHA1_BIN_LITERAL)
964+
extern const struct object_id empty_blob_oid;
965+
#define EMPTY_BLOB_SHA1_BIN (empty_blob_oid.hash)
966+
966967

967968
static inline int is_empty_blob_sha1(const unsigned char *sha1)
968969
{
969970
return !hashcmp(sha1, EMPTY_BLOB_SHA1_BIN);
970971
}
971972

973+
static inline int is_empty_blob_oid(const struct object_id *oid)
974+
{
975+
return !hashcmp(oid->hash, EMPTY_BLOB_SHA1_BIN);
976+
}
977+
978+
static inline int is_empty_tree_sha1(const unsigned char *sha1)
979+
{
980+
return !hashcmp(sha1, EMPTY_TREE_SHA1_BIN);
981+
}
982+
983+
static inline int is_empty_tree_oid(const struct object_id *oid)
984+
{
985+
return !hashcmp(oid->hash, EMPTY_TREE_SHA1_BIN);
986+
}
987+
988+
972989
int git_mkstemp(char *path, size_t n, const char *template);
973990

974991
/* set default permissions by passing mode arguments to open(2) */

sha1_file.c

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ static inline uintmax_t sz_fmt(size_t s) { return s; }
3838

3939
const unsigned char null_sha1[20];
4040
const struct object_id null_oid;
41+
const struct object_id empty_tree_oid = {
42+
EMPTY_TREE_SHA1_BIN_LITERAL
43+
};
44+
const struct object_id empty_blob_oid = {
45+
EMPTY_BLOB_SHA1_BIN_LITERAL
46+
};
4147

4248
/*
4349
* This is meant to hold a *small* number of objects that you would

0 commit comments

Comments
 (0)