Merge branch 'ym/fix-opportunistic-index-update-race'
authorJunio C Hamano <gitster@pobox.com>
Tue, 3 Jun 2014 19:06:41 +0000 (12:06 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 3 Jun 2014 19:06:41 +0000 (12:06 -0700)
Read-only operations such as "git status" that internally refreshes
the index write out the refreshed index to the disk to optimize
future accesses to the working tree, but this could race with a
"read-write" operation that modify the index while it is running.
Detect such a race and avoid overwriting the index.

Duy raised a good point that we may need to do the same for the
normal writeout codepath, not just the "opportunistic" update
codepath. While that is true, nobody sane would be running two
simultaneous operations that are clearly write-oriented competing
with each other against the same index file. So in that sense that
can be done as a less urgent follow-up for this topic.

* ym/fix-opportunistic-index-update-race:
read-cache.c: verify index file before we opportunistically update it
wrapper.c: add xpread() similar to xread()

1  2 
builtin/index-pack.c
cache.h
git-compat-util.h
read-cache.c
Simple merge
diff --cc cache.h
index ef4412d1c68e1f4dc4821eaf24178361b312e27a,9244c387c39b3a5cf29162a36fdb1388cff9a87f..557bd6ae812e44e88efa90511dbbd767c52e5895
+++ b/cache.h
@@@ -292,8 -277,9 +292,9 @@@ struct index_state 
        struct cache_time timestamp;
        unsigned name_hash_initialized : 1,
                 initialized : 1;
 -      struct hash_table name_hash;
 -      struct hash_table dir_hash;
 +      struct hashmap name_hash;
 +      struct hashmap dir_hash;
+       unsigned char sha1[20];
  };
  
  extern struct index_state the_index;
Simple merge
diff --cc read-cache.c
Simple merge