Skip to content

Submodule working directory#4243

Merged
ethomson merged 5 commits into
libgit2:masterfrom
pks-t:pks/submodule-workdir
Jun 4, 2017
Merged

Submodule working directory#4243
ethomson merged 5 commits into
libgit2:masterfrom
pks-t:pks/submodule-workdir

Conversation

@pks-t
Copy link
Copy Markdown
Member

@pks-t pks-t commented May 17, 2017

This is work in progress trying to reproduce the error reported in #4242. Please do not merge yet

@pks-t pks-t force-pushed the pks/submodule-workdir branch from 7a67985 to e526fbc Compare May 17, 2017 07:41
pks-t added 4 commits May 19, 2017 08:34
The `path` out-parameter of `find_repo` is being sanitized initially
such that we do not try to append to existing content. The sanitization
is done via `git_buf_free`, though, which forces us to needlessly
reallocate the buffer later in the function. Fix this by using
`git_buf_clear` instead.
The out-parameters of `find_repo` containing found paths of a repository
are a tad confusing, as they are not as obvious as they could be. Rename
them like following to ease reading the code:

- `repo_path` -> `gitdir_path`
- `parent_path` -> `workdir_path`
- `link_path` -> `gitlink_path`
- `common_path` -> `commondir_path`
The check whether a repository is a worktree or not is currently done
inside of `git_repository_open_ext`. As we want to extend this function
later on, pull it out into its own function `repo_is_worktree` to ease
working on it.
To determine if a repository is a worktree or not, we currently check
for the existence of a "gitdir" file inside of the repository's gitdir.
While this is sufficient for non-broken repositories, we have at least
one case of a subtly broken repository where there exists a gitdir file
inside of a gitmodule. This will cause us to misidentify the submodule
as a worktree.

While this is not really a fault of ours, we can do better here by
observing that a repository can only ever be a worktree iff its common
directory and dotgit directory are different. This allows us to make our
check whether a repo is a worktree or not more strict by doing a simple
string comparison of these two directories. This will also allow us to
do the right thing in the above case of a broken repository, as for
submodules these directories will be the same. At the same time, this
allows us to skip the `stat` check for the "gitdir" file for most
repositories.
@pks-t pks-t force-pushed the pks/submodule-workdir branch from 0fb9568 to 2696c5c Compare May 19, 2017 07:45
@pks-t
Copy link
Copy Markdown
Member Author

pks-t commented May 19, 2017

I consider this PR ready to be merged now. It fixes the broken case of #4242 by making our checks whether a repository is a workdir or not more strict.

@pks-t pks-t mentioned this pull request May 19, 2017
8 tasks
@ethomson ethomson merged commit 04de614 into libgit2:master Jun 4, 2017
@ethomson
Copy link
Copy Markdown
Member

ethomson commented Jun 4, 2017

Thanks for taking care of this!

@pks-t pks-t deleted the pks/submodule-workdir branch June 6, 2017 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants