summaryrefslogtreecommitdiff
path: root/src/tree.c
Commit message (Collapse)AuthorAgeFilesLines
* tree: rename from_tree to validate and clarify the tree in the testcmn/null-oid-existing-treeCarlos Martín Nieto2018-07-271-6/+6
|
* tree: accept null ids in existing trees when updatingCarlos Martín Nieto2018-07-181-6/+8
| | | | | | | | | When we add entries to a treebuilder we validate them. But we validate even those that we're adding because they exist in the base tree. This disables using the normal mechanisms on these trees, even to fix them. Keep track of whether the entry we're appending comes from an existing tree and bypass the name and id validation if it's from existing data.
* tree: remove unused function `git_tree__prefix_position`Patrick Steinhardt2018-06-151-35/+0
|
* tree: remove unused function `git_tree_entry_icmp`Patrick Steinhardt2018-06-151-8/+0
|
* Convert usage of `git_buf_free` to new `git_buf_dispose`Patrick Steinhardt2018-06-101-4/+4
|
* path: reject .gitmodules as a symlinkCarlos Martín Nieto2018-05-231-1/+1
| | | | | | | | Any part of the library which asks the question can pass in the mode to have it checked against `.gitmodules` being a symlink. This is particularly relevant for adding entries to the index from the worktree and for checking out files.
* Explicitly mark fallthrough cases with commentsPatrick Steinhardt2018-02-161-1/+1
| | | | | | | | | | | | | | | | | | A lot of compilers nowadays generate warnings when there are cases in a switch statement which implicitly fall through to the next case. To avoid this warning, the last line in the case that is falling through can have a comment matching a regular expression, where one possible comment body would be `/* fall through */`. An alternative to the comment would be an explicit attribute like e.g. `[[clang::fallthrough]` or `__attribute__ ((fallthrough))`. But GCC only introduced support for such an attribute recently with GCC 7. Thus, and also because the fallthrough comment is supported by most compilers, we settle for using comments instead. One shortcoming of that method is that compilers are very strict about that. Most interestingly, that comment _really_ has to be the last line. In case a closing brace follows the comment, the heuristic will fail.
* tree: reject writing null-OID entries to a treePatrick Steinhardt2018-01-261-0/+6
| | | | | | | | | | | | In commit a96d3cc3f (cache-tree: reject entries with null sha1, 2017-04-21), the git.git project has changed its stance on null OIDs in tree objects. Previously, null OIDs were accepted in tree entries to help tools repair broken history. This resulted in some problems though in that many code paths mistakenly passed null OIDs to be added to a tree, which was not properly detected. Align our own code base according to the upstream change and reject writing tree entries early when the OID is all-zero.
* tree: standard error messages are lowercaseethomson/tree_error_messagesEdward Thomson2017-12-311-10/+10
| | | | | | | | Our standard error messages begin with a lower case letter so that they can be prefixed or embedded nicely. These error messages were missed during the standardization pass since they use the `tree_error` helper function.
* Make sure to always include "common.h" firstPatrick Steinhardt2017-07-031-2/+2
| | | | | | | | | | | | | | | | | | | | | | Next to including several files, our "common.h" header also declares various macros which are then used throughout the project. As such, we have to make sure to always include this file first in all implementation files. Otherwise, we might encounter problems or even silent behavioural differences due to macros or defines not being defined as they should be. So in fact, our header and implementation files should make sure to always include "common.h" first. This commit does so by establishing a common include pattern. Header files inside of "src" will now always include "common.h" as its first other file, separated by a newline from all the other includes to make it stand out as special. There are two cases for the implementation files. If they do have a matching header file, they will always include this one first, leading to "common.h" being transitively included as first file. If they do not have a matching header file, they instead include "common.h" as first file themselves. This fixes the outlined problems and will become our standard practice for header and source files inside of the "src/" from now on.
* treebuilder: exit early if running OOM in `write_with_buffer`Patrick Steinhardt2017-03-281-3/+4
| | | | | | | | | | While writing the tree inside of a buffer, we check whether the buffer runs out of memory after each tree entry. While we set the error code as soon as we detect the OOM situation, we happily proceed iterating over the entries. This is not useful at all, as we will try to write into the buffer repeatedly, which cannot work. Fix this by exiting as soon as we are OOM.
* treebuilder: remove shadowing variable in `write_with_buffer`Patrick Steinhardt2017-03-281-1/+1
| | | | | | The `git_tree_entry *entry` variable is defined twice inside of this function. While this is not a problem currently, remove the shadowing variable to avoid future confusion.
* treebuilder: fix memory leaks in `write_with_buffer`Patrick Steinhardt2017-03-281-7/+8
| | | | | | | While we detect errors in `git_treebuilder_write_with_buffer`, we just exit directly instead of freeing allocated memory. Fix this by remembering error codes and skipping forward to the function's cleanup code.
* strmap: remove GIT__USE_STRMAP macroPatrick Steinhardt2017-02-171-2/+0
|
* khash: avoid using macro magic to get return addressPatrick Steinhardt2017-02-171-2/+2
|
* Merge pull request #3892 from mitesch/shared_bufferEdward Thomson2017-01-211-15/+30
|\ | | | | Use a shared buffer in calls of git_treebuilder_write to avoid heap contention
| * write_tree: use shared buffer for writing treesMichael Tesch2016-12-121-15/+30
| | | | | | | | | | | | | | | | | | The function to write trees allocates a new buffer for each tree. This causes problems with performance when performing a lot of actions involving writing trees, e.g. when doing many merges. Fix the issue by instead handing in a shared buffer, which is then re-used across the calls without having to re-allocate between calls.
* | giterr_set: consistent error messagesEdward Thomson2016-12-291-5/+5
| | | | | | | | | | | | | | | | Error messages should be sentence fragments, and therefore: 1. Should not begin with a capital letter, 2. Should not conclude with punctuation, and 3. Should not end a sentence and begin a new one
* | tree: look for conflicts in the new tree when updatingcmn/tree-updater-orderingCarlos Martín Nieto2016-11-141-0/+3
| | | | | | | | | | | | | | | | | | | | We look at whether we're trying to replace a blob with a tree during the update phase, but we fail to look at whether we've just inserted a blob where we're now trying to insert a tree. Update the check to look at both places. The test for this was previously succeeding due to the bu where we did not look at the sorted output.
* | tree: use the sorted update list in our loopCarlos Martín Nieto2016-11-141-2/+2
| | | | | | | | | | The loop is made with the assumption that the inputs are sorted and not using it leads to bad outputs.
* | common: cast precision specifiers to intPatrick Steinhardt2016-11-141-2/+2
| |
* | tree: validate filename and OID length when parsing objectPatrick Steinhardt2016-10-071-1/+6
|/ | | | | | | | When parsing tree entries from raw object data, we do not verify that the tree entry actually has a filename as well as a valid object ID. Fix this by asserting that the filename length is non-zero as well as asserting that there are at least `GIT_OID_RAWSZ` bytes left when parsing the OID.
* Merge pull request #3792 from edquist/miscEdward Thomson2016-05-261-1/+1
|\ | | | | Fix comment for GIT_FILEMODE_LINK
| * Fix comment for GIT_FILEMODE_LINKCarl Edquist2016-05-181-1/+1
| | | | | | | | 0120000 is symbolic link, not commit
* | tree: handle removal of all entries in the updatercmn/remove-single-entryCarlos Martín Nieto2016-05-241-0/+9
| | | | | | | | | | When we remove all entries in a tree, we should remove that tree from its parent rather than include the empty tree.
* | tree: plug leaks in the tree updatercmn/tree-update-basenameCarlos Martín Nieto2016-05-191-3/+11
| |
* | tree: use the basename for the entry removalCarlos Martín Nieto2016-05-191-1/+1
|/ | | | | | When we want to remove the file, use the basename as the name of the entry to remove, instead of the full one, which includes the directories we've inserted into the stack.
* Introduce a function to create a tree based on a different onecmn/tree-updateCarlos Martín Nieto2016-05-171-0/+245
| | | | | | | | | | | Instead of going through the usual steps of reading a tree recursively into an index, modifying it and writing it back out as a tree, introduce a function to perform simple updates more efficiently. `git_tree_create_updated` avoids reading trees which are not modified and supports upsert and delete operations. It is not as versatile as modifying the index, but it makes some common operations much more efficient.
* Plug a few leaksCarlos Martín Nieto2016-03-311-0/+2
|
* tree: drop the now-unnecessary entries vectorEdward Thomson2016-03-221-44/+29
| | | | | Remove the now-unnecessary entries vector. Add `git_array_search` to binary search through an array to accomplish this.
* tree: store the entries in a growable arraycmn/tree-reuseCarlos Martín Nieto2016-03-201-57/+36
| | | | | | Take advantage of the constant size of tree-owned arrays and store them in an array instead of a pool. This still lets us free them all at once but lets the system allocator do the work of fitting them in.
* tree: re-use the id and filename in the odb objectCarlos Martín Nieto2016-03-201-39/+51
| | | | | Instead of copying over the data into the individual entries, point to the originals, which are already in a format we can use.
* 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.