Commit Graph

9977 Commits

Author SHA1 Message Date
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
Patrick Steinhardt
143e539fd0 branch: restrict branch deletion for worktrees
Restrict the ability to delete branches that are checked out in
any linked repository.
2017-02-13 11:05:57 +01:00
Patrick Steinhardt
e3acd37b70 branch: implement git_branch_is_checked_out
Implement a new function that is able to determine if a branch is
checked out in any repository connected to the current
repository. In particular, this is required to check if for a
given repository and branch, there exists any working tree
connected to that repository that is referencing this branch.
2017-02-13 11:04:57 +01:00
Patrick Steinhardt
4321595dcb worktree: test basic merge functionality 2017-02-13 11:04:04 +01:00
Patrick Steinhardt
04fb12abb2 worktree: implement functions reading HEAD
Implement `git_repository_head_for_worktree` and
`git_repository_head_detached_for_worktree` for directly accessing a
worktree's HEAD without opening it as a `git_repository` first.
2017-02-13 11:03:01 +01:00
Patrick Steinhardt
f0cfc34105 worktree: implement git_worktree_prune
Implement the `git_worktree_prune` function. This function can be
used to delete working trees from a repository. According to the
flags passed to it, it can either delete the working tree's
gitdir only or both gitdir and the working directory.
2017-02-13 11:02:03 +01:00
Patrick Steinhardt
2a503485fa worktree: implement locking mechanisms
Working trees support locking by creating a file `locked` inside
the tree's gitdir with an optional reason inside. Support this
feature by adding functions to get and set the locking status.
2017-02-13 11:01:09 +01:00
Patrick Steinhardt
dea7488e93 worktree: implement git_worktree_add
Implement the `git_worktree_add` function which can be used to create
new working trees for a given repository.
2017-02-13 11:00:17 +01:00
Patrick Steinhardt
372dc9ff6a worktree: implement git_worktree_validate
Add a new function that checks wether a given `struct
git_worktree` is valid. The validation includes checking if the
gitdir, parent directory and common directory are present.
2017-02-13 10:59:16 +01:00
Patrick Steinhardt
8c8d726ef7 worktree: implement git_repository_open_from_worktree
Add function `git_repository_open_from_worktree`, which allows to open a
`git_worktree` as repository.
2017-02-13 10:59:04 +01:00
Patrick Steinhardt
a6bddf605d tests: fix permissions on testrepo.git index file 2017-02-13 10:34:08 +01:00
Patrick Steinhardt
d3bc09e816 worktree: introduce struct git_worktree
Introduce a new `struct git_worktree`, which holds information
about a possible working tree connected to a repository.
Introduce functions to allow opening working trees for a
repository.
2017-02-13 10:28:15 +01:00
Patrick Steinhardt
45f2b7a43f worktree: implement git_worktree_list
Add new module for working trees with the `git_worktree_list`
function. The function lists names for all working trees of a
certain repository.
2017-02-13 10:28:15 +01:00
Patrick Steinhardt
854b5c70e3 repository: expose repo_init_create_head
Expose the function `repo_init_create_head` as
`git_repository_create_head`.
2017-02-13 10:28:15 +01:00
Patrick Steinhardt
4292837d50 config: open configuration in commondir
A repository's configuartion file can always be found in the
GIT_COMMON_DIR, which has been newly introduced. For normal
repositories this does change nothing, but for working trees this
change allows to access the shared configuration file.
2017-02-13 10:28:15 +01:00
Patrick Steinhardt
e9403024fe refdb: look for reflog in commondir 2017-02-13 10:28:15 +01:00
Patrick Steinhardt
e0a6c28eb3 refdb: introduce commondir awareness
The refdb_fs_backend is not aware of the git commondir, which
stores common objects like the o bject database and packed/loose
refereensces when worktrees are used.

Make refdb_fs_backend aware of the common directory by
introducing a new commonpath variable that points to the actual
common path of the database and using it instead of the gitdir
for the mentioned objects.
2017-02-13 10:28:15 +01:00
Patrick Steinhardt
71dd086195 refdb: rename refdb_fs_backend's .path to .gitpath
The variable '.path' of the refdb_fs_backend struct becomes
confusing regarding the introduction of the git commondir. It
does not immediatly become obvious what it should point to.

Fix this problem by renaming the variable to `gitpath`,
clarifying that it acutally points to the `.git` directory of the
repository, in contrast to the commonpath directory, which points
to the directory containing shared objects like references and
the object store.
2017-02-13 10:28:15 +01:00
Patrick Steinhardt
79ab3ef69f repository: introduce is_worktree variable 2017-02-13 10:28:15 +01:00
Patrick Steinhardt
c5f3da9692 repository: use git_repository_item_path
The recent introduction of the commondir variable of a repository
requires callers to distinguish whether their files are part of
the dot-git directory or the common directory shared between
multpile worktrees. In order to take the burden from callers and
unify knowledge on which files reside where, the
`git_repository_item_path` function has been introduced which
encapsulate this knowledge.

Modify most existing callers of `git_repository_path` to use
`git_repository_item_path` instead, thus making them implicitly
aware of the common directory.
2017-02-13 10:28:15 +01:00
Patrick Steinhardt
cb3269c970 repository: add function to retrieve paths for repo items 2017-02-13 10:28:15 +01:00
Patrick Steinhardt
c09fd54e2e repository: introduce commondir variable
The commondir variable stores the path to the common directory.
The common directory is used to store objects and references
shared across multiple repositories. A current use case is the
newly introduced `git worktree` feature, which sets up a separate
working copy, where the backing git object store and references
are pointed to by the common directory.
2017-02-13 10:13:02 +01:00
Patrick Steinhardt
807d57e7df tests: implement worktree helpers 2017-02-13 10:13:02 +01:00
Patrick Steinhardt
8acc3b16ef tests: add merge-conflict branch for testrepo
Add a new branch that causes a merge conflict to `testrepo` so
that we are able to test merging in worktrees.
2017-02-13 10:13:02 +01:00
Patrick Steinhardt
e5a620de80 tests: add submodule worktree test data
Create worktrees for submodule repositories. The worktrees are
created for the parent repository (e.g. the one containing
submodules) and for the contained child repository.
2017-02-13 10:13:02 +01:00
Patrick Steinhardt
bd9f4fd24c tests: add worktree test data 2017-02-13 10:13:02 +01:00
Edward Thomson
b0c3fa36c1 Merge pull request #4112 from cbargren/fix/proxy-env-vars
Add support for lowercase proxy environment variables
2017-02-10 16:15:41 +00:00