summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* | | Merge pull request #4982 from pks-t/pks/worktree-add-bare-headEdward Thomson2019-02-145-31/+59
|\ \ \ | | | | | | | | Enable creation of worktree from bare repo's default branch
| * | | branch: fix `branch_is_checked_out` with bare reposPatrick Steinhardt2019-02-141-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In a bare repository, HEAD usually points to the branch that is considered the "default" branch. As the current implementation for `git_branch_is_checked_out` only does a comparison of HEAD with the branch that is to be checked, it will say that the branch pointed to by HEAD in such a bare repo is checked out. Fix this by skipping the main repo's HEAD when it is bare.
| * | | branches: introduce flag to skip enumeration of certain HEADsPatrick Steinhardt2019-02-144-17/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Right now, the function `git_repository_foreach_head` will always iterate over all HEADs of the main repository and its worktrees. In some cases, it might be required to skip either of those, though. Add a flag in preparation for the following commit that enables this behaviour.
| * | | branches: do not assert that the given ref is a branchPatrick Steinhardt2019-02-141-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Libraries should use assert(3P) only very scarcely. First, we usually shouldn't cause the caller of our library to abort in case where the assert fails. Second, if code is compiled with -DNDEBUG, then the assert will not be included at all. In our `git_branch_is_checked_out` function, we have an assert that verifies that the given reference parameter is non-NULL and in fact a branch. While the first check is fine, the second is not. E.g. when compiled with -DNDEBUG, we'd proceed and treat the given reference as a branch in all cases. Fix the issue by instead treating a non-branch reference as not being checked out. This is the obvious solution, as references other than branches cannot be directly checked out.
| * | | worktree: error out early if given ref is not validPatrick Steinhardt2019-02-141-12/+14
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When adding a new worktree, we only verify that an optionally given reference is valid half-way through the function. At this point, some data structures have already been created on-disk. If we bail out due to an invalid reference, these will be left behind and need to be manually cleaned up by the user. Improve the situation by moving the reference checks to the function's preamble. Like this, we error out as early as possible and will not leave behind any files.
* | | Merge pull request #4965 from hackworks/eliminate-check-for-keep-fileEdward Thomson2019-02-142-3/+13
|\ \ \ | | | | | | | | Allow bypassing check for '.keep' file
| * | | Allow bypassing check '.keep' files using libgit2 option ↵Dhruva Krishnamurthy2019-02-022-3/+13
| |/ / | | | | | | | | | 'GIT_OPT_IGNORE_PACK_KEEP_FILE_CHECK'
* | | deprecation: ensure we GIT_EXTERN deprecated funcsEdward Thomson2019-02-141-0/+6
|/ / | | | | | | | | | | | | | | | | | | Although the error functions were deprecated, we did not properly mark them as deprecated. We need to include the `deprecated.h` file in order to ensure that the functions get their export attributes. Similarly, do not define `GIT_DEPRECATE_HARD` within the library, or those functions will also not get their export attributes. Define that only on the tests and examples.
* | mbedtls: fix potential size overflow when reading or writing dataethomson/stream-truncated-writesPatrick Steinhardt2019-01-311-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The mbedtls library uses a callback mechanism to allow downstream users to plug in their own receive and send functions. We implement `bio_read` and `bio_write` functions, which simply wrap the `git_stream_read` and `git_stream_write` functions, respectively. The problem arises due to the return value of the callback functions: mbedtls expects us to return an `int` containing the actual number of bytes that were read or written. But this is in fact completely misdesigned, as callers are allowed to pass in a buffer with length `SIZE_MAX`. We thus may be unable to represent the number of bytes written via the return value. Fix this by only ever reading or writing at most `INT_MAX` bytes.
* | mbedtls: make global variables staticPatrick Steinhardt2019-01-311-4/+2
| | | | | | | | | | | | The mbedtls stream implementation makes use of some global variables which are not marked as `static`, even though they're only used in this compilation unit. Fix this and remove a duplicate declaration.
* | openssl: fix potential size overflow when writing dataPatrick Steinhardt2019-01-311-2/+1
| | | | | | | | | | | | | | Our `openssl_write` function calls `SSL_write` by passing in both `data` and `len` arguments directly. Thing is, our `len` parameter is of type `size_t` and theirs is of type `int`. We thus need to clamp our length to be at most `INT_MAX`.
* | streams: handle short writes only in generic streamPatrick Steinhardt2019-01-312-20/+11
| | | | | | | | | | | | | | | | Now that the function `git_stream__write_full` exists and callers of `git_stream_write` have been adjusted, we can lift logic for short writes out of the stream implementations. Instead, this is now handled either by `git_stream__write_full` or by callers of `git_stream_write` directly.
* | streams: fix callers potentially only writing partial dataPatrick Steinhardt2019-01-314-25/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Similar to the write(3) function, implementations of `git_stream_write` do not guarantee that all bytes are written. Instead, they return the number of bytes that actually have been written, which may be smaller than the total number of bytes. Furthermore, due to an interface design issue, we cannot ever write more than `SSIZE_MAX` bytes at once, as otherwise we cannot represent the number of bytes written to the caller. Unfortunately, no caller of `git_stream_write` ever checks the return value, except to verify that no error occurred. Due to this, they are susceptible to the case where only partial data has been written. Fix this by introducing a new function `git_stream__write_full`. In contrast to `git_stream_write`, it will always return either success or failure, without returning the number of bytes written. Thus, it is able to write all `SIZE_MAX` bytes and loop around `git_stream_write` until all data has been written. Adjust all callers except the BIO callbacks in our mbedtls and OpenSSL streams, which already do the right thing and require the amount of bytes written.
* | streams: make file-local functions staticPatrick Steinhardt2019-01-313-19/+17
|/ | | | | | The callback functions that implement the `git_stream` structure are only used inside of their respective implementation files, but they are not marked as `static`. Fix this.
* filter: return an intEdward Thomson2019-01-251-1/+1
| | | | | Validate that the return value of the read is not less than INT_MAX, then cast.
* diff_generate: validate oid file sizeEdward Thomson2019-01-251-2/+2
| | | | Index entries are 32 bit unsigned ints, not `size_t`s.
* describe: don't mix and match abbreviated size typesEdward Thomson2019-01-251-2/+2
| | | | | The git_describe_format_options.abbreviated_size type is an unsigned int. There's no need for it to be anything else; keep it what it is.
* delta: validate sizes and cast safelyEdward Thomson2019-01-251-4/+11
| | | | | Quiet down a warning from MSVC about how we're potentially losing data. Validate that our data will fit into the type provided then cast.
* git transport: only write INT_MAX bytesEdward Thomson2019-01-251-5/+9
| | | | | The transport code returns an `int` with the number of bytes written; thus only attempt to write at most `INT_MAX`.
* windows: add SSIZE_MAXEdward Thomson2019-01-251-0/+6
| | | | | | Windows doesn't include ssize_t or its _MAX value by default. We are already declaring ssize_t as SSIZE_T, which is __int64_t on Win64 and long otherwise. Include its _MAX value as a correspondence to its type.
* streams: don't write more than SSIZE_MAXEdward Thomson2019-01-254-13/+13
| | | | | | | | | Our streams implementation takes a `size_t` that indicates the length of the data buffer to be written, and returns an `ssize_t` that indicates the length that _was_ written. Clearly no such implementation can write more than `SSIZE_MAX` bytes. Ensure that each TLS stream implementation does not try to write more than `SSIZE_MAX` bytes (or smaller; if the given implementation takes a smaller size).
* buffer: explicitly castEdward Thomson2019-01-251-1/+1
| | | | | Quiet down a warning from MSVC about how we're potentially losing data. This is safe since we've explicitly tested it.
* blame: make hunk_cmp handle unsigned differencesEdward Thomson2019-01-251-1/+6
|
* apply: make update_hunk accept a size_tEdward Thomson2019-01-251-1/+1
|
* iterator: cast filesystem iterator entry values explicitlyEdward Thomson2019-01-251-3/+10
| | | | | | | | | | | | The filesystem iterator takes `stat` data from disk and puts them into index entries, which use 32 bit ints for time (the seconds portion) and filesize. However, on most systems these are not 32 bit, thus will typically invoke a warning. Most users ignore these fields entirely. Diff and checkout code do use the values, however only for the cache to determine if they should check file modification. Thus, this is not a critical error (and will cause a hash recomputation at worst).
* blob: validate that blob sizes fit in a size_tEdward Thomson2019-01-258-20/+52
| | | | | | Our blob size is a `git_off_t`, which is a signed 64 bit int. This may be erroneously negative or larger than `SIZE_MAX`. Ensure that the blob size fits into a `size_t` before casting.
* tree: cast filename length in git_tree__parse_rawEdward Thomson2019-01-251-2/+2
| | | | | Quiet down a warning from MSVC about how we're potentially losing data. Ensure that we're within a uint16_t before we do.
* odb_loose: explicitly cast to size_tEdward Thomson2019-01-251-1/+1
| | | | | | Quiet down a warning from MSVC about how we're potentially losing data. This is safe since we've explicitly tested that it's positive and less than SIZE_MAX.
* patch: explicitly cast down in parse_header_percentEdward Thomson2019-01-251-1/+1
| | | | | | Quiet down a warning from MSVC about how we're potentially losing data. This is safe since we've explicitly tested that it's within the range of 0-100.
* index: explicitly cast down to a size_tEdward Thomson2019-01-251-1/+1
| | | | | | Quiet down a warning from MSVC about how we're potentially losing data. This cast is safe since we've explicitly tested that `strip_len` <= `last_len`.
* diff: explicitly cast in flush_hunkEdward Thomson2019-01-251-1/+1
| | | | Quiet down a warning from MSVC about how we're potentially losing data.
* Merge pull request #4858 from tiennou/fix/index-ext-readEdward Thomson2019-01-251-14/+15
|\ | | | | index: preserve extension parsing errors
| * index: preserve extension parsing errorsEtienne Samson2019-01-241-14/+15
| | | | | | | | | | | | | | Previously, we would clobber any extension-specific error message with an "extension is truncated" message. This makes `read_extension` correctly preserve those errors, takes responsibility for truncation errors, and adds a new message with the actual extension signature for unsupported mandatory extensions.
* | deprecation: don't use deprecated stream cbEdward Thomson2019-01-251-1/+3
| | | | | | | | | | | | Avoid the deprecated `git_stream_cb` typedef since we want to compile the library without deprecated functions or types. Instead, we can unroll the alias to its actual type.
* | Don't use deprecated constantsSven Strickroth2019-01-242-3/+3
| | | | | | | | | | | | Follow up for PR #4917. Signed-off-by: Sven Strickroth <email@cs-ware.de>
* | Fix VS warning C4098: 'giterr_set_str' : void function returning a valueSven Strickroth2019-01-241-1/+1
|/ | | | Signed-off-by: Sven Strickroth <email@cs-ware.de>
* git_error: use new names in internal APIs and usageEdward Thomson2019-01-22141-1760/+1760
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* git_error: deprecate error valuesEdward Thomson2019-01-221-1/+1
| | | | | Replace the `GITERR` values with a `const int` to deprecate error values.
* git_error: use full class name in public error APIEdward Thomson2019-01-221-4/+26
| | | | | | | | | Move to the `git_error` name in error-related functions, deprecating the `giterr` functions. This means, for example, that `giterr_last` is now `git_error_last`. The old names are retained for compatibility. This only updates the public API; internal API and function usage remains unchanged.
* Fix odb foreach to also close on positive error codeMarijan Šuflaj2019-01-202-2/+2
| | | | | | | | 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.
* repository: free memory in symlink detection functionethomson/memleaksEdward Thomson2019-01-201-5/+8
|
* Merge pull request #4945 from libgit2/ethomson/fix-intrinsicsEdward Thomson2019-01-201-22/+32
|\ | | | | Add/multiply with overflow tweaks
| * add with overflow: correct documentationethomson/fix-intrinsicsEdward Thomson2019-01-201-2/+2
| | | | | | | | | | Correct the documentation on the fallback add/multiply with overflow functions.
| * add with overflow: use SizeTAdd on WindowsEdward Thomson2019-01-201-0/+10
| | | | | | | | | | Windows provides <intsafe.h> which provides "performant" add and multiply with overflow operations. Use them when possible.
| * Remove unused git__add_uint64_overflowEdward Thomson2019-01-201-12/+0
| |
| * add with overflow intrinsics: simplify testsEdward Thomson2019-01-201-26/+18
| | | | | | | | | | | | Use the smallest unsigned type that is equivalent to `size_t` to simplify the conditionals. Error if we're on a system that we believe offers builtins but we cannot determine which one to use.
| * Let GCC use the add/mul overflow intrinsicslhchavez2019-01-091-10/+30
| | | | | | | | | | | | | | | | This change tweaks the macros for git__{add,multiply}_sizet_overflow so that GCC can use them. It also stops using the uadd,umul versions since the add,mul can handle way more cases.
* | Merge pull request #4939 from libgit2/ethomson/git_refEdward Thomson2019-01-1910-80/+81
|\ \ | | | | | | Move `git_ref_t` to `git_reference_t`
| * | references: use new names in internal usageethomson/git_refEdward Thomson2019-01-1710-80/+81
| | | | | | | | | | | | Update internal usage to use the `git_reference` names for constants.
* | | Merge pull request #4940 from libgit2/ethomson/git_objEdward Thomson2019-01-198-17/+17
|\ \ \ | | | | | | | | More `git_obj` to `git_object` updates