Commit f49c2c22 authored by Linus Torvalds's avatar Linus Torvalds Committed by Junio C Hamano

racy-git: an empty blob has a fixed object name

We use size=0 as the magic token to say the entry is known to be racily
clean, but a sequence that does:

 - update the path with a non-empty blob and write the index;
 - update an unrelated path and write the index -- this smudges
   the above entry;
 - truncate the path to size zero.

would make both the size field for the path in the index and the size on
the filesystem zero.  We should not mistake it as a clean index entry.
Signed-off-by: default avatarLinus Torvalds <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent 4afbcab9
......@@ -197,6 +197,16 @@ static int ce_modified_check_fs(struct cache_entry *ce, struct stat *st)
return 0;
static int is_empty_blob_sha1(const unsigned char *sha1)
static const unsigned char empty_blob_sha1[20] = {
return !hashcmp(sha1, empty_blob_sha1);
static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
unsigned int changed = 0;
......@@ -252,6 +262,12 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
if (ce->ce_size != (unsigned int) st->st_size)
changed |= DATA_CHANGED;
/* Racily smudged entry? */
if (!ce->ce_size) {
if (!is_empty_blob_sha1(ce->sha1))
changed |= DATA_CHANGED;
return changed;
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment