summaryrefslogtreecommitdiff
path: root/tests/object/tree
Commit message (Collapse)AuthorAgeFilesLines
* refactor: `tests` is now `tests/libgit2`Edward Thomson2022-02-228-1631/+0
| | | | | | Like we want to separate libgit2 and utility source code, we want to separate libgit2 and utility tests. Start by moving all the tests into libgit2.
* Fix typosDimitris Apostolou2022-01-051-1/+1
|
* str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstrEdward Thomson2021-10-171-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | libgit2 has two distinct requirements that were previously solved by `git_buf`. We require: 1. A general purpose string class that provides a number of utility APIs for manipulating data (eg, concatenating, truncating, etc). 2. A structure that we can use to return strings to callers that they can take ownership of. By using a single class (`git_buf`) for both of these purposes, we have confused the API to the point that refactorings are difficult and reasoning about correctness is also difficult. Move the utility class `git_buf` to be called `git_str`: this represents its general purpose, as an internal string buffer class. The name also is an homage to Junio Hamano ("gitstr"). The public API remains `git_buf`, and has a much smaller footprint. It is generally only used as an "out" param with strict requirements that follow the documentation. (Exceptions exist for some legacy APIs to avoid breaking callers unnecessarily.) Utility functions exist to convert a user-specified `git_buf` to a `git_str` so that we can call internal functions, then converting it back again.
* clar: include the function nameethomson/clar_tapEdward Thomson2020-06-051-1/+2
|
* tree: ensure we protect NTFS paths everywhereEdward Thomson2019-12-101-5/+3
|
* test: ensure treebuilder validate new protection rulesEdward Thomson2019-12-101-0/+1
| | | | | Ensure that the new protection around .git::$INDEX_ALLOCATION rules are enabled for using the treebuilder when core.protectNTFS is set.
* object: use literal constant in bigfile testEdward Thomson2019-06-241-1/+2
| | | | | Don't calculate 4 GiB as that will produce a compiler warning on MSVC. Just hardcode it.
* largefile tests: only write 2GB on 32-bit platformsethomson/largefiles_32bitEdward Thomson2019-06-231-1/+5
| | | | | Don't try to feed 4 GB of data to APIs that only take a `size_t` on 32-bit platforms.
* index: rename `frombuffer` to `from_buffer`Edward Thomson2019-06-161-1/+1
| | | | | | The majority of functions are named `from_something` (with an underscore) instead of `fromsomething`. Update the index functions for consistency with the rest of the library.
* tests: object: refactor largefile test to not use `p_fallocate`Patrick Steinhardt2019-06-141-25/+15
| | | | | | | | | | | | | | The `p_fallocate` platform is currently in use in our tests, only, but it proved to be quite burdensome to get it implemented in a cross-platform way. The only "real" user is the test object::tree::read::largefile, where it's used to allocate a large file in the filesystem only to commit it to the repo and read its object back again. We can simplify this quite a bit by just using an in-memory buffer of 4GB. Sure, this cannot be used on platforms with low resources. But creating 4GB files is not any better, and we already skip the test if the environment variable "GITTEST_INVASIVE_FS_SIZE" is not set. So we're arguably not worse off than before.
* tests: test largefiles on win32Edward Thomson2019-04-041-4/+0
|
* tests: test that largefiles can be read through the tree APIEtienne Samson2019-01-301-0/+53
|
* git_error: use new names in internal APIs and usageEdward Thomson2019-01-222-2/+2
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* object_type: use new enumeration namesethomson/index_fixesEdward Thomson2018-12-013-5/+5
| | | | Use the new object_type enumeration names within the codebase.
* index: use new enum and structure namesEdward Thomson2018-12-011-9/+9
| | | | Use the new-style index names throughout our own codebase.
* tree: fix integer overflow when reading unreasonably large filemodesPatrick Steinhardt2018-11-021-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | The `parse_mode` option uses an open-coded octal number parser. The parser is quite naive in that it simply parses until hitting a character that is not in the accepted range of '0' - '7', completely ignoring the fact that we can at most accept a 16 bit unsigned integer as filemode. If the filemode is bigger than UINT16_MAX, it will thus overflow and provide an invalid filemode for the object entry. Fix the issue by using `git__strntol32` instead and doing a bounds check. As this function already handles overflows, it neatly solves the problem. Note that previously, `parse_mode` was also skipping the character immediately after the filemode. In proper trees, this should be a simple space, but in fact the parser accepted any character and simply skipped over it. As a consequence of using `git__strntol32`, we now need to an explicit check for a trailing whitespace after having parsed the filemode. Because of the newly introduced error message, the test object::tree::parse::mode_doesnt_cause_oob_read needs adjustment to its error message check, which in fact is a good thing as it demonstrates that we now fail looking for the whitespace immediately following the filemode. Add a test that shows that we will fail to parse such invalid filemodes now.
* tree: fix mode parsing reading out-of-boundsPatrick Steinhardt2018-11-021-0/+12
| | | | | | | | | | | When parsing a tree entry's mode, we will eagerly parse until we hit a character that is not in the accepted set of octal digits '0' - '7'. If the provided buffer is not a NUL terminated one, we may thus read out-of-bounds. Fix the issue by passing the buffer length to `parse_mode` and paying attention to it. Note that this is not a vulnerability in our usual code paths, as all object data read from the ODB is NUL terminated.
* tree: add various tests exercising the tree parserPatrick Steinhardt2018-11-021-0/+146
| | | | | | | | | | | We currently don't have any tests that directly exercise the tree parser. This is due to the fact that the parsers for raw object data has only been recently introduce with commit ca4db5f4a (object: implement function to parse raw data, 2017-10-13), and previous to that the setup simply was too cumbersome as it always required going through the ODB. Now that we have the infrastructure, add a suite of tests that directly exercise the tree parser and various edge cases.
* tree: rename from_tree to validate and clarify the tree in the testcmn/null-oid-existing-treeCarlos Martín Nieto2018-07-271-0/+1
|
* tree: accept null ids in existing trees when updatingCarlos Martín Nieto2018-07-181-0/+15
| | | | | | | | | 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.
* treewide: remove use of C++ style commentsPatrick Steinhardt2018-07-131-3/+3
| | | | | | | | | C++ style comment ("//") are not specified by the ISO C90 standard and thus do not conform to it. While libgit2 aims to conform to C90, we did not enforce it until now, which is why quite a lot of these non-conforming comments have snuck into our codebase. Do a tree-wide conversion of all C++ style comments to the supported C style comments to allow us enforcing strict C90 compliance in a later commit.
* Convert usage of `git_buf_free` to new `git_buf_dispose`Patrick Steinhardt2018-06-101-1/+1
|
* tree: initialize the id we use for testing submodule insertionscmn/tree-write-initialiseCarlos Martín Nieto2018-02-281-0/+1
| | | | | | Instead of laving it uninitialized and relying on luck for it to be non-zero, let's give it a dummy hash so we make valgrind happy (in this case the hash comes from `sha1sum </dev/null`.
* tree: reject writing null-OID entries to a treePatrick Steinhardt2018-01-261-0/+11
| | | | | | | | | | | | 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: add a failing test for unsorted inputCarlos Martín Nieto2016-11-141-0/+57
| | | | | We do not currently use the sorted version of this input in the function, which means we produce bad results.
* tree: handle removal of all entries in the updatercmn/remove-single-entryCarlos Martín Nieto2016-05-241-0/+32
| | | | | 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-1/+2
|
* tree: use testrepo2 for the tree updater testsCarlos Martín Nieto2016-05-191-9/+38
| | | | This gives us trees with subdirectories, which the new test needs.
* Introduce a function to create a tree based on a different onecmn/tree-updateCarlos Martín Nieto2016-05-171-0/+167
| | | | | | | | | | | 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.
* tree: re-use the id and filename in the odb objectCarlos Martín Nieto2016-03-201-0/+2
| | | | | 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-0/+12
| | | | | | | | 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.
* turn on strict object validation by defaultEdward Thomson2016-02-281-6/+6
|
* tests: use legitimate object idsEdward Thomson2016-02-281-13/+18
| | | | | Use legitimate (existing) object IDs in tests so that we have the ability to turn on strict object validation when running tests.
* treebuilder: validate tree entries (optionally)Edward Thomson2016-02-281-0/+55
| | | | | When `GIT_OPT_ENABLE_STRICT_OBJECT_CREATION` is turned on, validate the tree and parent ids given to treebuilder insertion.
* conflict tests: use GIT_IDXENTRY_STAGE_SETEdward Thomson2015-05-281-3/+3
|
* Plug a couple of leaksCarlos Martín Nieto2015-01-041-1/+0
|
* treebuilder: rename _create() to _new()cmn/treebuilder-newCarlos Martín Nieto2014-12-273-14/+14
| | | | | | 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-173-32/+74
| | | | | | Path validation may be influenced by `core.protectHFS` and `core.protectNTFS` configuration settings, thus treebuilders can take a repository to influence their configuration.
* treebuilder: use a map instead of vector to store the entriesCarlos Martín Nieto2014-06-101-2/+6
| | | | | | | | | | | | | | | | | 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.
* Merge pull request #2027 from libgit2/rb/only-windows-is-windowsBen Straub2014-02-051-9/+91
|\ | | | | Some tests of paths that can't actually be written to disk
| * Further tree building tests with hard pathsRussell Belfer2014-01-031-6/+40
| |
| * Tree accessor tests with hard path namesRussell Belfer2014-01-031-9/+57
| |
* | index: rename an entry's id to 'id'Carlos Martín Nieto2014-01-251-3/+3
|/ | | | This was not converted when we converted the rest, so do it now.
* Add git_treebuilder_insert test and clarify docRussell Belfer2013-12-121-15/+69
| | | | | | This wasn't being tested and since it has a callback, I fixed it even though the return value of this callback is not treated like any of the other callbacks in the API.
* Remove converting user error to GIT_EUSERRussell Belfer2013-12-111-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Rename tests-clar to testsBen Straub2013-11-146-0/+854