зеркало из https://github.com/microsoft/git.git
mingw: allow to specify the symlink type in .gitattributes
On Windows, symbolic links have a type: a "file symlink" must point at a file, and a "directory symlink" must point at a directory. If the type of symlink does not match its target, it doesn't work. Git does not record the type of symlink in the index or in a tree. On checkout it'll guess the type, which only works if the target exists at the time the symlink is created. This may often not be the case, for example when the link points at a directory inside a submodule. By specifying `symlink=file` or `symlink=dir` the user can specify what type of symlink Git should create, so Git doesn't have to rely on unreliable heuristics. Signed-off-by: Bert Belder <bertbelder@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Родитель
f4a211f39f
Коммит
0fa2f7f927
|
@ -385,6 +385,36 @@ sign `$` upon checkout. Any byte sequence that begins with
|
|||
with `$Id$` upon check-in.
|
||||
|
||||
|
||||
`symlink`
|
||||
^^^^^^^^^
|
||||
|
||||
On Windows, symbolic links have a type: a "file symlink" must point at
|
||||
a file, and a "directory symlink" must point at a directory. If the
|
||||
type of symlink does not match its target, it doesn't work.
|
||||
|
||||
Git does not record the type of symlink in the index or in a tree. On
|
||||
checkout it'll guess the type, which only works if the target exists
|
||||
at the time the symlink is created. This may often not be the case,
|
||||
for example when the link points at a directory inside a submodule.
|
||||
|
||||
The `symlink` attribute allows you to explicitly set the type of symlink
|
||||
to `file` or `dir`, so Git doesn't have to guess. If you have a set of
|
||||
symlinks that point at other files, you can do:
|
||||
|
||||
------------------------
|
||||
*.gif symlink=file
|
||||
------------------------
|
||||
|
||||
To tell Git that a symlink points at a directory, use:
|
||||
|
||||
------------------------
|
||||
tools_folder symlink=dir
|
||||
------------------------
|
||||
|
||||
The `symlink` attribute is ignored on platforms other than Windows,
|
||||
since they don't distinguish between different types of symlinks.
|
||||
|
||||
|
||||
`filter`
|
||||
^^^^^^^^
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#define SECURITY_WIN32
|
||||
#include <sspi.h>
|
||||
#include "win32/fscache.h"
|
||||
#include "../attr.h"
|
||||
|
||||
#define HCAST(type, handle) ((type)(intptr_t)handle)
|
||||
|
||||
|
@ -2911,6 +2912,37 @@ int link(const char *oldpath, const char *newpath)
|
|||
return 0;
|
||||
}
|
||||
|
||||
enum symlink_type {
|
||||
SYMLINK_TYPE_UNSPECIFIED = 0,
|
||||
SYMLINK_TYPE_FILE,
|
||||
SYMLINK_TYPE_DIRECTORY,
|
||||
};
|
||||
|
||||
static enum symlink_type check_symlink_attr(struct index_state *index, const char *link)
|
||||
{
|
||||
static struct attr_check *check;
|
||||
const char *value;
|
||||
|
||||
if (!index)
|
||||
return SYMLINK_TYPE_UNSPECIFIED;
|
||||
|
||||
if (!check)
|
||||
check = attr_check_initl("symlink", NULL);
|
||||
|
||||
git_check_attr(index, NULL, link, check);
|
||||
|
||||
value = check->items[0].value;
|
||||
if (ATTR_UNSET(value))
|
||||
return SYMLINK_TYPE_UNSPECIFIED;
|
||||
if (!strcmp(value, "file"))
|
||||
return SYMLINK_TYPE_FILE;
|
||||
if (!strcmp(value, "dir") || !strcmp(value, "directory"))
|
||||
return SYMLINK_TYPE_DIRECTORY;
|
||||
|
||||
warning(_("ignoring invalid symlink type '%s' for '%s'"), value, link);
|
||||
return SYMLINK_TYPE_UNSPECIFIED;
|
||||
}
|
||||
|
||||
int mingw_create_symlink(struct index_state *index, const char *target, const char *link)
|
||||
{
|
||||
wchar_t wtarget[MAX_LONG_PATH], wlink[MAX_LONG_PATH];
|
||||
|
@ -2931,7 +2963,31 @@ int mingw_create_symlink(struct index_state *index, const char *target, const ch
|
|||
if (wtarget[len] == '/')
|
||||
wtarget[len] = '\\';
|
||||
|
||||
return create_phantom_symlink(wtarget, wlink);
|
||||
switch (check_symlink_attr(index, link)) {
|
||||
case SYMLINK_TYPE_UNSPECIFIED:
|
||||
/* Create a phantom symlink: it is initially created as a file
|
||||
* symlink, but may change to a directory symlink later if/when
|
||||
* the target exists. */
|
||||
return create_phantom_symlink(wtarget, wlink);
|
||||
case SYMLINK_TYPE_FILE:
|
||||
if (!CreateSymbolicLinkW(wlink, wtarget, symlink_file_flags))
|
||||
break;
|
||||
return 0;
|
||||
case SYMLINK_TYPE_DIRECTORY:
|
||||
if (!CreateSymbolicLinkW(wlink, wtarget,
|
||||
symlink_directory_flags))
|
||||
break;
|
||||
/* There may be dangling phantom symlinks that point at this
|
||||
* one, which should now morph into directory symlinks. */
|
||||
process_phantom_symlinks();
|
||||
return 0;
|
||||
default:
|
||||
BUG("unhandled symlink type");
|
||||
}
|
||||
|
||||
/* CreateSymbolicLinkW failed. */
|
||||
errno = err_win_to_posix(GetLastError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifndef _WINNT_H
|
||||
|
|
Загрузка…
Ссылка в новой задаче