Commit Graph

25 Commits

Author SHA1 Message Date
Carlos Martín Nieto
bb0757d56c tree-cache: correct the entry_count calculation
The entry_count field is the amount of index entries covered by a
particular cache entry, that is how many files are there (recursively)
under a particular directory.

The current code that attemps to do this is severely defincient and is
trying to count the amount of children, which always comes up to zero.

We don't even need to recount, since we have the information during the
cache creation. We can take that number and keep it, as we only ever
invalidate or replace.
2014-10-22 21:25:08 +02:00
Sven Strickroth
cf1013a888 There is no "z" size specifier on MSVC
See http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx and https://stackoverflow.com/questions/6655410/why-doesnt-zd-printf-format-work-in-vs2010

Signed-off-by: Sven Strickroth <email@cs-ware.de>
2014-10-13 16:32:26 +02:00
Carlos Martín Nieto
795d8e9328 index: make sure to write cached subtrees if parent is invalidated
If e.g. the root tree is invalidated, we still want to write out
its children, since those may still have valid cache entries.
2014-10-10 19:43:42 +02:00
Carlos Martín Nieto
c2f8b21593 index: write out the tree cache extension
Keeping the cache around after read-tree is only one part of the
optimisation opportunities. In order to share the cache between program
instances, we need to write the TREE extension to the index.

Do so, taking the opportunity to rename 'entries' to 'entry_count' to
match the name given in the format description. The included test is
rather trivial, but works as a sanity check.
2014-10-10 19:43:42 +02:00
Carlos Martín Nieto
46bb006730 tree-cache: remove the parent pointer
This wasn't used. We invalidate based on the full path, so we always go
down the tree, never up.
2014-10-10 19:37:48 +02:00
Carlos Martín Nieto
6843cebe17 index: fill the tree cache when reading from a tree
When reading from a tree, we know what every tree is going to look like,
so we can fill in the tree cache completely, making use of the index for
modification of trees a lot quicker.
2014-10-10 19:35:19 +02:00
Carlos Martín Nieto
19c88310cb tree-cache: move to use a pool allocator
This simplifies freeing the entries quite a bit; though there aren't
that many failure paths right now, introducing filling the cache from a
tree will introduce more. This makes sure not to leak memory on errors.
2014-10-10 19:35:18 +02:00
Carlos Martín Nieto
d091a9dbde tree-cache: extract the allocation 2014-10-10 19:35:18 +02:00
Russell Belfer
1fa17b5c92 Minor tree cache speedups
While I was looking at the conflict cleanup code, I looked over at
the tree cache code, since we clear the tree cache for each entry
that gets removed and there is some redundancy there.  I made some
small tweaks to avoid extra calls to strchr and strlen in a few
circumstances.
2014-04-17 14:43:46 -07:00
nulltoken
a5d7318802 tree-cache: Fix error message typo 2013-11-19 13:25:38 +01:00
nulltoken
3d5233455b tree-cache: Don't segfault upon corruption 2013-11-19 13:25:37 +01:00
nulltoken
82e6a42c6c tree-cache: Zero out the allocated tree children array 2013-11-19 13:25:25 +01:00
nulltoken
7b69289f4e tree-cache: Free the tree upon the detection of a corrupted child 2013-11-19 13:25:16 +01:00
Edward Thomson
359fc2d241 update copyrights 2013-01-08 17:31:27 -06:00
Nguyễn Thái Ngọc Duy
08f3d6caf4 tree cache: loosen negative entry count check
While C Git has been writing entry count -1 (ie. never other negative
numbers) as invalid since day 1, it accepts all negative entry counts
as invalid. JGit follows the same rule. libgit2 should also follow, or
the index that works with C Git or JGit may someday be rejected by
libgit2.

Other reimplementations like dulwich and grit have not bothered with
parsing or writing tree cache.
2012-12-12 19:23:05 +07:00
Vicent Martí
3f0358604e misc: Fix warnings from PVS Studio trial 2012-06-07 22:43:48 +02:00
Vicent Martí
3fbcac89c4 Remove old and unused error codes 2012-05-02 19:56:38 -07:00
Carlos Martín Nieto
2218fd57a5 tree-cache: don't error out on a childless invalidated entry
The code used to assume that there had to be data after the newline in
a tree cache extension entry. This isn't true for a childless
invalidated entry if it's the last one, as there won't be any children
nor a hash to take up space.

Adapt the off-by-one comparison to also work in this case. Fixes #633.
2012-04-23 10:41:43 -07:00
schu
5e0de32818 Update Copyright header
Signed-off-by: schu <schu-github@schulog.org>
2012-02-13 17:11:09 +01:00
Vicent Marti
3286c408ec global: Properly use git__ memory wrappers
Ensure that all memory related functions (malloc, calloc, strdup, free,
etc) are using their respective `git__` wrappers.
2011-10-28 19:02:36 -07:00
Carlos Martín Nieto
3ba69ba8a4 Add git_tree_cache_get
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-09-27 14:33:18 +02:00
Carlos Martín Nieto
69bffab969 Add git_tree_cache_invalidate_path
Whenever a file is updated in the index, each tree leading towards it
needs to be invalidated. Provide the supporting function.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-09-27 14:33:18 +02:00
Carlos Martín Nieto
acd31b4ad6 tree cache: correctly handle invalidated trees
The fix introduced in a02fc2cd1 (2011-05-24; index: correctly parse
invalidated TREE extensions) threw out the rest of the data in the
extension if it found an invalidated entry. This was the result of
incorrect reading of the documentation.

Insted, keep reading the extension, as there may be cached data we can
use.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-09-27 14:33:18 +02:00
Carlos Martín Nieto
b183ffe77e Make tree cache name a flex-array
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-09-27 14:33:18 +02:00
Carlos Martín Nieto
b41713206b Move the tree cache functions to their own file
Rename git_index_tree to git_tree_cache.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-09-27 14:33:18 +02:00