Introduce helper to create symlinks that knows about index_state

On Windows, symbolic links actually have a type depending on the target:
it can be a file or a directory.

In certain circumstances, this poses problems, e.g. when a symbolic link
is supposed to point into a submodule that is not checked out, so there
is no way for Git to auto-detect the type.

To help with that, we will add support over the course of the next
commits to specify that symlink type via the Git attributes. This
requires an index_state, though, something that Git for Windows'
`symlink()` replacement cannot know about because the function signature
is defined by the POSIX standard and not ours to change.

So let's introduce a helper function to create symbolic links that
*does* know about the index_state.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2019-02-11 14:19:18 +01:00
committed by Git for Windows Build Agent
parent 5778398772
commit dbfa224abd
8 changed files with 20 additions and 8 deletions

View File

@@ -2224,7 +2224,7 @@ static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
if (strbuf_readlink(&lnk, template_path->buf,
st_template.st_size) < 0)
die_errno(_("cannot readlink '%s'"), template_path->buf);
if (symlink(lnk.buf, path->buf))
if (create_symlink(NULL, lnk.buf, path->buf))
die_errno(_("cannot symlink '%s' '%s'"),
lnk.buf, path->buf);
strbuf_release(&lnk);
@@ -2485,7 +2485,7 @@ static int create_default_files(const char *template_path,
repo_git_path_replace(the_repository, &path, "tXXXXXX");
if (!close(xmkstemp(path.buf)) &&
!unlink(path.buf) &&
!symlink("testing", path.buf) &&
!create_symlink(NULL, "testing", path.buf) &&
!lstat(path.buf, &st1) &&
S_ISLNK(st1.st_mode))
unlink(path.buf); /* good */