Skip to content

Commit

Permalink
Fast-path 'update-index --refresh' a bit.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Sep 20, 2005
1 parent e9bacb4 commit 1991b22
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions update-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 1991b22

Please sign in to comment.