summaryrefslogtreecommitdiff
path: root/update-index.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-09-19 14:49:50 -0700
committerJunio C Hamano <junkio@cox.net>2005-09-20 15:07:53 -0700
commit1991b223c05d45d2a915842990b2a7c4819dcbcf (patch)
tree341f43cab4c91c279e8adb995ac77c61fadf7f98 /update-index.c
parente9bacb4f6a6f0aae7270acb257977f9ee0bbd6db (diff)
downloadgit-1991b223c05d45d2a915842990b2a7c4819dcbcf.tar.gz
Fast-path 'update-index --refresh' a bit.
If the length in the stat information does not match what is recorded in the index, there is no point rehashing the contents to see if the index entry can be refreshed. We need to be a bit careful. Immediately after read-tree or checkout-index without -u, ce_size is set to zero and does not match the length of the blob that is recorded, and we need to actually look at the contents to see if it has been changed. Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'update-index.c')
-rw-r--r--update-index.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/update-index.c b/update-index.c
index 8fe015b499..60c8417496 100644
--- a/update-index.c
+++ b/update-index.c
@@ -184,6 +184,13 @@ static struct cache_entry *refresh_entry(struct cache_entry *ce)
if (changed & (MODE_CHANGED | TYPE_CHANGED))
return ERR_PTR(-EINVAL);
+ /* Immediately after read-tree or update-index --cacheinfo,
+ * the length field is zero. For other cases the ce_size
+ * should match the SHA1 recorded in the index entry.
+ */
+ if ((changed & DATA_CHANGED) && ce->ce_size != htonl(0))
+ return ERR_PTR(-EINVAL);
+
switch (st.st_mode & S_IFMT) {
case S_IFREG:
if (compare_data(ce, &st))