]> git.ipfire.org Git - thirdparty/git.git/commit - cache.h
Optimize "diff --cached" performance.
authorJunio C Hamano <gitster@pobox.com>
Thu, 9 Aug 2007 20:42:50 +0000 (13:42 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Aug 2007 18:44:23 +0000 (11:44 -0700)
commitaf3785dc5a76f4d5ddb8039e33c322e0e8b60e72
treec02265433c45546fddd7b1205aba081c32743a2c
parent63c21c494fc91eda339d06b3a466c4241afffc81
Optimize "diff --cached" performance.

The read_tree() function is called only from the call chain to
run "git diff --cached" (this includes the internal call made by
git-runstatus to run_diff_index()).  The function vacates stage
without any funky "merge" magic.  The caller then goes and
compares stage #1 entries from the tree with stage #0 entries
from the original index.

When adding the cache entries this way, it used the general
purpose add_cache_entry().  This function looks for an existing
entry to replace or if there is none to find where to insert the
new entry, resolves D/F conflict and all the other things.

For the purpose of reading entries into an empty stage, none of
that processing is needed.  We can instead append everything and
then sort the result at the end.

This commit changes read_tree() to first make sure that there is
no existing cache entries at specified stage, and if that is the
case, it runs add_cache_entry() with ADD_CACHE_JUST_APPEND flag
(new), and then sort the resulting cache using qsort().

This new flag tells add_cache_entry() to omit all the checks
such as "Does this path already exist?  Does adding this path
remove other existing entries because it turns a directory to a
file?" and instead append the given cache entry straight at the
end of the active cache.  The caller of course is expected to
sort the resulting cache at the end before using the result.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h
read-cache.c
tree.c