Skip to content

Commit f8582ca

Browse files
peffgitster
authored andcommitted
make is_empty_blob_sha1 available everywhere
The read-cache implementation defines this static function, but it is a generally useful concept in git. Let's give the empty blob the same treatment as the empty tree, providing both hex and binary forms of the sha1. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cba595b commit f8582ca

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

cache.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,19 @@ static inline void hashclr(unsigned char *hash)
708708
#define EMPTY_TREE_SHA1_BIN \
709709
((const unsigned char *) EMPTY_TREE_SHA1_BIN_LITERAL)
710710

711+
#define EMPTY_BLOB_SHA1_HEX \
712+
"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
713+
#define EMPTY_BLOB_SHA1_BIN_LITERAL \
714+
"\xe6\x9d\xe2\x9b\xb2\xd1\xd6\x43\x4b\x8b" \
715+
"\x29\xae\x77\x5a\xd8\xc2\xe4\x8c\x53\x91"
716+
#define EMPTY_BLOB_SHA1_BIN \
717+
((const unsigned char *) EMPTY_BLOB_SHA1_BIN_LITERAL)
718+
719+
static inline int is_empty_blob_sha1(const unsigned char *sha1)
720+
{
721+
return !hashcmp(sha1, EMPTY_BLOB_SHA1_BIN);
722+
}
723+
711724
int git_mkstemp(char *path, size_t n, const char *template);
712725

713726
int git_mkstemps(char *path, size_t n, const char *template, int suffix_len);

read-cache.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,6 @@ static int ce_modified_check_fs(struct cache_entry *ce, struct stat *st)
157157
return 0;
158158
}
159159

160-
static int is_empty_blob_sha1(const unsigned char *sha1)
161-
{
162-
static const unsigned char empty_blob_sha1[20] = {
163-
0xe6,0x9d,0xe2,0x9b,0xb2,0xd1,0xd6,0x43,0x4b,0x8b,
164-
0x29,0xae,0x77,0x5a,0xd8,0xc2,0xe4,0x8c,0x53,0x91
165-
};
166-
167-
return !hashcmp(sha1, empty_blob_sha1);
168-
}
169-
170160
static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
171161
{
172162
unsigned int changed = 0;

0 commit comments

Comments
 (0)