Commit Graph

10496 Commits

Author SHA1 Message Date
Patrick Steinhardt
f4d1592c2f global: fix typo in git_libgit2_init description 2017-04-21 07:48:30 +00:00
Carlos Martín Nieto
8d89e40961 Merge pull request #4192 from libgit2/ethomson/win32_posix
Refactor some of the win32 POSIX emulation
2017-04-17 17:19:03 +02:00
Edward Thomson
86536c7e45 win32: remediation not cleanup
The `remediation` function is run in the retry loop in order to attempt
to fix any problems that the prior run encountered.  There is nothing
"cleaned up".  Clarify the name.
2017-04-17 15:40:03 +01:00
Carlos Martín Nieto
5c76096046 transport: provide a getter for the proxy options
As with the callbacks, third-party implementations of smart subtransports cannot
reach into the opaque struct and thus cannot know what options the user set.

Add a getter for these options to copy the proxy options into something external
implementors can use.
2017-04-17 13:03:03 +02:00
Edward Thomson
f9d3b0d05f Merge pull request #4201 from pks-t/pks/fileops-fd-leak
fileops: fix leaking fd in `mmap_ro_file`
2017-04-12 09:21:26 +01:00
Patrick Steinhardt
38b6e70027 fileops: fix leaking fd in mmap_ro_file
When the `git_futils_mmap_ro_file` function encounters an error after
the file has been opened, it will do a simple returns. Instead, we
should close the opened file descriptor to avoid a leak. This commit
fixes the issue.
2017-04-12 08:09:08 +02:00
Edward Thomson
d476d024d0 Merge pull request #4196 from pks-t/pks/filter-segfault
filter: only close filter if it's been initialized correctly
2017-04-11 19:18:05 +01:00
Edward Thomson
a5781e2a18 Merge pull request #4195 from pks-t/pks/openssl-1.1
Fix building against OpenSSL v1.1
2017-04-11 19:17:11 +01:00
Edward Thomson
1262963add Merge pull request #4198 from pks-t/pks/git-compat
README: document our relation to changes in upstream
2017-04-11 19:10:28 +01:00
Patrick Steinhardt
19a04f67cd README: document our relation to changes in upstream
libgit2 is a mere consumer of changes which are trickling down from the
upstream git.git project. This commit documents the ramifications caused
by this relation.
2017-04-11 07:22:02 +02:00
Patrick Steinhardt
78b8f0392c tests: fix indentation in checkout::head::with_index_only_tree 2017-04-10 12:44:19 +02:00
Patrick Steinhardt
88520151fd openssl_stream: use new initialization function on OpenSSL version >=1.1
Previous to OpenSSL version 1.1, the user had to initialize at least the error
strings as well as the SSL algorithms by himself. OpenSSL version 1.1 instead
provides a new function `OPENSSL_init_ssl`, which handles initialization of all
subsystems. As the new API call will by default load error strings and
initialize the SSL algorithms, we can safely replace these calls when compiling
against version 1.1 or later.

This fixes a compiler error when compiling against OpenSSL version 1.1 which has
been built without stubs for deprecated syntax.
2017-04-10 11:29:07 +02:00
Patrick Steinhardt
29081c2fd4 openssl_stream: remove locking initialization on OpenSSL version >=1.1
Up to version 1.0, OpenSSL required us to provide a callback which implements
a locking mechanism. Due to problems in the API design though this mechanism was
inherently broken, especially regarding that the locking callback cannot report
errors in an obvious way. Due to this shortcoming, the locking initialization
has been completely removed in OpenSSL version 1.1. As the library has also been
refactored to not make any use of these callback functions, we can safely remove
all initialization of the locking subsystem if compiling against OpenSSL version
1.1 or higher.

This fixes a compilation error when compiling against OpenSSL version 1.1 which
has been built without stubs for deprecated syntax.
2017-04-10 11:29:07 +02:00
Patrick Steinhardt
cf07db2f1b filter: only close filter if it's been initialized correctly
In the function `git_filter_list_stream_data`, we initialize, write and
subesquently close the stream which should receive content processed by
the filter. While we skip writing to the stream if its initialization
failed, we still try to close it unconditionally -- even if the
initialization failed, where the stream might not be set at all, leading
us to segfault.

Semantics in this code is not really clear. The function handling the
same logic for files instead of data seems to do the right thing here in
only closing the stream when initialization succeeded. When stepping
back a bit, this is only reasonable: if a stream cannot be initialized,
the caller would not expect it to be closed again. So actually, both
callers of `stream_list_init` fail to do so. The data streaming function
will always close the stream and the file streaming function will not
close the stream if writing to it has failed.

The fix is thus two-fold:

- callers of `stream_list_init` now close the stream iff it has been
  initialized
- `stream_list_init` now closes the lastly initialized stream if
  the current stream in the chain failed to initialize

Add a test which segfaulted previous to these changes.
2017-04-07 16:34:47 +02:00
Edward Thomson
e572b63121 Merge pull request #4183 from pks-t/pks/coverity
Coverity
2017-04-07 09:03:56 +01:00
Edward Thomson
44998cdb9a Merge pull request #4193 from pks-t/pks/libdir
pkgconfig: fix handling of prefixes containing whitespaces
2017-04-07 09:02:54 +01:00
Patrick Steinhardt
22436f2945 pkgconfig: fix handling of prefixes containing whitespaces
Our libgit2.pc.in file is quoting the `libdir` variable in our declared
"Libs:" line. The intention is to handle whitespaces here, but pkgconfig
already does so by automatically escaping whitespace with backslashes.
The correct thing to do is to instead quote the prefix, as this is the
one which is being substituted by CMake upon installation. As both
libdir and includedir will be expanded to "${prefix}/lib" and
"${prefix}/include", respectively, pkgconfig will also correctly escape
whitespaces.

Note that this will actually break when a user manually wants to
override libdir and includedir with a path containing whitespace. But
actually, this cannot be helped, as always quoting these variables will
actuall break the common case of being prefixed with "${prefix}". So we
just bail out here and declare this as unsupported out of the box.
2017-04-05 14:46:23 +02:00
Patrick Steinhardt
2a485dabc0 refs: update worktree HEADs when renaming branches
Whenever we rename a branch, we update the repository's symbolic HEAD
reference if it currently points to the branch that is to be renamed.
But with the introduction of worktrees, we also have to iterate over all
HEADs of linked worktrees to adjust them. Do so.
2017-04-05 13:50:38 +02:00
Patrick Steinhardt
38fc5ab0a2 branch: use foreach_head to see if a branch is checked out
Previously, we have extracted the logic to find and iterate over all
HEADs of a repository. Use this function in `git_branch_is_checked_out`.
2017-04-05 13:50:38 +02:00
Patrick Steinhardt
74511aa204 repository: add function to iterate over all HEADs
While we already provide functions to get the current repository's HEAD,
it is quite involved to iterate over HEADs of both the repository and
all linked work trees. This commit implements a function
`git_repository_foreach_head`, which accepts a callback which is then
called for all HEAD files.
2017-04-05 13:50:38 +02:00
Patrick Steinhardt
3e84aa506d repository: get worktree HEAD via git_reference__read_head
The functions `git_repository_head_for_worktree` and
`git_repository_detached_head_for_worktree` both implement their
own logic to read the HEAD reference file. Use the new function
`git_reference__read_head` instead to unify the code paths.
2017-04-05 13:50:38 +02:00
Patrick Steinhardt
987f565917 repository: extract function to get path to a file in a work tree
The function `read_worktree_head` has the logic embedded to construct
the path to `HEAD` in the work tree's git directory, which is quite
useful for other callers. Extract the logic into its own function to
make it reusable by others.
2017-04-05 13:49:31 +02:00
Patrick Steinhardt
8242cc1a23 repository: set error message if trying to set HEAD to a checked out one
If trying to set the HEAD of a repository to another reference, we have
to check whether this reference is already checked out in another linked
work tree. If it is, we will refuse setting the HEAD and return an
error, but do not set a meaningful error message. Add one.
2017-04-05 13:49:31 +02:00
Patrick Steinhardt
5b65ac2578 refs: implement function to read references from file
Currently, we only provide functions to read references directly from a
repository's reference store via e.g. `git_reference_lookup`. But in
some cases, we may want to read files not connected to the current
repository, e.g. when looking up HEAD of connected work trees. This
commit implements `git_reference__read_head`, which will read out and
allocate a reference at an arbitrary path.
2017-04-05 13:49:31 +02:00
Patrick Steinhardt
602972560a tests: worktree::refs: convert spaces to tabs 2017-04-05 13:44:52 +02:00
Edward Thomson
48f09c6c47 win32: only set git_win32__retries where it exists 2017-04-05 11:59:03 +01:00
Edward Thomson
89d403cce2 win32: enable p_utimes for readonly files
Instead of failing to set the timestamp of a read-only file (like any
object file), set it writable temporarily to update the timestamp.
2017-04-05 11:04:29 +01:00
Patrick Steinhardt
9daba9f4b6 fileops: do not overwrite correct error message on mmap
When executing `git_futils_mmap_ro_file`, we first try to guess whether
the file is mmapable at all. Part of this check is whether the file is
too large to be mmaped, which can be true on systems with 32 bit
`size_t` types.

The check is performed by first getting the file size wtih
`git_futils_filesize` and then checking whether the returned size can be
represented as `size_t`, returning an error if so. While this test also
catches the case where the function returned an error (as `-1` is not
representable by `size_t`), we will set the misleading error message
"file too large to mmap". But in fact, a negative return value from
`git_futils_filesize` will be caused by the inability to fstat the file.

Fix the error message by handling negative return values separately and
not overwriting the error message in that case.
2017-04-04 11:58:46 +02:00
Patrick Steinhardt
756138e475 blame_git: check return value of git__calloc
We do not check the return value of `git__calloc`, which may return
`NULL` in out-of-memory situations. Fix the error by using
`GITERR_CHECK_ALLOC`.
2017-04-04 11:58:46 +02:00
Patrick Steinhardt
a76d75021c path: short-circuit git_path_apply_relative on error
Short-circuit the call to `git_path_resolve_relative` in case
`git_buf_joinpath` returns an error. While this does not fix any
immediate errors, the resulting code is easier to read and handles
potential new error conditions raised by `git_buf_joinpath`.
2017-04-04 11:58:46 +02:00
Patrick Steinhardt
cffd616a72 path: handle error returned by git_buf_joinpath
In the `_check_dir_contents` function, we first allocate memory for
joining the directory and subdirectory together and afterwards use
`git_buf_joinpath`. While this function in fact should not fail as
memory is already allocated, err on the safe side and check for returned
errors.
2017-04-04 11:58:46 +02:00
Patrick Steinhardt
4467aeac42 config_file: handle errors other than OOM while parsing section headers
The current code in `parse_section_header_ext` is only prepared to
properly handle out-of-memory conditions for the `git_buf` structure.
While very unlikely and probably caused by a programming error, it is
also possible to run into error conditions other than out-of-memory
previous to reaching the actual parsing loop. In these cases, we will
run into undefined behavior as the `rpos` variable is only initialized
after these triggerable errors, but we use it in the cleanup-routine.

Fix the issue by unifying the function's cleanup code with an
`end_error` section, which will not use the `rpos` variable.
2017-04-04 11:58:46 +02:00
Edward Thomson
7ece906598 win32: make posix emulation retries configurable
POSIX emulation retries should be configurable so that tests can disable
them.  In particular, maniacally threading tests may end up trying to
open locked files and need retries, which will slow continuous
integration tests significantly.
2017-04-03 23:14:24 +01:00
Edward Thomson
1069ad3c54 win32: do not inherit file descriptors 2017-04-03 23:13:38 +01:00
Sven Strickroth
d5e6ca1e4a Allow to configure default file share mode for opening files
This can prevent FILE_SHARED_VIOLATIONS when used in tools such as TortoiseGit TGitCache and FILE_SHARE_DELETE, because files can be opened w/o being locked any more.

Signed-off-by: Sven Strickroth <email@cs-ware.de>
2017-04-03 23:13:00 +01:00
Edward Thomson
dbacbf7848 Merge pull request #4188 from rcjsuen/patch-1
Correct non-existent file references in `odb.h`
2017-04-03 13:31:39 +01:00
Remy Suen
a12796dd72 Correct typos that reference a non-existing file
There are references to odb_backends.h when the file is actually named
odb_backend.h and in the sys folder.
2017-04-03 21:25:53 +09:00
Edward Thomson
e86d02f92d git_repository_set_head: use remote name in reflog
When `git_repository_set_head` is provided a remote reference, update
the reflog with the tag name, like we do with a branch.  This helps
consumers match the semantics of `git checkout remote`.
2017-04-03 00:10:47 +01:00
Sven Strickroth
92d5a6377a win32: deduplicate code: use p_open in p_creat
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2017-04-02 19:42:41 +01:00
Sven Strickroth
ef5cfcdb4f win32: use CreateFile in p_open
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2017-04-02 19:41:26 +01:00
Edward Thomson
fbc6910f6b win32: teach p_open about do_with_retries 2017-04-02 19:38:20 +01:00
Edward Thomson
a0f67e4a26 win32: teach p_unlink about do_with_retries 2017-04-02 19:38:19 +01:00
Edward Thomson
8a4e151301 win32: make p_rename use do_with_retries 2017-04-02 19:38:19 +01:00
Edward Thomson
cc8d9a29e7 win32: introduce do_with_retries macro
Provide a macro that will allow us to run a function with posix-like
return values multiple times in a retry loop, with an optional cleanup
function called between invocations.
2017-04-01 10:47:30 +01:00
Edward Thomson
dcaa90991f win32: map windows error codes to errno
Introduce mapping from windows error codes to errno values.  This
allows us to replace our calls to the Windows posix emulation functions
with calls to the Win32 APIs for more fine-grained control over the
emulation.

These mappings match the Windows CRT's mappings for its posix emulation
as they were described to me.
2017-04-01 10:47:29 +01:00
Edward Thomson
fcb322f5a0 Merge remote-tracking branch 'origin/pr/3790' into win32_posix 2017-03-31 23:39:33 +01:00
Edward Thomson
caf7a7a6b1 Merge pull request #4182 from pks-t/pks/treebuilder
git_treebuilder_write_with_buffer refactorings
2017-03-28 15:16:34 +01:00
Patrick Steinhardt
06abbb7f07 treebuilder: exit early if running OOM in write_with_buffer
While writing the tree inside of a buffer, we check whether the buffer
runs out of memory after each tree entry. While we set the error code as
soon as we detect the OOM situation, we happily proceed iterating over
the entries. This is not useful at all, as we will try to write into the
buffer repeatedly, which cannot work.

Fix this by exiting as soon as we are OOM.
2017-03-28 08:39:29 +02:00
Patrick Steinhardt
8d1e71f5a2 treebuilder: remove shadowing variable in write_with_buffer
The `git_tree_entry *entry` variable is defined twice inside of this
function. While this is not a problem currently, remove the shadowing
variable to avoid future confusion.
2017-03-28 08:39:29 +02:00
Patrick Steinhardt
4f9327faf9 treebuilder: fix memory leaks in write_with_buffer
While we detect errors in `git_treebuilder_write_with_buffer`, we just
exit directly instead of freeing allocated memory. Fix this by
remembering error codes and skipping forward to the function's cleanup
code.
2017-03-28 08:39:29 +02:00