summaryrefslogtreecommitdiff
path: root/src/pack-objects.c
Commit message (Collapse)AuthorAgeFilesLines
* str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstrEdward Thomson2021-10-171-22/+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
|
* packbuilder: don't try to malloc(0)Edward Thomson2021-07-191-10/+16
|
* Allow compilation on systems without CLOCK_MONOTONICPeter Pettersson2021-07-151-2/+2
| | | | | | | | Makes usage of CLOCK_MONOTONIC conditional and makes functions that uses git__timer handle clock resynchronization. Call gettimeofday with tzp set to NULL as required by https://pubs.opengroup.org/onlinepubs/9699919799/functions/gettimeofday.html
* threads: rename thread files to thread.[ch]Edward Thomson2020-12-061-1/+1
|
* util: move git_online_cpus into utilEdward Thomson2020-12-061-1/+1
| | | | | | The number of CPUs is useful information for creating a thread pool or a number of workers, but it's not really about threading directly. Evict it from the thread file
* packbuilder: use git__noop on non-threaded systemsEdward Thomson2020-12-051-1/+1
| | | | Our git_packbuilder__cache_lock function returns a value; use git__noop.
* pack-objects: use GIT_ASSERTEdward Thomson2020-11-271-29/+25
|
* pack: use GIT_ASSERTEdward Thomson2020-11-271-4/+3
|
* buffer: git_buf_sanitize should return a valueEdward Thomson2020-11-251-1/+6
| | | | | | `git_buf_sanitize` is called with user-input, and wants to sanity-check that input. Allow it to return a value if the input was malformed in a way that we cannot cope.
* tree-wide: mark local functions as staticPatrick Steinhardt2020-06-091-5/+5
| | | | | | | We've accumulated quite some functions which are never used outside of their respective code unit, but which are lacking the `static` keyword. Add it to reduce their linkage scope and allow the compiler to optimize better.
* Merge pull request #5532 from joshtriplett/pack-default-pathEdward Thomson2020-06-021-10/+21
|\ | | | | git_packbuilder_write: Allow setting path to NULL to use the default path
| * git_packbuilder_write: Allow setting path to NULL to use the default pathJosh Triplett2020-05-231-0/+10
| | | | | | | | | | | | If given a NULL path, write to the object path of the repository. Add tests for the new behavior.
| * git_packbuilder_write: Unify cleanup pathJosh Triplett2020-05-231-10/+11
| | | | | | | | | | | | Clean up and return via a single label, to avoid duplicate error handling before each return, and to make it easier to extend the set of cleanups needed.
* | git_pool_init: handle failure casesethomson/poolinitEdward Thomson2020-06-011-6/+3
|/ | | | Propagate failures caused by pool initialization errors.
* pack-objects: check return code of `git_zstream_set_input`Patrick Steinhardt2020-02-071-1/+3
| | | | | | While `git_zstream_set_input` cannot fail right now, it might change in the future if we ever decide to have it check its parameters more vigorously. Let's thus check whether its return code signals an error.
* configuration: cvar -> configmapPatrick Steinhardt2019-07-181-1/+1
| | | | | `cvar` is an unhelpful name. Refactor its usage to `configmap` for more clarity.
* pack-objects: allocate memory more efficientlybrian m. carlson2019-07-171-1/+1
| | | | | | | | | | | | | | | | | | The packbuilder code allocates memory in chunks. When it needs to allocate, it tries to add 1024 to the number of objects and multiply by 3/2. However, it actually multiplies by 1 instead, since it performs an integral division in the expression "3 / 2" and only then multiplies by the increased number of objects. The current behavior causes the code to waste massive amounts of time copying memory when it reallocates, causing inserting all non-blob objects in the Linux repository into a new pack to take some indeterminate time greater than 5 minutes instead of 52 seconds. Correct this error by first dividing by two, and only then multiplying by 3. We still check for overflow for the multiplication, which is the only part that can overflow. This appears to be the only place in the code base which has this problem.
* indexer: use git_indexer_progress throughoutEdward Thomson2019-02-221-3/+3
| | | | | Update internal usage of `git_transfer_progress` to `git_indexer_progreses`.
* oidmap: introduce high-level setter for key/value pairsPatrick Steinhardt2019-02-151-13/+15
| | | | | | | | | | | | | | | Currently, one would use either `git_oidmap_insert` to insert key/value pairs into a map or `git_oidmap_put` to insert a key only. These function have historically been macros, which is why their syntax is kind of weird: instead of returning an error code directly, they instead have to be passed a pointer to where the return value shall be stored. This does not match libgit2's common idiom of directly returning error codes.Furthermore, `git_oidmap_put` is tightly coupled with implementation details of the map as it exposes the index of inserted entries. Introduce a new function `git_oidmap_set`, which takes as parameters the map, key and value and directly returns an error code. Convert all trivial callers of `git_oidmap_insert` and `git_oidmap_put` to make use of it.
* oidmap: introduce high-level getter for valuesPatrick Steinhardt2019-02-151-10/+3
| | | | | | | | | | | | | | The current way of looking up an entry from a map is tightly coupled with the map implementation, as one first has to look up the index of the key and then retrieve the associated value by using the index. As a caller, you usually do not care about any indices at all, though, so this is more complicated than really necessary. Furthermore, it invites for errors to happen if the correct error checking sequence is not being followed. Introduce a new high-level function `git_oidmap_get` that takes a map and a key and returns a pointer to the associated value if such a key exists. Otherwise, a `NULL` pointer is returned. Adjust all callers that can trivially be converted.
* maps: use uniform lifecycle management functionsPatrick Steinhardt2019-02-151-4/+2
| | | | | | | | | | | | | | | | Currently, the lifecycle functions for maps (allocation, deallocation, resize) are not named in a uniform way and do not have a uniform function signature. Rename the functions to fix that, and stick to libgit2's naming scheme of saying `git_foo_new`. This results in the following new interface for allocation: - `int git_<t>map_new(git_<t>map **out)` to allocate a new map, returning an error code if we ran out of memory - `void git_<t>map_free(git_<t>map *map)` to free a map - `void git_<t>map_clear(git<t>map *map)` to remove all entries from a map This commit also fixes all existing callers.
* git_error: use new names in internal APIs and usageEdward Thomson2019-01-221-28/+28
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* object_type: use new enumeration namesethomson/index_fixesEdward Thomson2018-12-011-16/+16
| | | | Use the new object_type enumeration names within the codebase.
* khash: remove intricate knowledge of khash typesPatrick Steinhardt2018-11-281-6/+4
| | | | | | | Instead of using the `khiter_t`, `git_strmap_iter` and `khint_t` types, simply use `size_t` instead. This decouples code from the khash stuff and makes it possible to move the khash includes into the implementation files.
* fix check if blob is uninteresting when inserting tree to packbuilderAnders Borum2018-10-011-1/+1
| | | | | | | | Blobs that have been marked as uninteresting should not be inserted into packbuilder when inserting a tree. The check as to whether a blob was uninteresting looked at the status for the tree itself instead of the blob. This could cause significantly larger packfiles.
* indexer: introduce options struct to `git_indexer_new`Patrick Steinhardt2018-06-221-1/+5
| | | | | | | | | | We strive to keep an options structure to many functions to be able to extend options in the future without breaking the API. `git_indexer_new` doesn't have one right now, but we want to be able to add an option for enabling strict packfile verification. Add a new `git_indexer_options` structure and adjust callers to use that.
* pack-objects: make `git_walk_object` internal to pack-objectsPatrick Steinhardt2018-06-221-10/+16
| | | | | | | | | | | The `git_walk_objects` structure is currently only being used inside of the pack-objects.c file, but being declared in its header. This has actually been the case since its inception in 04a36feff (pack-objects: fill a packbuilder from a walk, 2014-10-11) and has never really changed. Move the struct declaration into pack-objects.c to improve code encapsulation.
* Convert usage of `git_buf_free` to new `git_buf_dispose`Patrick Steinhardt2018-06-101-2/+2
|
* Merge pull request #4028 from chescock/improve-local-fetchEdward Thomson2017-12-301-1/+5
|\ | | | | Transfer fewer objects on push and local fetch
| * Don't fetch objects we don't need in local transport.Chris Hescock2016-12-201-1/+5
| | | | | | | | | | Hide all local refs in the revwalk. Packbuilder should not add hidden trees or blobs.
* | Honor `core.fsyncObjectFiles`ethomson/fsyncEdward Thomson2017-03-021-0/+4
| |
* | oidmap: remove GIT__USE_OIDMAP macroPatrick Steinhardt2017-02-171-2/+0
| |
* | khash: avoid using macro magic to get return addressPatrick Steinhardt2017-02-171-1/+1
| |
* | khash: avoid using `kh_key`/`kh_val` as lvaluePatrick Steinhardt2017-02-171-2/+2
| |
* | khash: avoid using `kh_put` directlyPatrick Steinhardt2017-02-171-2/+2
| |
* | khash: avoid using `kh_val`/`kh_value` directlyPatrick Steinhardt2017-02-171-3/+3
| |
* | khash: avoid using `kh_clear` directlyPatrick Steinhardt2017-02-171-1/+1
| |
* | khash: avoid using `kh_get` directlyPatrick Steinhardt2017-02-171-1/+1
| |
* | khash: avoid using `kh_end` directlyPatrick Steinhardt2017-02-171-1/+1
| |
* | khash: use `git_map_exists` where applicablePatrick Steinhardt2017-02-171-2/+1
| |
* | pack: report revwalk errorEtienne Samson2017-01-131-1/+1
| |
* | 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
* packbuilder: `size_t` all the thingsEdward Thomson2016-07-241-63/+85
| | | | | | | | After 1cd65991, we were passing a pointer to an `unsigned long` to a function that now expected a pointer to a `size_t`. These types differ on 64-bit Windows, which means that we trash the stack. Use `size_t`s in the packbuilder to avoid this.
* Merge pull request #3223 from ethomson/applyEdward Thomson2016-06-251-14/+21
|\ | | | | Reading patch files
| * patch: formatting cleanupsEdward Thomson2016-05-261-1/+1
| |
| * zstream: offer inflating, `git_zstream_inflatebuf`Edward Thomson2016-05-261-1/+1
| | | | | | | | Introduce `git_zstream_inflatebuf` for simple uses.
| * delta: refactor git_delta functions for consistencyEdward Thomson2016-05-261-13/+20
| | | | | | | | | | Refactor the git_delta functions to have consistent naming and parameters with the rest of the library.
* | threads: split up OS-dependent thread codePatrick Steinhardt2016-06-201-1/+1
|/