Commit Graph

10103 Commits

Author SHA1 Message Date
Patrick Steinhardt
ce6f61daf0 attrcache: remove useless do_init indirection
Remove useless indirection from `git_attr_cache__init` to
`git_attr_cache__do_init`. The difference is that the
`git_attr_cache__init` macro first checks if the cache is already
initialized and, if so, not call `git_attr_cache__do_init`. But
actually, `git_attr_cache__do_init` already does the same thing and
returns immediately if the cache is already initialized.

Remove the indirection.
2017-02-21 16:17:36 +01:00
Patrick Steinhardt
c11510103d attrcache: replace existing file entry with git__swap
When doing an upsert of a file, we used to use `git__compare_and_swap`,
comparing the entry's file which is to be replaced with itself. This can
be more easily formulated by using `git__swap`, which unconditionally
replaces the value.
2017-02-21 16:17:36 +01:00
Patrick Steinhardt
b8ab782a6d attrcache: do not lock/unlock the mutex directly
Improve encapsulation by not referencing the attrcache mutex directly
but instead using the `attr_cache_lock` and `attr_cache_unlock`
functions.
2017-02-21 16:17:31 +01:00
Edward Thomson
b13f0da153 Merge pull request #4130 from libgit2/ethomson/clar_messages
Improve clar messages
2017-02-17 16:32:14 +00:00
Edward Thomson
c52480fde5 cl_git_exec -> cl_git_expect 2017-02-17 13:01:49 +00:00
Edward Thomson
a1dcc83030 tests: provide better pass/failure error messages
Provide more detailed messages when conditions pass or fail
unexpectedly.  In particular, this provides the error messages when a
test fails with a different error code than was expected.
2017-02-17 12:58:57 +00:00
Edward Thomson
cc17264270 p_snprintf: no need for arguments to a format
`snprintf` requires a _format_ but does not require _arguments_ to the
format.  eg: `snprintf(buf, 42, "hi")` is perfectly legal.  Expand the
macro to match.

Without this, `p_sprintf(buf, 42, "hi")` errors with:

```
error: expected expression
                p_snprintf(msg, 42, "hi");
                ^
src/unix/posix.h:53:34: note: expanded from macro 'p_snprintf'
                                 ^
/usr/include/secure/_stdio.h:57:73: note: expanded from macro 'snprintf'
  __builtin___snprintf_chk (str, len, 0, __darwin_obsz(str),
__VA_ARGS__)
```
2017-02-17 12:10:19 +00:00
Patrick Steinhardt
d0c72a92ef Merge pull request #4092 from pks-t/pks/khash-cleanups
khash cleanups
2017-02-17 12:41:05 +01:00
Patrick Steinhardt
8f1ff26bd3 idxmap: remove GIT__USE_IDXMAP 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
cee9ca6609 idxmap: convert to use functions instead of macros 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
8f5fe903d6 offmap: remove GIT__USE_OFFMAP macro 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
cf6124d68b offmap: convert to use functions instead of macros 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
0d71690549 oidmap: remove GIT__USE_OIDMAP macro 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
659f5d07d5 oidmap: convert macros to functions 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
13c3bc9adf strmap: remove GIT__USE_STRMAP macro 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
a13cfd2af2 strmap: convert macros to functions 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
f14f75d4a1 khash: avoid using kh_resize directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
73028af85c khash: avoid using macro magic to get return address 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
85d2748c6f khash: avoid using kh_key/kh_val as lvalue 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
f31cb45ad2 khash: avoid using kh_put directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
a8cd560b10 khash: avoid using kh_del directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
71a54317ef khash: avoid using kh_key directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
cb18386f72 khash: avoid using kh_val/kh_value directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
76e671a653 khash: avoid using kh_exist directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
c37b069b9f khash: avoid using kh_clear directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
a853c52723 khash: avoid using kh_get directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
64e46dc3b5 khash: avoid using kh_end directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
036daa59e9 khash: use git_map_exists where applicable 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
9694d9ba79 khash: avoid using kh_foreach/kh_foreach_value directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
63e914cbf4 khash: avoid using kh_size directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
a1b23df58c offmap: remove unused macro git_offmap_insert2 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
bff9b7a5a3 strmap: remove unused macro git_strmap_insert2 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
021f4943a9 Merge pull request #4124 from pks-t/pks/worktree-refs
refdb: catch additional per-worktree refs
2017-02-17 11:14:53 +01:00
Edward Thomson
95248be72f Merge pull request #4127 from Uncommon/comment
Minor comment fix
2017-02-16 22:30:33 +00:00
David Catmull
19874e2934 Minor comment fix 2017-02-16 08:40:49 -07:00
Patrick Steinhardt
6da6b425d8 refdb: catch additional per-worktree refs
The upstream git.git project currently identifies all references inside
of `refs/bisect/` as well as `HEAD` as per-worktree references. This is
already incorrect and is currently being fixed by an in-flight topic
[1]. The new behavior will be to match all pseudo-references outside of
the `refs/` hierarchy as well as `refs/bisect/`.

Our current behavior is to mark a selection of pseudo-references as
per-worktree, only. This matches more pseudo-references than current
git, but forgets about `refs/bisect/`. Adjust behavior to match the
in-flight topic, that is classify the following references as
per-worktree:

- everything outside of `refs/`
- everything inside of `refs/bisect/`

[1]: <20170213152011.12050-1-pclouds@gmail.com>
2017-02-15 09:06:56 +01:00
Edward Thomson
a59545de5e Merge pull request #4122 from pks-t/pks/signature-dbl-free
Signature cleanups
2017-02-13 14:38:12 +00:00
Patrick Steinhardt
ade0d9c658 commit: avoid possible use-after-free
When extracting a commit's signature, we first free the object and only
afterwards put its signature contents into the result buffer. This works
in most cases - the free'd object will normally be cached anyway, so we
only end up decrementing its reference count without actually freeing
its contents. But in some more exotic setups, where caching is disabled,
this can definitly be a problem, as we might be the only instance
currently holding a reference to this object.

Fix this issue by first extracting the contents and freeing the object
afterwards only.
2017-02-13 13:50:52 +01:00
Patrick Steinhardt
dc851d9eae commit: clear user-provided buffers
The functions `git_commit_header_field` and
`git_commit_extract_signature` both receive buffers used to hand back
the results to the user. While these functions called `git_buf_sanitize`
on these buffers, this is not the right thing to do, as it will simply
initialize or zero-terminate passed buffers. As we want to overwrite
contents, we instead have to call `git_buf_clear` to completely reset
them.
2017-02-13 13:50:52 +01:00
Edward Thomson
c576d4fff2 Merge pull request #4115 from gsaralms/users/gsaral/optionalOfsDelta
Changes to provide option to turn off/on ofs_delta
2017-02-13 12:46:00 +00:00
Patrick Steinhardt
cdb2c2a0bf buffer: clarify how git_buf_sanitize handles non-NULL input
When `git_buf_sanitize` gets called, it converts a buffer with NULL
content to be correctly initialized. This is done by pointing it to
`git_buf__initbuf`. While the method's documentation states this
clearly, it may also lead to the conclusion that it will do the same to
buffers which do _not_ have NULL contents.

Clarify behavior when passing a buffer with non-NULL contents, where
`git_buf_sanitize` will ensure that the contents are `\0`-terminated.
2017-02-13 13:31:37 +01:00
Edward Thomson
4f9f8e0dc9 Merge pull request #3436 from pks-t/libgit2-worktree
Worktree implementation
2017-02-13 11:10:49 +00:00
Patrick Steinhardt
1ba242c9ab worktree: extract git_worktree_is_prunable 2017-02-13 11:13:08 +01:00
Patrick Steinhardt
3f3a4ce7bc worktree: test opening worktree via gitlink, gitdir and worktree 2017-02-13 11:12:01 +01:00
Patrick Steinhardt
6f6dd17cb2 worktree: test creating and opening submodule worktrees 2017-02-13 11:10:58 +01:00
Patrick Steinhardt
43275f512e Merge pull request #4121 from pks-t/pks/fix-test-index-permissions
tests: fix permissions on testrepo.git index file
2017-02-13 11:10:18 +01:00
Patrick Steinhardt
1fd6e035dd worktree: test opening discovered submodule worktrees 2017-02-13 11:09:57 +01:00
Patrick Steinhardt
39abd3adaa worktree: compute workdir for worktrees opened via their gitdir
When opening a worktree via the gitdir of its parent repository
we fail to correctly set up the worktree's working directory. The
problem here is two-fold: we first fail to see that the gitdir
actually is a gitdir of a working tree and then subsequently
fail to determine the working tree location from the gitdir.

The first problem of not noticing a gitdir belongs to a worktree
can be solved by checking for the existence of a `gitdir` file in
the gitdir. This file points back to the gitlink file located in
the working tree's working directory. As this file only exists
for worktrees, it should be sufficient indication of the gitdir
belonging to a worktree.

The second problem, that is determining the location of the
worktree's working directory, can then be solved by reading the
`gitdir` file in the working directory's gitdir. When we now
resolve relative paths and strip the final `.git` component, we
have the actual worktree's working directory location.
2017-02-13 11:08:57 +01:00
Patrick Steinhardt
84f56cb05a repository: rename path_repository and path_gitlink
The `path_repository` variable is actually confusing to think
about, as it is not always clear what the repository actually is.
It may either be the path to the folder containing worktree and
.git directory, the path to .git itself, a worktree or something
entirely different. Actually, the intent of the variable is to
hold the path to the gitdir, which is either the .git directory
or the bare repository.

Rename the variable to `gitdir` to avoid confusion. While at it,
also rename `path_gitlink` to `gitlink` to improve consistency.
2017-02-13 11:07:52 +01:00
Patrick Steinhardt
384518d09d repository: restrict checking out checked out branches
If a branch is already checked out in a working tree we are not
allowed to check out that branch in another repository. Introduce
this restriction when setting a repository's HEAD.
2017-02-13 11:06:52 +01:00