summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* | diff_print: handle errors when printing to filePatrick Steinhardt2020-06-171-5/+18
|/ | | | | | | | | | | When printing the diff to a `FILE *` handle, we neither check the return value of fputc(3P) nor the one of fwrite(3P). As a result, we'll silently return successful even if we didn't print anything at all. Futhermore, the arguments to fwrite(3P) are reversed: we have one item of length `content_len`, and not `content_len` items of one byte. Fix both issues by checking return values as well as reversing the arguments to fwrite(3P).
* Merge pull request #5552 from libgit2/pks/small-fixesEdward Thomson2020-06-132-55/+14
|\ | | | | Random code cleanups and fixes
| * checkout: remove unused code for deferred removalspks/small-fixesPatrick Steinhardt2020-06-081-53/+11
| | | | | | | | | | | | | | | | | | | | | | With commit 05f690122 (checkout: remove blocking dir when FORCEd, 2015-03-31), the last case was removde that actually queued a deferred removal. This is now more than five years in the past and nobody complained, so we can rest quite assured that the deferred removal is not really needed at all. Let's remove all related code to simplify the already complicated checkout logic.
| * revparse: remove superfluous tab characterPatrick Steinhardt2020-06-081-1/+1
| |
| * revparse: detect out-of-memory cases when parsing curly brace contentsPatrick Steinhardt2020-06-081-1/+2
| | | | | | | | | | | | | | | | | | | | When extracting curly braces (e.g. the "upstream" part in "HEAD@{upstream}"), we put the curly braces' contents into a `git_buf` structure, but don't check the return value of `git_buf_putc`. So when we run out-of-memory, we'll use a partially filled buffer without noticing. Let's fix this issue by checking `git_buf_putc`'s return value.
* | cmake: enable warnings for missing function declarationsPatrick Steinhardt2020-06-091-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Over time, we have accumulated quite a lot of functions with missing prototypes, missing `static` keywords or which were completely unused. It's easy to miss these mistakes, but luckily GCC and Clang both have the `-Wmissing-declarations` warning. Enabling this will cause them to emit warnings for every not-static function that doesn't have a previous declaration. This is a very sane thing to enable, and with the preceding commits all these new warnings have been fixed. So let's always enable this warning so we won't introduce new instances of them.
* | refs: add missing function declarationPatrick Steinhardt2020-06-091-0/+1
| | | | | | | | | | | | The function `git_reference__is_note` is not declared anywhere. Let's add the declaration to avoid having non-static functions without declaration.
* | tree-wide: do not compile deprecated functions with hard deprecationPatrick Steinhardt2020-06-0930-1/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When compiling libgit2 with -DDEPRECATE_HARD, we add a preprocessor definition `GIT_DEPRECATE_HARD` which causes the "git2/deprecated.h" header to be empty. As a result, no function declarations are made available to callers, but the implementations are still available to link against. This has the problem that function declarations also aren't visible to the implementations, meaning that the symbol's visibility will not be set up correctly. As a result, the resulting library may not expose those deprecated symbols at all on some platforms and thus cause linking errors. Fix the issue by conditionally compiling deprecated functions, only. While it becomes impossible to link against such a library in case one uses deprecated functions, distributors of libgit2 aren't expected to pass -DDEPRECATE_HARD anyway. Instead, users of libgit2 should manually define GIT_DEPRECATE_HARD to hide deprecated functions. Using "real" hard deprecation still makes sense in the context of CI to test we don't use deprecated symbols ourselves and in case a dependant uses libgit2 in a vendored way and knows it won't ever use any of the deprecated symbols anyway.
* | tree-wide: add missing header includesPatrick Steinhardt2020-06-093-4/+7
| | | | | | | | | | | | | | We're missing some header includes leading to missing function prototypes. While we currently don't warn about these, we should have their respective headers included in order to detect the case where a function signature change results in an incompatibility.
* | tree-wide: mark local functions as staticPatrick Steinhardt2020-06-0920-61/+59
| | | | | | | | | | | | | | 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.
* | tree-wide: remove unused functionsPatrick Steinhardt2020-06-084-53/+0
|/ | | | | We have some functions which aren't used anywhere. Let's remove them to get rid of unneeded baggage.
* Merge pull request #5536 from libgit2/ethomson/httpPatrick Steinhardt2020-06-031-4/+16
|\ | | | | httpclient: support googlesource
| * httpclient: clear the read_buf on new requestsethomson/httpEdward Thomson2020-06-021-1/+4
| | | | | | | | | | | | | | | | | | | | | | The httpclient implementation keeps a `read_buf` that holds the data in the body of the response after the headers have been written. We store that data for subsequent calls to `git_http_client_read_body`. If we want to stop reading body data and send another request, we need to clear that cached data. Clear the cached body data on new requests, just like we read any outstanding data from the socket.
| * httpclient: don't read more than the client wantsEdward Thomson2020-06-011-0/+4
| | | | | | | | | | | | | | When `git_http_client_read_body` is invoked, it provides the size of the buffer that can be read into. This will be set as the parser context's `output_size` member. Use this as an upper limit on our reads, and ensure that we do not read more than the client requests.
| * httpclient: read_body should return 0 at EOFEdward Thomson2020-06-011-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | When users call `git_http_client_read_body`, it should return 0 at the end of a message. When the `on_message_complete` callback is called, this will set `client->state` to `DONE`. In our read loop, we look for this condition and exit. Without this, when there is no data left except the end of message chunk (`0\r\n`) in the http stream, we would block by reading the three bytes off the stream but not making progress in any `on_body` callbacks. Listening to the `on_message_complete` callback allows us to stop trying to read from the socket when we've read the end of message chunk.
* | 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.
* | | Merge pull request #5531 from joshtriplett/mempack-threadsEdward Thomson2020-06-021-0/+2
|\ \ \ | | | | | | | | mempack: Use threads when building the pack
| * | | mempack: Use threads when building the packJosh Triplett2020-05-231-0/+2
| |/ / | | | | | | | | | | | | | | | The mempack ODB backend creates a packbuilder internally to write out a pack; call git_packbuilder_set_threads on that packbuilder, to use threads for packing if available.
* | | strarray: we should `dispose` instead of `free`Edward Thomson2020-06-016-9/+14
| | | | | | | | | | | | | | | | | | We _dispose_ the contents of objects; we _free_ objects (and their contents). Update `git_strarray_free` to be `git_strarray_dispose`. `git_strarray_free` remains as a deprecated proxy function.
* | | strarray: move to its own fileEdward Thomson2020-06-012-46/+56
| |/ |/|
* | Merge pull request #5526 from libgit2/ethomson/poolinitPatrick Steinhardt2020-06-0118-52/+56
|\ \ | | | | | | git_pool_init: allow the function to fail
| * | git_pool_init: handle failure casesethomson/poolinitEdward Thomson2020-06-0116-49/+49
| | | | | | | | | | | | Propagate failures caused by pool initialization errors.
| * | git_pool_init: return an intEdward Thomson2020-05-232-3/+7
| | | | | | | | | | | | Let `git_pool_init` return an int so that it could fail.
* | | Merge pull request #5527 from libgit2/ethomson/config_unreadablePatrick Steinhardt2020-06-011-0/+9
|\ \ \ | | | | | | | | Handle unreadable configuration files
| * | | config: ignore unreadable configuration filesWil Shipley2020-06-011-0/+9
| | |/ | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Modified `config_file_open()` so it returns 0 if the config file is not readable, which happens on global config files under macOS sandboxing (note that for some reason `access(F_OK)` DOES work with sandboxing, but it is lying). Without this read check sandboxed applications on macOS can not open any repository, because `config_file_read()` will return GIT_ERROR when it cannot read the global /Users/username/.gitconfig file, and the upper layers will just completely abort on GIT_ERROR when attempting to load the global config file, so no repositories can be opened.
* | | index: write v4: bugfix: prefix path with strip_len, not same_lenPatrick Wang2020-05-261-2/+2
|/ / | | | | | | | | According to index-format.txt of git, the path of an entry is prefixed with N, where N indicates the length of bytes to be stripped.
* | Merge pull request #5522 from pks-t/pks/openssl-cert-memleakEdward Thomson2020-05-231-6/+12
|\ \ | |/ |/| OpenSSL certificate memory leak
| * streams: openssl: fix memleak due to us not free'ing certsPatrick Steinhardt2020-05-151-6/+12
| | | | | | | | | | | | | | | | | | When creating a `git_cert` from the OpenSSL X509 certificate of a given stream, we do not call `X509_free()` on the certificate, leading to a memory leak as soon as the certificate is requested e.g. by the certificate check callback. Fix the issue by properly calling `X509_free()`.
* | Merge pull request #5515 from pks-t/pks/flaky-checkout-testEdward Thomson2020-05-231-3/+4
|\ \ | | | | | | tests: checkout: fix flaky test due to mtime race
| * | checkout: fix file being treated as unmodified due to racy indexPatrick Steinhardt2020-05-161-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When trying to determine whether a file changed, we try to avoid heavy operations by fist taking a look at the index, seeing whether the index entry is modified already. This doesn't seem to cut it, though, as we currently have the racy checkout::index::can_disable_pathspec_match test case: sometimes the files get restored to their original contents, sometimes they aren't. The issue is caused by a racy index [1]: in case we modify a file, add it to the index and then modify it again in-place without changing its file, then we may end up with a modified file that has the same stat(3P) info as we've currently got it in its corresponding index entry. The mitigation for this is to treat files with the same mtime as the index are treated as racily modified. We already have this logic in place for the index, but not when doing a checkout. Fix the issue by only consulting the index entry in case it has an older mtime as the index. Previously, the following script reliably had at least 20 failures, while now there is no failure to be observed anymore: ```bash j=0 for i in $(seq 100) do if ! ./libgit2_clar -scheckout::index::can_disable_pathspec_match >/dev/null then j=$(($j + 1)) fi done echo "Failures: $j" ``` [1]: https://git-scm.com/docs/racy-git
* | | Merge pull request #5523 from libgit2/pks/cmake-sort-reproducible-buildsEdward Thomson2020-05-231-17/+23
|\ \ \ | |/ / |/| | cmake: Sort source files for reproducible builds
| * | cmake: Sort source files for reproducible buildspks/cmake-sort-reproducible-buildsPatrick Steinhardt2020-05-151-17/+23
| |/ | | | | | | | | | | | | | | | | | | | | We currently use `FILE(GLOB ...)` in most places to find source and header files. This is problematic in that the order of files returned depends on the operating system's directory iteration order and may thus not be deterministic. As a result, we link object files in unspecified order, which may cause the linker to emit different code across runs. Fix this issue by sorting all code used as input to the libgit2 library to improve the reliability of reproducible builds.
* | futils: fix order of declared parameters for `git_futils_fake_symlink`pks/futils-symlink-argsPatrick Steinhardt2020-05-122-6/+6
|/ | | | | | | | | While the function `git_futils_fake_symlink` is declared with arguments `new, old`, the implementation uses the reverse order `old, new`. Let's fix the ordering issues to be `new, old` for both, which matches what symlink(3P) has. While at it, we also rename these parameters: `old` and `new` doesn't really make a lot of sense in the context of symlinks, which is why this commit renames them to be called `target` and `path`.
* assert: allow non-int returning functions to assertethomson/assert_macrosEdward Thomson2020-05-111-14/+21
| | | | | | | | | | Include GIT_ASSERT_WITH_RETVAL and GIT_ASSERT_ARG_WITH_RETVAL so that functions that do not return int (or more precisely, where `-1` would not be an error code) can assert. This allows functions that return, eg, NULL on an error code to do that by passing the return value (in this example, `NULL`) as a second parameter to the GIT_ASSERT_WITH_RETVAL functions.
* assert: optionally fall-back to assert(3)Edward Thomson2020-05-112-27/+52
| | | | | | | | | Fall back to the system assert(3) in debug builds, which may aide in debugging. "Safe" assertions can be enabled in debug builds by setting GIT_ASSERT_HARD=0. Similarly, hard assertions can be enabled in release builds by setting GIT_ASSERT_HARD to nonzero.
* Introduce GIT_ASSERT macrosEdward Thomson2020-05-111-0/+27
| | | | | | | | | | | | Provide macros to replace usages of `assert`. A true `assert` is punishing as a library. Instead we should do our best to not crash. GIT_ASSERT_ARG(x) will now assert that the given argument complies to some format and sets an error message and returns `-1` if it does not. GIT_ASSERT(x) is for internal usage, and available as an internal consistency check. It will set an error message and return `-1` in the event of failure.
* Fix uninitialized stack memory and NULL ptr dereference in stash_to_indexPhilip Kelley2020-05-101-2/+2
| | | | Caught by static analysis.
* checkout: Fix removing untracked files by path in subdirectoriesSegev Finer2020-05-111-2/+7
| | | | | | | | The checkout code didn't iterate into a subdir if it didn't match the pathspec, but since the pathspec might match files in the subdir we should recurse into it (In contrast to gitignore handling). Fixes #5089
* checkout: filter pathspecs for _all_ checkout typesethomson/checkout_pathspecsEdward Thomson2020-05-101-9/+20
| | | | | | | | | | We were previously applying the pathspec filter for the baseline iterator during checkout, as well as the target tree. This was an oversight; in fact, we should apply the pathspec filter to _all_ checkout targets, not just trees. Add a helper function to set the iterator pathspecs from the given checkout pathspecs, and call it everywhere.
* Merge pull request #5431 from libgit2/ethomson/hexdumpEdward Thomson2020-05-101-9/+22
|\ | | | | git__hexdump: better mimic `hexdump -C`
| * git__hexdump: better mimic `hexdump -C`ethomson/hexdumpEdward Thomson2020-04-011-9/+22
| |
* | blame: add option to ignore whitespace changesCarl Schwan2020-04-141-3/+6
| |
* | Merge pull request #5485 from libgit2/ethomson/sysdir_unusedPatrick Steinhardt2020-04-052-30/+0
|\ \ | | | | | | sysdir: remove unused git_sysdir_get_str
| * | sysdir: remove unused git_sysdir_get_strethomson/sysdir_unusedEdward Thomson2020-04-052-30/+0
| | |
* | | Fix typo causing removal of symbol 'git_worktree_prune_init_options'Seth Junot2020-04-041-1/+1
|/ / | | | | | | | | | | Commit 0b5ba0d replaced this function with an "option_init" equivallent, but misspelled the replacement function. As a result, this symbol has been missing from libgit2.so ever since.
* | Merge pull request #5425 from lhchavez/fix-get-delta-basePatrick Steinhardt2020-04-043-26/+44
|\ \ | | | | | | pack: Improve error handling for get_delta_base()
| * | Re-adding the "delta offset is zero" error caselhchavez2020-04-021-0/+6
| | |
| * | Making get_delta_base() conform to the general error-handling patternlhchavez2020-04-013-25/+29
| | | | | | | | | | | | | | | This makes get_delta_base() return the error code as the return value and the delta base as an out-parameter.