]> git.ipfire.org Git - thirdparty/git.git/commit - read-cache.c
Fix name re-hashing semantics
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 23 Feb 2008 04:37:40 +0000 (20:37 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sat, 23 Feb 2008 05:24:47 +0000 (21:24 -0800)
commita22c637124a2f591382d56546136a8e2bb2c2c66
treee88516846d755c492ee9a5b96a731caa9227dbf3
parent22c430ad8468133fa5ed46d8407d7f4cde2c4a0e
Fix name re-hashing semantics

We handled the case of removing and re-inserting cache entries badly,
which is something that merging commonly needs to do (removing the
different stages, and then re-inserting one of them as the merged
state).

We even had a rather ugly special case for this failure case, where
replace_index_entry() basically turned itself into a no-op if the new
and the old entries were the same, exactly because the hash routines
didn't handle it on their own.

So what this patch does is to not just have the UNHASHED bit, but a
HASHED bit too, and when you insert an entry into the name hash, that
involves:

 - clear the UNHASHED bit, because now it's valid again for lookup
   (which is really all that UNHASHED meant)

 - if we're being lazy, we're done here (but we still want to clear the
   UNHASHED bit regardless of lazy mode, since we can become unlazy
   later, and so we need the UNHASHED bit to always be set correctly,
   even if we never actually insert the entry into the hash list)

 - if it was already hashed, we just leave it on the list

 - otherwise mark it HASHED and insert it into the list

this all means that unhashing and rehashing a name all just works
automatically.  Obviously, you cannot change the name of an entry (that
would be a serious bug), but nothing can validly do that anyway (you'd
have to allocate a new struct cache_entry anyway since the name length
could change), so that's not a new limitation.

The code actually gets simpler in many ways, although the lazy hashing
does mean that there are a few odd cases (ie something can be marked
unhashed even though it was never on the hash in the first place, and
isn't actually marked hashed!).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h
read-cache.c