Commit Graph

10496 Commits

Author SHA1 Message Date
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
Patrick Steinhardt
e7330016af diff_parse: check return value of git_diff_init_options 2017-03-21 15:48:16 +01:00
Patrick Steinhardt
723bdf4864 patch_parse: check if advancing over header newline succeeds
While parsing patch header lines, we iterate over each line and check if
the line has trailing garbage. What we do not check though is that the
line is actually a line ending with a trailing newline.

Fix this by checking the return code of `parse_advance_expected_str`.
2017-03-21 15:48:16 +01:00
Patrick Steinhardt
8d452448bb odb_pack: initialize git_rawobj structure
The `pack_entry_find_prefix` function receives a `git_rawobj` structure
as argument. While the function first initializes the structure to a
sensible state, Coverity is unable to correctly detect this, resulting
in a warning.

Fix this warning by initializing the object to all-zeroes before passing
it to the function.
2017-03-21 15:48:15 +01:00
Patrick Steinhardt
2cf48e1326 config_file: check if section header buffer runs out of memory
While parsing section headers, we use a buffer to store the actual
section name. We do not check though if the buffer runs out of memory at
any stage. Do so.
2017-03-21 15:48:15 +01:00
Patrick Steinhardt
ff8d2eb15f blame_git: check return value of object lookup
The function `pass_whole_blame` performs an object lookup but does not
check if the lookup actually succeeds. Convert the function to return an
error code and check for it in the calling function.
2017-03-21 15:48:15 +01:00
Edward Thomson
33ea4aae37 Merge pull request #4139 from richardipsum/readme-running-tests
README: Mention how to run tests
2017-03-21 13:41:24 +00:00
Patrick Steinhardt
c62179731a Merge pull request #4171 from rcjsuen/patch-1
Fix typo in remote.h API
2017-03-20 14:32:57 +01:00
Remy Suen
12b7394cdd Fix typo in remote.h API 2017-03-20 22:30:37 +09:00
Patrick Steinhardt
dd0b1e8cb6 openssl_stream: fix releasing OpenSSL locks
The OpenSSL library may require multiple locks to work correctly, where
it is the caller's responsibility to initialize and release the locks.
While we correctly initialized up to `n` locks, as determined by
`CRYPTO_num_locks`, we were repeatedly freeing the same mutex in our
shutdown procedure.

Fix the issue by freeing locks at the correct index.
2017-03-20 12:36:14 +01:00
Edward Thomson
1d50f95546 Merge pull request #4166 from pks-t/pks/map-free-fix
Remove `map_free` macros
2017-03-20 11:29:27 +00:00
Patrick Steinhardt
31059923bd Merge pull request #4169 from csware/absolute-symlink 2017-03-20 12:16:18 +01:00
Patrick Steinhardt
c10ce7c21a tests: filebuf: test writing to symlink with absolute paths 2017-03-20 12:14:07 +01:00
Sven Strickroth2
86a8cd9f6a filebuf: fix resolving absolute symlinks
The symlink destination is always concatenated to the original path. Fix
this by using `git_buf_sets` instead of `git_buf_puts`.
2017-03-20 12:14:05 +01:00
Patrick Steinhardt
e30a6ee378 Merge pull request #4160 from pks-t/pks/diff-fixes
Diff fixes
2017-03-20 11:06:23 +01:00
Patrick Steinhardt
44b3b9feca Merge pull request #4162 from pks-t/pks/merge-source-fixes
merge_driver: fix const-correctness for source getters
2017-03-20 11:05:03 +01:00
Patrick Steinhardt
94af9155cf map: remove *map_free macros
The `map_free` functions were not implemented as functions but instead
as macros which also set the map to NULL. While this is most certainly
sensible in most cases, we should prefer the more obvious behavior,
namingly leaving the map pointer intact.

Furthermore, this macro has been refactored incorrectly during the
map-refactorings: the two statements are not actually grouped together
by a `do { ... } while (0)` block, as it is required for macros to
match the behavior of functions more closely. This has led to at least
one subtle nesting error in `pack-objects.c`. The following code block

```
    if (pb->object_ix)
        git_oidmap_free(pb->object_ix);
```

would be expanded to

```
    if (pb->object_ix)
        git_oidmap__free(pb->object_ix); pb->object_ix = NULL;
```

which is not what one woudl expect. While it is not a bug here as it
would simply become a no-op, the wrong implementation could lead to bugs
in other occasions.

Fix this by simply removing the macro altogether and replacing it with
real function calls. This leaves the burden of setting the pointer to
NULL afterwards to the caller, but this is actually expected and behaves
like other `free` functions.
2017-03-20 09:01:18 +01:00
Patrick Steinhardt
77c8ee74ff checkout: fix double-free of checkout_data's mkdir_map
We currently call `git_strmap_free` on `checkout_data.mkdir_map` in the
`checkout_data_clear` function. The only thing protecting us from a
double-free is that the `git_strmap_free` function is in fact not a
function, but a macro that also sets the map to NULL.

Remove the second call to `git_strmap_free` and explicitly set the map
member to NULL.
2017-03-20 08:59:30 +01:00
Patrick Steinhardt
b0c9bc920f submodule: resolve URLs relative to main worktree
It is possible to specify submodule URLs relative to the repository
location. E.g. having a submodule with URL "../submodule" will look for
the submodule at "repo/../submodule".

With the introduction of worktrees, though, we cannot simply resolve the
URL relative to the repository location itself. If the repository for
which a URL is to be resolved is a working tree, we have to resolve the
URL relative to the parent's repository path. Otherwise, the URL would
change depending on where the working tree is located.

Fix this by special-casing when we have a working tree while getting the
URL base.
2017-03-17 09:27:56 +01:00
Patrick Steinhardt
097f0105b4 refdb: create references in commondir
References for a repository are usually created inside of its gitdir.
When using worktrees, though, these references are not to be created
inside the worktree gitdir, but instead inside the gitdir of its parent
repository, which is the commondir. Like this, branches will still be
available after the worktree itself has been deleted.

The filesystem refdb currently still creates new references inside of
the gitdir. Fix this and have it create references in commondir.
2017-03-17 09:27:56 +01:00
Patrick Steinhardt
8f154be3eb worktree: write resolved paths into link files
The three link files "worktree/.git", ".git/worktrees/<name>/commondir"
and ".git/worktrees/<name>/gitdir" should always contain absolute and
resolved paths. Adjust the logic creating new worktrees to first use
`git_path_prettify_dir` before writing out these files, so that paths
are resolved first.
2017-03-17 09:27:56 +01:00
Patrick Steinhardt
7cf7a40749 worktree: rename variable in git_worktree_add 2017-03-17 09:27:56 +01:00
Patrick Steinhardt
9dcc79bc6a worktree: use fully qualified reference name for created HEAD
When creating a new worktree, we have to set up the initial data
structures. Next to others, this also includes the HEAD pseudo-ref.
We currently set it to the worktree respectively branch name, which is
actually not fully qualified.

Use the fully qualified branch name instead.
2017-03-17 09:27:55 +01:00
Patrick Steinhardt
20a368e2d7 worktree: parent path should point to the working dir
The working tree's parent path should not point to the parent's gitdir,
but to the parent's working directory. Pointing to the gitdir would not
make any sense, as the parent's working directory is actually equal to
both repository's common directory.

Fix the issue.
2017-03-17 09:27:55 +01:00
Patrick Steinhardt
3017ba94a3 worktree: implement git_worktree_open_from_repository
While we already provide functionality to look up a worktree from a
repository, we cannot do so the other way round. That is given a
repository, we want to look up its worktree if it actually exists.
Getting the worktree of a repository is useful when we want to get
certain meta information like the parent's location, getting the locked
status, etc.
2017-03-17 09:26:13 +01:00
Patrick Steinhardt
dfc9870647 worktree: split off function opening working directory
Separate the logic of finding the worktree directory of a repository and
actually opening the working tree's directory. This is a preparatory
step for opening the worktree structure of a repository itself.
2017-03-17 08:56:18 +01:00
Patrick Steinhardt
3e9c5d8a05 worktree: have is_worktree_dir accept a string instead of buffer
This will be used in later commits, where it becomes cumbersome to
always pass in a buffer.
2017-03-17 08:56:18 +01:00