Skip to content

Commit c636d0e

Browse files
committed
Merge branch 'lt/racy-empty' into maint
* lt/racy-empty: racy-git: an empty blob has a fixed object name
2 parents 39f319f + f49c2c2 commit c636d0e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

read-cache.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ static int ce_modified_check_fs(struct cache_entry *ce, struct stat *st)
138138
return 0;
139139
}
140140

141+
static int is_empty_blob_sha1(const unsigned char *sha1)
142+
{
143+
static const unsigned char empty_blob_sha1[20] = {
144+
0xe6,0x9d,0xe2,0x9b,0xb2,0xd1,0xd6,0x43,0x4b,0x8b,
145+
0x29,0xae,0x77,0x5a,0xd8,0xc2,0xe4,0x8c,0x53,0x91
146+
};
147+
148+
return !hashcmp(sha1, empty_blob_sha1);
149+
}
150+
141151
static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
142152
{
143153
unsigned int changed = 0;
@@ -193,6 +203,12 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
193203
if (ce->ce_size != (unsigned int) st->st_size)
194204
changed |= DATA_CHANGED;
195205

206+
/* Racily smudged entry? */
207+
if (!ce->ce_size) {
208+
if (!is_empty_blob_sha1(ce->sha1))
209+
changed |= DATA_CHANGED;
210+
}
211+
196212
return changed;
197213
}
198214

0 commit comments

Comments
 (0)