summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
| * | | global: convert all users of POSIX regex to use our new regexp APIPatrick Steinhardt2019-09-215-81/+66
| | | | | | | | | | | | | | | | | | | | The old POSIX regex API has been superseded by our new regexp API. Convert all users to make use of the new one.
| * | | regexp: implement new regular expression APIPatrick Steinhardt2019-09-212-0/+318
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We currently support a set of different regular expression backends with PCRE, PCRE2, regcomp(3P) and regcomp_l(3). The current implementation of this is done via a simple POSIX wrapper that either directly uses supplied functions or that is a very small wrapper. To support PCRE and PCRE2, we use their provided <pcreposix.h> and <pcre2posix.h> wrappers. These wrappers are implemented in such a way that the accompanying libraries pcre-posix and pcre2-posix provide the same symbols as the libc ones, namely regcomp(3P) et al. This works out on some systems just fine, most importantly on glibc-based ones, where the regular expression functions are implemented as weak aliases and thus get overridden by linking in the pcre{,2}-posix library. On other systems we depend on the linking order of libc and pcre library, and as libc always comes first we will end up with the functions of the libc implementation. As a result, we may use the structures `regex_t` and `regmatch_t` declared by <pcre{,2}posix.h>, but use functions defined by the libc, leading to segfaults. The issue is not easily solvable. Somed distributions like Debian have resolved this by patching PCRE and PCRE2 to carry custom prefixes to all the POSIX function wrappers. But this is not supported by upstream and thus inherently unportable between distributions. We could instead try to modify linking order, but this starts becoming fragile and will not work e.g. when libgit2 is loaded via dlopen(3P) or similar ways. In the end, this means that we simply cannot use the POSIX wrappers provided by the PCRE libraries at all. Thus, this commit introduces a new regular expression API. The new API is on a tad higher level than the previous POSIX abstraction layer, as it tries to abstract away any non-portable flags like e.g. REG_EXTENDED, which has no equivalents in all of our supported backends. As there are no users of POSIX regular expressions that do _not_ reguest REG_EXTENDED this is fine to be abstracted away, though. Due to the API being higher-level than before, it should generally be a tad easier to use than the previous one. Note: ideally, the new API would've been called `git_regex_foobar` with a file "regex.h" and "regex.c". Unfortunately, this is currently impossible to implement due to naming clashes between the then-existing "regex.h" and <regex.h> provided by the libc. As we add the source directory of libgit2 to the header search path, an include of <regex.h> would always find our own "regex.h". Thus, we have to take the bitter pill of adding one more character to all the functions to disambiguate the includes. To improve guarantees around cross-backend compatibility, this commit also brings along an improved regular expression test suite core::regexp.
* | | | Merge pull request #5106 from tiennou/fix/ref-api-fixesPatrick Steinhardt2019-09-272-45/+101
|\ \ \ \ | |_|_|/ |/| | | git_refdb API fixes
| * | | refdb: make sure to remove packed refs firstEtienne Samson2019-09-051-10/+24
| | | | | | | | | | | | | | | | | | | | This fixes part of the issue where, given a concurrent `git pack-refs`, a ref lookup could return an old, vestigial value from the packed file, as the valid loose one would have been deleted.
| * | | refdb: repurpose filesystem prune functionEtienne Samson2019-09-051-6/+6
| | | |
| * | | refdb: reorder parameters for consistencyEtienne Samson2019-09-051-9/+10
| | | |
| * | | refdb: fix packed_delete clobbering some errorsEtienne Samson2019-09-051-5/+10
| | | | | | | | | | | | | | | | | | | | In the case of a failed lookup, we'd paper over that by writing back the packed-refs successfully.
| * | | refdb: make low-level deletion helpers explicitEtienne Samson2019-09-051-23/+47
| | | |
| * | | refdb: ensure all mandatory functions are provided at setup timeEtienne Samson2019-09-051-0/+10
| | | |
| * | | refdb: check the version of the backend we're about to setEtienne Samson2019-09-051-0/+2
| | | |
| * | | refdb: documentationEtienne Samson2019-09-051-1/+1
| | | |
* | | | Don't use enum for flagsSven Strickroth2019-09-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Using an `enum` causes trouble when used with C++ as bitwise operations are not possible w/o casting (e.g., `opts.flags &= ~GIT_BLOB_FILTER_CHECK_FOR_BINARY;` is invalid as there is no `&=` operator for `enum`). Signed-off-by: Sven Strickroth <email@cs-ware.de>
* | | | Merge pull request #5232 from pks-t/pks/buffer-ensure-size-oomEdward Thomson2019-09-211-7/+14
|\ \ \ \ | | | | | | | | | | buffer: fix writes into out-of-memory buffers
| * | | | buffer: fix printing into out-of-memory bufferPatrick Steinhardt2019-09-211-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before printing into a `git_buf` structure, we always call `ENSURE_SIZE` first. This macro will reallocate the buffer as-needed depending on whether the current amount of allocated bytes is sufficient or not. If `asize` is big enough, then it will just do nothing, otherwise it will call out to `git_buf_try_grow`. But in fact, it is insufficient to only check `asize`. When we fail to allocate any more bytes e.g. via `git_buf_try_grow`, then we set the buffer's pointer to `git_buf__oom`. Note that we touch neither `asize` nor `size`. So if we just check `asize > targetsize`, then we will happily let the caller of `ENSURE_SIZE` proceed with an out-of-memory buffer. As a result, we will print all bytes into the out-of-memory buffer instead, resulting in an out-of-bounds write. Fix the issue by having `ENSURE_SIZE` verify that the buffer is not marked as OOM. Add a test to verify that we're not writing into the OOM buffer.
| * | | | buffer: fix infinite loop when growing buffersPatrick Steinhardt2019-09-211-5/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When growing buffers, we repeatedly multiply the currently allocated number of bytes by 1.5 until it exceeds the requested number of bytes. This has two major problems: 1. If the current number of bytes is tiny and one wishes to resize to a comparatively huge number of bytes, then we may need to loop thousands of times. 2. If resizing to a value close to `SIZE_MAX` (which would fail anyway), then we probably hit an infinite loop as multiplying the current amount of bytes will repeatedly result in integer overflows. When reallocating buffers, one typically chooses values close to 1.5 to enable re-use of resulting memory holes in later reallocations. But because of this, it really only makes sense to use a factor of 1.5 _once_, but not looping until we finally are able to fit it. Thus, we can completely avoid the loop and just opt for the much simpler algorithm of multiplying with 1.5 once and, if the result doesn't fit, just use the target size. This avoids both problems of looping extensively and hitting overflows. This commit also adds a test that would've previously resulted in an infinite loop.
| * | | | buffer: fix memory leak if unable to grow bufferPatrick Steinhardt2019-09-211-1/+4
| | |/ / | |/| | | | | | | | | | | | | | | | | | | | | | | | | | If growing a buffer fails, we set its pointer to the static `git_buf__oom` structure. While we correctly free the old pointer if `git__malloc` returned an error, we do not free it if there was an integer overflow while calculating the new allocation size. Fix this issue by freeing the pointer to plug the memory leak.
* | | | cred: add missing private header in GSSAPI blockEtienne Samson2019-09-211-0/+1
| | | | | | | | | | | | Should have been part of 8bf0f7eb26c65b2b937b1f40a384b9b269b0b76d
* | | | Merge pull request #5206 from tiennou/cmake/pkgconfig-buildingPatrick Steinhardt2019-09-191-22/+11
|\ \ \ \ | |/ / / |/| | | CMake pkg-config modulification
| * | | cmake: add missing requires to the .pc fileEtienne Samson2019-09-141-0/+2
| | | |
| * | | cmake: streamline *.pc file handling via a moduleEtienne Samson2019-09-141-22/+9
| | | |
* | | | cred: separate public interface from low-level detailsEtienne Samson2019-09-137-22/+12
|/ / /
* | | Merge pull request #5195 from tiennou/fix/commitish-smart-pushPatrick Steinhardt2019-09-133-64/+76
|\ \ \ | | | | | | | | smart: use push_glob instead of manual filtering
| * | | smart: implement by-date insertion when revwalkingEtienne Samson2019-08-233-2/+8
| | | |
| * | | revwalk: expose more ways of scheduling commitsEtienne Samson2019-08-232-18/+65
| | | | | | | | | | | | | | | | | | | | | | | | Before we can tweak the revwalk to be more efficent when negotiating, we need to add an "insertion mode" option. Since there's already an implicit set of those, make it visible, at least privately.
| * | | smart: use push_glob instead of manual filteringEtienne Samson2019-08-211-45/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The code worked under the assumption that anything under `refs/tags` are tag objects, and all the rest would be peelable to a commit. As it is completely valid to have tags to blobs under a non `refs/tags` ref, this would cause failures when trying to peel a tag to a commit. Fix the broken filtering by switching to `git_revwalk_push_glob`, which already handles this case.
* | | | open:move all cleanup code to cleanup label in git_repository_open_extLaurence McGlashan2019-09-101-9/+7
| | | |
* | | | open:fix memory leak when passing NULL to git_repository_open_extLaurence McGlashan2019-09-101-1/+6
| | | |
* | | | Merge pull request #5209 from mkostyuk/apply-wrong-patchEdward Thomson2019-09-091-1/+1
|\ \ \ \ | | | | | | | | | | apply: Fix a patch corruption related to EOFNL handling
| * | | | apply: Fix a patch corruption related to EOFNL handlingMax Kostyukevich2019-08-201-1/+1
| |/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use of apply's API can lead to an improper patch application and a corruption of the modified file. The issue is caused by mishandling of the end of file changes if there are several hunks to apply. The new line character is added to a line from a wrong hunk. The solution is to modify apply_hunk() to add the newline character at the end of a line from a right hunk.
* | | | Merge pull request #5210 from buddyspike/masterEdward Thomson2019-09-091-3/+6
|\ \ \ \ | | | | | | | | | | ignore: correct handling of nested rules overriding wild card unignore
| * | | | ignore: correct handling of nested rules overriding wild card unignorebuddyspike2019-08-281-3/+6
| |/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | problem: filesystem_iterator loads .gitignore files in top-down order. subsequently, ignore module evaluates them in the order they are loaded. this creates a problem if we have unignored a rule (using a wild card) in a sub dir and ignored it again in a level further below (see the test included in this patch). solution: process ignores in reverse order. closes #4963
* | | | Merge pull request #5214 from pks-t/pks/diff-iterator-allocation-fixesEdward Thomson2019-09-092-79/+130
|\ \ \ \ | | | | | | | | | | Memory allocation fixes for diff generator
| * | | | iterator: remove duplicate memsetPatrick Steinhardt2019-08-271-5/+3
| | | | | | | | | | | | | | | | | | | | | | | | | When allocating new tree iterator frames, we zero out the allocated memory twice. Remove one of the `memset` calls.
| * | | | iterator: avoid leaving partially initialized frame on stackPatrick Steinhardt2019-08-271-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When allocating tree iterator entries, we use GIT_ERROR_ALLOC_CHECK` to check whether the allocation has failed. The macro will cause the function to immediately return, though, leaving behind a partially initialized iterator frame. Fix the issue by manually checking for memory allocation errors and using `goto done` in case of an error, popping the iterator frame.
| * | | | diff_generate: detect memory allocation errors when preparing optsPatrick Steinhardt2019-08-271-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When preparing options for the two iterators that are about to be diffed, we allocate a common prefix for both iterators depending on the options passed by the user. We do not check whether the allocation was successful, though. In fact, this isn't much of a problem, as using a `NULL` prefix is perfectly fine. But in the end, we probably want to detect that the system doesn't have any memory left, as we're unlikely to be able to continue afterwards anyway. While the issue is being fixed in the newly created function `diff_prepare_iterator_opts`, it has been previously existing in the previous macro `DIFF_FROM_ITERATORS` already.
| * | | | diff_generate: refactor `DIFF_FROM_ITERATORS` macro of doomPatrick Steinhardt2019-08-271-72/+121
| |/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While the `DIFF_FROM_ITERATORS` does make it shorter to implement the various `git_diff_foo_to_bar` functions, it is a complex and unreadable beast that implicitly assumes certain local variable names. This is not something desirable to have at all and obstructs understanding and more importantly debugging the code by quite a bit. The `DIFF_FROM_ITERATORS` macro basically removed the burden of having to derive the options for both iterators from a pair of iterator flags and the diff options. This patch introduces a new function that does the that exact and refactors all callers to manage the iterators by themselves. As we potentially need to allocate a shared prefix for the iterator, we need to tell the caller to allocate that prefix as soon as the options aren't required anymore. Thus, the function has a `char **prefix` out pointer that will get set to the allocated string and subsequently be free'd by the caller. While this patch increases the line count, I personally deem this to an acceptable tradeoff for increased readbiblity.
* | | | Merge pull request #5212 from libgit2/ethomson/creds_for_schemeEdward Thomson2019-09-092-9/+17
|\ \ \ \ | |_|/ / |/| | | Use an HTTP scheme that supports the given credentials
| * | | http: ensure the scheme supports the credentialsethomson/creds_for_schemeIan Hattendorf2019-08-231-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | When a server responds with multiple scheme support - for example, Negotiate and NTLM are commonly used together - we need to ensure that we choose a scheme that supports the credentials.
| * | | http: allow dummy negotiation scheme to fail to actEdward Thomson2019-08-212-5/+8
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The dummy negotiation scheme is used for known authentication strategies that do not wish to act. For example, when a server requests the "Negotiate" scheme but libgit2 is not built with Negotiate support, and will use the "dummy" strategy which will simply not act. Instead of setting `out` to NULL and returning a successful code, return `GIT_PASSTHROUGH` to indicate that it did not act and catch that error code.
* | | Merge pull request #5208 from mkostyuk/apply-removed-new-fileEdward Thomson2019-08-271-3/+6
|\ \ \ | | | | | | | | apply: git_apply_to_tree fails to apply patches that add new files
| * | | apply: git_apply_to_tree fails to apply patches that add new filesMax Kostyukevich2019-08-201-3/+6
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | git_apply_to_tree() cannot be used apply patches with new files. An attempt to apply such a patch fails because git_apply_to_tree() tries to remove a non-existing file from an old index. The solution is to modify git_apply_to_tree() to git_index_remove() when the patch states that the modified files is removed.
* | | Merge pull request #5189 from libgit2/ethomson/attrs_from_headEdward Thomson2019-08-275-14/+102
|\ \ \ | | | | | | | | Optionally read `.gitattributes` from HEAD
| * | | blob: optionally read attributes from repositoryEdward Thomson2019-08-111-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When `GIT_BLOB_FILTER_ATTTRIBUTES_FROM_HEAD` is passed to `git_blob_filter`, read attributes from `gitattributes` files that are checked in to the repository at the HEAD revision. This passes the flag `GIT_FILTER_ATTRIBUTES_FROM_HEAD` to the filter functions.
| * | | filter: optionally read attributes from repositoryEdward Thomson2019-08-111-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When `GIT_FILTER_ATTRIBUTES_FROM_HEAD` is specified, configure the filter to read filter attributes from `gitattributes` files that are checked in to the repository at the HEAD revision. This passes the flag `GIT_ATTR_CHECK_INCLUDE_HEAD` to the attribute reading functions.
| * | | attr: optionally read attributes from repositoryEdward Thomson2019-08-113-7/+56
| | | | | | | | | | | | | | | | | | | | When `GIT_ATTR_CHECK_INCLUDE_HEAD` is specified, read `gitattribute` files that are checked into the repository at the HEAD revision.
| * | | blob: allow blob filtering to ignore system gitattributesEdward Thomson2019-08-111-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Introduce `GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES`, which tells `git_blob_filter` to ignore the system-wide attributes file, usually `/etc/gitattributes`. This simply passes the appropriate flag to the attribute loading code.
| * | | filter: add GIT_FILTER_NO_SYSTEM_ATTRIBUTES optionEdward Thomson2019-08-111-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | Allow system-wide attributes (the ones specified in `/etc/gitattributes`) to be ignored if the flag `GIT_FILTER_NO_SYSTEM_ATTRIBUTES` is specified.
| * | | blob: deprecate `git_blob_filtered_content`Edward Thomson2019-08-111-16/+16
| | | | | | | | | | | | | | | | Users should now use `git_blob_filter`.
| * | | blob: introduce git_blob_filterEdward Thomson2019-08-111-4/+29
| | | | | | | | | | | | | | | | | | | | Provide a function to filter blobs that allows for more functionality than the existing `git_blob_filtered_content` function.
* | | | Merge pull request #5196 from pks-t/pks/config-include-onbranchEdward Thomson2019-08-271-1/+53
|\ \ \ \ | | | | | | | | | | config: implement "onbranch" conditional