summaryrefslogtreecommitdiff
path: root/src/tree.c
Commit message (Collapse)AuthorAgeFilesLines
* treebuilder: don't try to verify submodules exist in the odbcmn/treebuilder-submoduleCarlos Martín Nieto2016-03-041-1/+2
| | | | | | | | Submodules don't exist in the objectdb and the code is making us try to look for a blob with its commit id, which is obviously not going to work. Skip the test if the user wants to insert a submodule.
* treebuilder: validate tree entries (optionally)Edward Thomson2016-02-281-0/+15
| | | | | When `GIT_OPT_ENABLE_STRICT_OBJECT_CREATION` is turned on, validate the tree and parent ids given to treebuilder insertion.
* tree: zap warnings around `size_t` vs `uint16_t`Edward Thomson2016-02-161-10/+16
|
* tree: mark a tree as already sortedcmn/tree-is-sortedCarlos Martín Nieto2015-12-061-1/+2
| | | | | The trees are sorted on-disk, so we don't have to go over them again. This cuts almost a fifth of time spent parsing trees.
* tree: use a specialised mode parse functioncmn/parse-modeCarlos Martín Nieto2015-12-021-5/+21
| | | | | Instead of going out to strtol, which is made to parse generic numbers, copy a parse function from git which is specialised for file modes.
* tree: mark cloned tree entries as un-pooledPatrick Steinhardt2015-12-011-0/+2
| | | | | | | | | | | | When duplicating a `struct git_tree_entry` with `git_tree_entry_dup` the resulting structure is not allocated inside a memory pool. As we do a 1:1 copy of the original struct, though, we also copy the `pooled` field, which is set to `true` for pooled entries. This results in a huge memory leak as we never free tree entries that were duplicated from a pooled tree entry. Fix this by marking the newly duplicated entry as un-pooled.
* tree: ensure the entry filename fits in 16 bitscmn/tree-parse-speedCarlos Martín Nieto2015-11-301-16/+26
| | | | | | Return an error in case the length is too big. Also take this opportunity to have a single allocating function for the size and overflow logic.
* tree: make path len uint16_t and avoid holesCarlos Martín Nieto2015-11-281-1/+1
| | | | | | This reduces the size of the struct from 32 to 26 bytes, and leaves a single padding byte at the end of the struct (which comes from the zero-length array).
* tree: calculate the filename length onceCarlos Martín Nieto2015-11-281-5/+8
| | | | | We already know the size due to the `memchr()` so use that information instead of calling `strlen()` on it.
* tree: pool the entry memory allocationsCarlos Martín Nieto2015-11-281-5/+29
| | | | | | | These are rather small allocations, so we end up spending a non-trivial amount of time asking the OS for memory. Since these entries are tied to the lifetime of their tree, we can give the tree a pool so we speed up the allocations.
* tree: avoid advancing over the filename multiple timesCarlos Martín Nieto2015-11-281-4/+2
| | | | | | | We've already looked at the filename with `memchr()` and then used `strlen()` to allocate the entry. We already know how much we have to advance to get to the object id, so add the filename length instead of looking at each byte again.
* tree: add more correct error messages for not foundCarlos Martín Nieto2015-03-171-2/+2
| | | | | Don't use the full path, as that's not what we are asserting does not exist, but just the subpath we were looking up.
* Remove extra semicolon outside of a functionStefan Widgren2015-02-151-1/+1
| | | | | Without this change, compiling with gcc and pedantic generates warning: ISO C does not allow extra ‘;’ outside of a function.
* Make our overflow check look more like gcc/clang'sEdward Thomson2015-02-131-11/+7
| | | | | | | | | Make our overflow checking look more like gcc and clang's, so that we can substitute it out with the compiler instrinsics on platforms that support it. This means dropping the ability to pass `NULL` as an out parameter. As a result, the macros also get updated to reflect this as well.
* overflow checking: don't make callers set oomEdward Thomson2015-02-121-3/+1
| | | | | | Have the ALLOC_OVERFLOW testing macros also simply set_oom in the case where a computation would overflow, so that callers don't need to.
* allocations: test for overflow of requested sizeEdward Thomson2015-02-121-5/+13
| | | | | Introduce some helper macros to test integer overflow from arithmetic and set error message appropriately.
* treebuilder: rename _create() to _new()cmn/treebuilder-newCarlos Martín Nieto2014-12-271-2/+2
| | | | | | This function is a constructor, so let's name it like one and leave _create() for the reference functions, which do create/write the reference.
* treebuilder: take a repository for path validationEdward Thomson2014-12-171-14/+16
| | | | | | Path validation may be influenced by `core.protectHFS` and `core.protectNTFS` configuration settings, thus treebuilders can take a repository to influence their configuration.
* tree: Check for `.git` with case insensitivyVicent Marti2014-12-161-1/+1
|
* index: fill the tree cache on write-treeCarlos Martín Nieto2014-10-101-1/+16
| | | | | | | | | | | | | | | | An obvious place to fill the tree cache is on write-tree, as we're guaranteed to be able to fill in the whole tree cache. The way this commit does this is not the most efficient, as we read the root tree from the odb instead of filling in the cache as we go along, but it fills the cache such that successive operations (and persisting the index to disk) will be able to take advantage of the cache, and it reuses the code we already have for filling the cache. Filling in the cache as we create the trees would require some reallocation of the children vector, which is currently not possible with out pool implementation. A different data structure would likely allow us to perform this operation at a later date.
* index: write out the tree cache extensionCarlos Martín Nieto2014-10-101-2/+2
| | | | | | | | | | 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.
* tree: free in error conditionsCarlos Martín Nieto2014-06-251-0/+2
| | | | As reported by coverity, we would leak some memory in error conditions.
* treentry: no need for manual size book-keepingcmn/treebuilder-perfCarlos Martín Nieto2014-06-101-9/+6
| | | | We can simply ask the hasmap.
* treebuilder: don't keep removed entries aroundCarlos Martín Nieto2014-06-101-34/+17
| | | | | | If the user wants to keep a copy for themselves, they should make a copy. It adds unnecessary complexity to make sure the returned entries are valid until the builder is cleared.
* treebuilder: use a map instead of vector to store the entriesCarlos Martín Nieto2014-06-101-49/+74
| | | | | | | | | | | | | | | | | Finding a filename in a vector means we need to resort it every time we want to read from it, which includes every time we want to write to it as well, as we want to find duplicate keys. A hash-map fits what we want to do much more accurately, as we do not care about sorting, but just the particular filename. We still keep removed entries around, as the interface let you assume they were going to be around until the treebuilder is cleared or freed, but in this case that involves an append to a vector in the filter case, which can now fail. The only time we care about sorting is when we write out the tree, so let's make that the only time we do any sorting.
* treebuilder: insert sortedcmn/treebuilder-insert-sortedCarlos Martín Nieto2014-06-101-2/+2
| | | | | By inserting in the right position, we can keep the vector sorted, making entry insertion almost twice as fast.
* Convert pqueue to just be a git_vectorRussell Belfer2014-02-041-2/+4
| | | | | | | | | | | | | This updates the git_pqueue to simply be a set of specialized init/insert/pop functions on a git_vector. To preserve the pqueue feature of having a fixed size heap, I converted the "sorted" field in git_vectors to a more general "flags" field so that pqueue could mix in it's own flag. This had a bunch of ramifications because a number of places were directly looking at the vector "sorted" field - I added a couple new git_vector helpers (is_sorted, set_sorted) so the specific representation of this information could be abstracted.
* tree: remove legacy 'oid' namingCarlos Martín Nieto2014-01-251-3/+3
| | | | Rename git_tree_entry_byoid() to _byid() as per the convention.
* index: rename an entry's id to 'id'Carlos Martín Nieto2014-01-251-1/+1
| | | | This was not converted when we converted the rest, so do it now.
* Align git_tree_entry_dup.Arthur Schreiber2014-01-141-9/+8
|
* One more rename/cleanup for callback err functionsRussell Belfer2013-12-111-5/+11
|
* Remove converting user error to GIT_EUSERRussell Belfer2013-12-111-10/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changes the behavior of callbacks so that the callback error code is not converted into GIT_EUSER and instead we propagate the return value through to the caller. Instead of using the giterr_capture and giterr_restore functions, we now rely on all functions to pass back the return value from a callback. To avoid having a return value with no error message, the user can call the public giterr_set_str or some such function to set an error message. There is a new helper 'giterr_set_callback' that functions can invoke after making a callback which ensures that some error message was set in case the callback did not set one. In places where the sign of the callback return value is meaningful (e.g. positive to skip, negative to abort), only the negative values are returned back to the caller, obviously, since the other values allow for continuing the loop. The hardest parts of this were in the checkout code where positive return values were overloaded as meaningful values for checkout. I fixed this by adding an output parameter to many of the internal checkout functions and removing the overload. This added some code, but it is probably a better implementation. There is some funkiness in the network code where user provided callbacks could be returning a positive or a negative value and we want to rely on that to cancel the loop. There are still a couple places where an user error might get turned into GIT_EUSER there, I think, though none exercised by the tests.
* Further EUSER and error propagation fixesRussell Belfer2013-12-111-9/+4
| | | | | | | | | | | | | This continues auditing all the places where GIT_EUSER is being returned and making sure to clear any existing error using the new giterr_user_cancel helper. As a result, places that relied on intercepting GIT_EUSER but having the old error preserved also needed to be cleaned up to correctly stash and then retrieve the actual error. Additionally, as I encountered places where error codes were not being propagated correctly, I tried to fix them up. A number of those fixes are included in the this commit as well.
* tree: allow retrieval of raw attributesCarlos Martín Nieto2013-10-081-3/+6
| | | | | | When a tool needs to recreate the tree object (for example an interface to another VCS), it needs to use the raw attributes, forgoing any normalization.
* Fix memory leak in git_tree_walk on error or when stopping the walk from the ↵wilke2013-09-131-1/+2
| | | | supplied callback
* Prevent git_tree_walk 'skip entry' callback return code from leaking through ↵wilke2013-09-131-1/+3
| | | | as the return value of git_tree_walk
* Better macro name for is-exec-bit-set testRussell Belfer2013-09-051-1/+1
|
* Add more file mode permissions macrosRussell Belfer2013-09-051-6/+6
| | | | | | This adds some more macros for some standard operations on file modes, particularly related to permissions, and then updates a number of places around the code base to use the new macros.
* Reorganize diff and add basic diff driverRussell Belfer2013-06-101-0/+3
| | | | | | | | | | | | | | | | | | This is a significant reorganization of the diff code to break it into a set of more clearly distinct files and to document the new organization. Hopefully this will make the diff code easier to understand and to extend. This adds a new `git_diff_driver` object that looks of diff driver information from the attributes and the config so that things like function content in diff headers can be provided. The full driver spec is not implemented in the commit - this is focused on the reorganization of the code and putting the driver hooks in place. This also removes a few #includes from src/repository.h that were overbroad, but as a result required extra #includes in a variety of places since including src/repository.h no longer results in pulling in the whole world.
* Add cat-file example and increase const use in APIRussell Belfer2013-05-161-8/+15
| | | | | | | | | | | | | | | | This adds an example implementation that emulates git cat-file. It is a convenient and relatively simple example of getting data out of a repository. Implementing this also revealed that there are a number of APIs that are still not using const pointers to objects that really ought to be. The main cause of this is that `git_vector_bsearch` may need to call `git_vector_sort` before doing the search, so a const pointer to the vector is not allowed. However, for tree objects, with a little care, we can ensure that the vector of tree entries is always sorted and allow lookups to take a const pointer. Also, the missing const in commit objects just looks like an oversight.
* clarify error propogationRussell Belfer2013-05-011-1/+1
|
* object: Explicitly define helper API methods for all obj typesVicent Marti2013-04-301-2/+0
|
* Some cleanupsRussell Belfer2013-04-291-1/+1
| | | | | Removed useless prototype and renamed object typecast functions declaration macro.
* Standardize cast versions of git_object accessorsRussell Belfer2013-04-291-10/+2
| | | | | | This removes the GIT_INLINE versions of the simple git_object accessors and standardizes them with a helper macro in src/object.h to build the function bodies.
* clean up tree pointer castingRussell Belfer2013-04-221-8/+8
|
* Simplify object table parse functionsRussell Belfer2013-04-221-1/+3
| | | | | This unifies the object parse functions into one signature that takes an odb_object.
* Add callback to git_objects_tableRussell Belfer2013-04-221-18/+9
| | | | | | | | | | This adds create and free callback to the git_objects_table so that more of the creation and destruction of objects can be table driven instead of using switch statements. This also makes the semantics of certain object creation functions consistent so that we can make better use of function pointers. This also fixes a theoretical error case where an object allocation fails and we end up storing NULL into the cache.
* Use git_odb_object_data/_size whereever possibleRussell Belfer2013-04-221-5/+9
| | | | | This uses the odb object accessors so we can change the internals more easily...
* What has science done.Vicent Marti2013-04-221-1/+3
|
* treebuilder: don't overwrite the error messageCarlos Martín Nieto2013-04-181-1/+0
|