Commit Graph

10685 Commits

Author SHA1 Message Date
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
Patrick Steinhardt
a25df009ef Merge pull request #4180 from pks-t/pks/pass-blame-fix
Fix memory leaks
2017-03-28 08:38:24 +02:00
Patrick Steinhardt
fbdf2a79d5 worktree: unconditionally free the worktree's name 2017-03-24 09:26:31 +01:00
Patrick Steinhardt
4004d68f99 blame_git: remove spuriuous goto
The recent addition of an error code to `pass_whole_blame` in ff8d2eb15
(blame_git: check return value of object lookup, 2017-03-20) introduced
a spurious goto. Remove it.
2017-03-24 08:41:10 +01:00
Patrick Steinhardt
1d39a60319 Merge pull request #4175 from libgit2/ethomson/dont_trunc_and_excl
git_futils: don't O_EXCL and O_TRUNC
2017-03-24 08:26:33 +01:00
Carlos Martín Nieto
fa86a095cb Merge pull request #4178 from libgit2/ethomson/enfasten_sha1
sha1dc: perf improvements from upstream
2017-03-23 20:45:28 +01:00
Edward Thomson
d672963535 sha1dc: SHA1DCUpdate now takes a size_t 2017-03-23 17:25:11 +00:00
Edward Thomson
e65b5e960d config: expand paths with git_sysdir_expand... 2017-03-23 12:12:39 +00:00
Edward Thomson
ed812ee725 config::include: sanitize homedir
Sanitize the home directory to ensure that we do not accidentally locate
a file called `~/.nonexistentfile`.
2017-03-23 12:12:39 +00:00
Edward Thomson
29aef94830 config, attrcache: don't fallback to dirs literally named ~
The config and attrcache file reading code would attempt to load a file
in a home directory by expanding the `~` and looking for the file, using
`git_sysdir_find_global_file`.  If the file was not found, the error
handling would look for the literal path, eg `~/filename.txt`.

Use the new `git_config_expand_global_file` instead, which allows us to
get the path to the file separately, when the path is prefixed with
`~/`, and fail with a not found error without falling back to looking
for the literal path.
2017-03-23 12:12:39 +00:00
Edward Thomson
5135ddaac6 Introduce git_sysdir_expand_global_file
Provide a mechanism for callers to expand the full path of a file in the
global configuration directory (that is to say, the home directory) even
if the file doesn't necessarily exist.  This lets callers use their own
logic for building paths separate from handling file existence.
2017-03-23 12:12:39 +00:00
Sim Domingo
301dc26a5a fix error when including a missing config file relative to the home directory 2017-03-23 12:12:38 +00:00
Sim Domingo
047fe29c4f add failing test to include a missing config file relative to home dir 2017-03-23 12:12:38 +00:00
Edward Thomson
6987368565 Merge branch 'pr/3957' 2017-03-23 09:49:09 +00:00
Edward Thomson
b53d834fca merge: indentation fixup 2017-03-23 09:46:22 +00:00
Edward Thomson
6ad091dceb Merge pull request #4176 from libgit2/ethomson/3872
inet_pton: don't assume addr families don't exist
2017-03-23 09:33:09 +00:00
Edward Thomson
c9efa995e4 sha1dc: perf improvements from upstream
Update SHA-1 collision detection code (cr-marcstevens/sha1collisiondetection)
to master to include performance improvements.
2017-03-23 09:16:24 +00:00
Edward Thomson
f623cf894a Merge pull request #4163 from pks-t/pks/submodules-with-worktrees
Worktree fixes
2017-03-22 20:32:55 +00:00
Edward Thomson
6fd6c67824 Merge pull request #4030 from libgit2/ethomson/fsync
fsync all the things
2017-03-22 20:29:22 +00:00
Edward Thomson
7e53e8ce45 Merge pull request #4167 from pks-t/pks/ci-fixes
Coverity fixes
2017-03-22 20:26:52 +00:00
Edward Thomson
69d0b460f0 Merge pull request #4172 from rcjsuen/patch-1
Fix the documentation for git_cred_acquire_cb
2017-03-22 20:22:45 +00:00
Edward Thomson
983979fa0d inet_pton: don't assume addr families don't exist
Address family 5 might exist on some crazy system like Haiku.
Use `INT_MAX-1` as an unsupported address family.
2017-03-22 19:52:38 +00:00
Edward Thomson
4a26915d34 git_futils: don't O_EXCL and O_TRUNC
`O_EXCL` and `O_TRUNC` are mutually exclusive flags to open(2); you can't
truncate a file if you're asserting that it can't exist in the first place.
Drop `O_TRUNC`.
2017-03-22 19:48:50 +00:00
Remy Suen
84b4e5733d Use proper documentation tags
git_cred_acquire_cb isn't using the standard @param and @return tags.
This is causing the generated documentation to not be formatted
properly.
2017-03-22 06:08:24 +09:00
Edward Thomson
ea3bb5c0bb git_repository_set_head: use tag name in reflog
When `git_repository_set_head` is provided a tag reference, update the
reflog with the tag name, like we do with a branch.  This helps
consumers match the semantics of `git checkout tag`.
2017-03-21 18:12:02 +00:00