summaryrefslogtreecommitdiff
path: root/tests/odb
Commit message (Collapse)AuthorAgeFilesLines
* test: correct test namesEdward Thomson2021-11-111-1/+1
|
* tests: declare functions statically where appropriateEdward Thomson2021-11-111-1/+1
|
* Merge pull request #6104 from libgit2/ethomson/pathEdward Thomson2021-11-112-2/+2
|\ | | | | path: refactor utility path functions
| * path: separate git-specific path functions from utilEdward Thomson2021-11-092-2/+2
| | | | | | | | | | | | Introduce `git_fs_path`, which operates on generic filesystem paths. `git_path` will be kept for only git-specific path functionality (for example, checking for `.git` in a path).
* | Add tests for ODB refreshJosh Triplett2021-11-086-7/+198
|/ | | | | Add optional refreshing in the fake backend, and count the number of refresh calls if enabled.
* str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstrEdward Thomson2021-10-174-24/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* hash: hash functions operate on byte arrays not git_oidsEdward Thomson2021-10-021-1/+1
| | | | | | Separate the concerns of the hash functions from the git_oid functions. The git_oid structure will need to understand either SHA1 or SHA256; the hash functions should only deal with the appropriate one of these.
* hash: accept the algorithm in inputsEdward Thomson2021-10-011-1/+1
|
* tests: don't generate false positives on empty path segmentsPeter Pettersson2021-08-081-1/+1
|
* tests: reset odb backend priorityethomson/odb_tests_priorityEdward Thomson2021-07-301-0/+6
|
* odb: Implement option for overriding of default odb backend priorityTony De La Nuez2021-07-301-0/+23
| | | | | | | | | | | Introduce GIT_OPT_SET_ODB_LOOSE_PRIORITY and GIT_OPT_SET_ODB_PACKED_PRIORITY to allow overriding the default priority values for the default ODB backends. Libgit2 has historically assumed that most objects for long- running operations will be packed, therefore GIT_LOOSE_PRIORITY is set to 1 by default, and GIT_PACKED_PRIORITY to 2. When a client allows libgit2 to set the default backends, they can specify an override for the two priority values in order to change the order in which each ODB backend is accessed.
* blob: add underscore to `from` functionsEdward Thomson2019-06-162-5/+5
| | | | | | The majority of functions are named `from_something` (with an underscore) instead of `fromsomething`. Update the blob functions for consistency with the rest of the library.
* Fix a memory leak in odb_otype_fast()lhchavez2019-02-201-0/+21
| | | | This change frees a copy of a cached object in odb_otype_fast().
* git_error: use new names in internal APIs and usageEdward Thomson2019-01-223-3/+3
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* Fix odb foreach to also close on positive error codeMarijan Ć uflaj2019-01-201-0/+15
| | | | | | | | In include/git2/odb.h it states that callback can also return positive value which should break looping. Implementations of git_odb_foreach() and pack_backend__foreach() did not respect that.
* object_type: use new enumeration namesethomson/index_fixesEdward Thomson2018-12-0113-59/+59
| | | | Use the new object_type enumeration names within the codebase.
* Convert usage of `git_buf_free` to new `git_buf_dispose`Patrick Steinhardt2018-06-104-5/+5
|
* odb: fix writing to fake write streamsPatrick Steinhardt2018-03-231-0/+8
| | | | | | | | | | | | | | | | | | In commit 7ec7aa4a7 (odb: assert on logic errors when writing objects, 2018-02-01), the check for whether we are trying to overflowing the fake stream buffer was changed from returning an error to raising an assert. The conversion forgot though that the logic around `assert`s are basically inverted. Previously, if the statement stream->written + len > steram->size evaluated to true, we would return a `-1`. Now we are asserting that this statement is true, and in case it is not we will raise an error. So the conversion to the `assert` in fact changed the behaviour to the complete opposite intention. Fix the assert by inverting its condition again and add a regression test.
* tests: add tests for the mempack ODB backendPatrick Steinhardt2018-03-231-0/+52
| | | | | | Our mempack ODB backend has no test coverage at all right now. Add a simple test suite to at least have some coverage of the most basic operations on the ODB.
* odb: error when we can't create object headerEdward Thomson2018-02-091-3/+3
| | | | | Return an error to the caller when we can't create an object header for some reason (printf failure) instead of simply asserting.
* odb_loose: largefile tests only on 64 bit platformsEdward Thomson2018-02-011-1/+14
| | | | | | | | Only run the large file tests on 64 bit platforms. Even though we support streaming reads on objects, and do not need to fit them in memory, we use `size_t` in various places to reflect the size of an object.
* odb_loose: test read_header on large blobsEdward Thomson2018-02-011-0/+16
| | | | | | Test that we can read_header on large blobs. This should succeed on all platforms since we read only a few bytes into memory to be able to parse the header.
* odb_loose: test read_header explicitlyEdward Thomson2018-02-011-0/+30
|
* odb: test loose object streamingEdward Thomson2018-02-011-0/+54
|
* odb_loose: test reading a large file in streamEdward Thomson2018-02-011-1/+47
| | | | | | Since some test situations may have generous disk space, but limited RAM (eg hosted build agents), test that we can stream a large file into a loose object, and then stream it out of the loose object storage.
* odb: reject reading and writing null OIDsPatrick Steinhardt2018-01-261-0/+18
| | | | | | | | | The null OID (hash with all zeroes) indicates a missing object in upstream git and is thus not a valid object ID. Add defensive measurements to avoid writing such a hash to the object database in the very unlikely case where some data results in the null OID. Furthermore, add shortcuts when reading the null OID from the ODB to avoid ever returning an object when a faulty repository may contain the null OID.
* tests: add GITTEST_SLOW env var checkethomson/large_loose_blobsEdward Thomson2017-12-201-13/+11
| | | | | | | | | Writing very large files may be slow, particularly on inefficient filesystems and when running instrumented code to detect invalid memory accesses (eg within valgrind or similar tools). Introduce `GITTEST_SLOW` so that tests that are slow can be skipped by the CI system.
* odb_loose: reject objects that cannot fit in memoryEdward Thomson2017-12-201-0/+21
| | | | | | | Check the size of objects being read from the loose odb backend and reject those that would not fit in memory with an error message that reflects the actual problem, instead of error'ing later with an unintuitive error message regarding truncation or invalid hashes.
* odb: test loose reading/writing large objectsEdward Thomson2017-12-201-0/+95
| | | | | | | Introduce a test for very large objects in the ODB. Write a large object (5 GB) and ensure that the write succeeds and provides us the expected object ID. Introduce a test that writes that file and ensures that we can subsequently read it.
* tests: odb: add more low-level backend testsPatrick Steinhardt2017-06-131-0/+232
| | | | | | | Introduce a new test suite "odb::backend::simple", which utilizes the fake backend to exercise the ODB abstraction layer. While such tests already exist for the case where multiple backends are put together, no direct testing for functionality with a single backend exist yet.
* tests: odb: implement `exists_prefix` for the fake backendPatrick Steinhardt2017-06-132-0/+22
| | | | | | The fake backend currently implements all reading functions except for the `exists_prefix` one. Implement it to enable further testing of the ODB layer.
* tests: odb: use correct OID lengthPatrick Steinhardt2017-06-131-1/+1
| | | | | | | | The `search_object` function takes the OID length as one of its parameters, where its maximum length is `GIT_OID_HEXSZ`. The `exists` function of the fake backend used `GIT_OID_RAWSZ` though, leading to only the first half of the OID being used when finding the correct object.
* tests: odb: have the fake backend detect ambiguous prefixesPatrick Steinhardt2017-06-131-26/+32
| | | | | | | | In order to be able to test the ODB prefix functions, we need to be able to detect ambiguous prefixes in case multiple objects with the same prefix exist in the fake ODB. Extend `search_object` to detect ambiguous queries and have callers return its error code instead of always returning `GIT_ENOTFOUND`.
* tests: odb: add tests with multiple backendsPatrick Steinhardt2017-06-121-0/+121
| | | | | | | | | | | | | | Previous to pulling out and extending the fake backend, it was quite cumbersome to write tests for very specific scenarios regarding backends. But as we have made it more generic, it has become much easier to do so. As such, this commit adds multiple tests for scenarios with multiple backends for the ODB. The changes also include a test for a very targeted scenario. When one backend found a matching object via `read_prefix`, but the last backend returns `GIT_ENOTFOUND` and when object hash verification is turned off, we fail to reset the error code to `GIT_OK`. This causes us to segfault later on, when doing a double-free on the returned object.
* tests: odb: allow passing fake objects to the fake backendPatrick Steinhardt2017-06-123-76/+78
| | | | | | | | | | | | | | Right now, the fake backend is quite restrained in the way how it works: we pass it an OID which it is to return later as well as an error code we want it to return. While this is sufficient for existing tests, we can make the fake backend a little bit more generic in order to allow us testing for additional scenarios. To do so, we change the backend to not accept an error code and OID which it is to return for queries, but instead a simple array of OIDs with their respective blob contents. On each query, the fake backend simply iterates through this array and returns the first matching object.
* tests: do not reuse OID from backendPatrick Steinhardt2017-06-121-8/+17
| | | | | | | In order to make the fake backend more useful, we want to enable it holding multiple object references. To do so, we need to decouple it from the single fake OID it currently holds, which we simply move up into the calling tests.
* tests: odb: move fake backend into its own filePatrick Steinhardt2017-06-123-137/+149
| | | | | | The fake backend used by the test suite `odb::backend::nonrefreshing` is useful to have some low-level tests for the ODB layer. As such, we move the implementation into its own `backend_helpers` module.
* settings: rename `GIT_OPT_ENABLE_SYNCHRONOUS_OBJECT_CREATION`Patrick Steinhardt2017-06-081-2/+2
| | | | | | | | | | | Initially, the setting has been solely used to enable the use of `fsync()` when creating objects. Since then, the use has been extended to also cover references and index files. As the option is not yet part of any release, we can still correct this by renaming the option to something more sensible, indicating not only correlation to objects. This commit renames the option to `GIT_OPT_ENABLE_FSYNC_GITDIR`. We also move the variable from the object to repository source code.
* odb: verify object hashesPatrick Steinhardt2017-04-281-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The upstream git.git project verifies objects when looking them up from disk. This avoids scenarios where objects have somehow become corrupt on disk, e.g. due to hardware failures or bit flips. While our mantra is usually to follow upstream behavior, we do not do so in this case, as we never check hashes of objects we have just read from disk. To fix this, we create a new error class `GIT_EMISMATCH` which denotes that we have looked up an object with a hashsum mismatch. `odb_read_1` will then, after having read the object from its backend, hash the object and compare the resulting hash to the expected hash. If hashes do not match, it will return an error. This obviously introduces another computation of checksums and could potentially impact performance. Note though that we usually perform I/O operations directly before doing this computation, and as such the actual overhead should be drowned out by I/O. Running our test suite seems to confirm this guess. On a Linux system with best-of-five timings, we had 21.592s with the check enabled and 21.590s with the ckeck disabled. Note though that our test suite mostly contains very small blobs only. It is expected that repositories with bigger blobs may notice an increased hit by this check. In addition to a new test, we also had to change the odb::backend::nonrefreshing test suite, which now triggers a hashsum mismatch when looking up the commit "deadbeef...". This is expected, as the fake backend allocated inside of the test will return an empty object for the OID "deadbeef...", which will obviously not hash back to "deadbeef..." again. We can simply adjust the hash to equal the hash of the empty object here to fix this test.
* tests: odb: make hash of fake backend configurablePatrick Steinhardt2017-04-281-12/+14
| | | | | | | | | | | | | In the odb::backend::nonrefreshing test suite, we set up a fake backend so that we are able to determine if backend functions are called correctly. During the setup, we also parse an OID which is later on used to read out the pseudo-object. While this procedure works right now, it will create problems later when we implement hash verification for looked up objects. The current OID ("deadbeef") will not match the hash of contents we give back to the ODB layer and thus cannot be verified. Make the hash configurable so that we can simply switch the returned for single tests.
* win32: enable `p_utimes` for readonly filesEdward Thomson2017-04-051-0/+25
| | | | | Instead of failing to set the timestamp of a read-only file (like any object file), set it writable temporarily to update the timestamp.
* Merge pull request #4030 from libgit2/ethomson/fsyncEdward Thomson2017-03-221-0/+55
|\ | | | | fsync all the things
| * Honor `core.fsyncObjectFiles`ethomson/fsyncEdward Thomson2017-03-021-0/+21
| |
| * fsync: call it "synchronous" object writingEdward Thomson2017-02-281-2/+2
| | | | | | | | | | Rename `GIT_OPT_ENABLE_SYNCHRONIZED_OBJECT_CREATION` -> `GIT_OPT_ENABLE_SYNCHRONOUS_OBJECT_CREATION`.
| * odb_loose: fsync testsEdward Thomson2017-02-281-0/+34
| | | | | | | | | | | | | | Introduce a simple counter that `p_fsync` implements. This is useful for ensuring that `p_fsync` is called when we expect it to be, for example when we have enabled an odb backend to perform `fsync`s when writing objects.
* | git_commit_create: freshen tree objects in commitethomson/freshen_treesEdward Thomson2017-03-031-16/+81
|/ | | | Freshen the tree object that a commit points to during commit time.
* tests: update error message checkingethomson/error_msgsEdward Thomson2016-12-291-1/+1
|
* revwalk: introduce tests that hide old commitsEdward Thomson2016-10-061-4/+4
| | | | | | Introduce some tests that show some commits, while hiding some commits that have a timestamp older than the common ancestors of these two commits.
* odb: only provide the empty treeEdward Thomson2016-08-051-14/+15
| | | | | | | Only provide the empty tree internally, which matches git's behavior. If we provide the empty blob then any users trying to write it with libgit2 would omit it from actually landing in the odb, which appear to git proper as a broken repository (missing that object).
* odb: only freshen pack files every 2 secondsethomson/refresh_objectsEdward Thomson2016-08-041-0/+14
| | | | | | Since writing multiple objects may all already exist in a single packfile, avoid freshening that packfile repeatedly in a tight loop. Instead, only freshen pack files every 2 seconds.