Skip to content

Commit 2481c4c

Browse files
authored
Merge pull request git-for-windows#2091 from dscho/symlink-attr-extra
Touch up symlink .gitattributes support
2 parents f6431eb + 74e71f1 commit 2481c4c

File tree

9 files changed

+31
-16
lines changed

9 files changed

+31
-16
lines changed

apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4346,7 +4346,7 @@ static int try_create_file(struct apply_state *state, const char *path,
43464346
/* Although buf:size is counted string, it also is NUL
43474347
* terminated.
43484348
*/
4349-
return !!symlink(buf, path);
4349+
return !!create_symlink(state && state->repo ? state->repo->index : NULL, buf, path);
43504350

43514351
fd = open(path, O_CREAT | O_EXCL | O_WRONLY, (mode & 0100) ? 0777 : 0666);
43524352
if (fd < 0)

builtin/difftool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
505505
}
506506
add_path(&wtdir, wtdir_len, dst_path);
507507
if (symlinks) {
508-
if (symlink(wtdir.buf, rdir.buf)) {
508+
if (create_symlink(lstate.istate, wtdir.buf, rdir.buf)) {
509509
ret = error_errno("could not symlink '%s' to '%s'", wtdir.buf, rdir.buf);
510510
goto finish;
511511
}

builtin/init-db.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
7676
if (strbuf_readlink(&lnk, template_path->buf,
7777
st_template.st_size) < 0)
7878
die_errno(_("cannot readlink '%s'"), template_path->buf);
79-
if (symlink(lnk.buf, path->buf))
79+
if (create_symlink(NULL, lnk.buf, path->buf))
8080
die_errno(_("cannot symlink '%s' '%s'"),
8181
lnk.buf, path->buf);
8282
strbuf_release(&lnk);
@@ -278,7 +278,7 @@ static int create_default_files(const char *template_path,
278278
path = git_path_buf(&buf, "tXXXXXX");
279279
if (!close(xmkstemp(path)) &&
280280
!unlink(path) &&
281-
!symlink("testing", path) &&
281+
!create_symlink(NULL, "testing", path) &&
282282
!lstat(path, &st1) &&
283283
S_ISLNK(st1.st_mode))
284284
unlink(path); /* good */

compat/mingw.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,28 +2573,32 @@ enum symlink_type {
25732573
SYMLINK_TYPE_DIRECTORY,
25742574
};
25752575

2576-
static enum symlink_type check_symlink_attr(const char *link)
2576+
static enum symlink_type check_symlink_attr(struct index_state *index, const char *link)
25772577
{
25782578
static struct attr_check *check;
25792579
const char *value;
25802580

2581+
if (!index)
2582+
return SYMLINK_TYPE_UNSPECIFIED;
2583+
25812584
if (!check)
25822585
check = attr_check_initl("symlink", NULL);
25832586

2584-
git_check_attr(the_repository->index, link, check);
2587+
git_check_attr(index, link, check);
25852588

25862589
value = check->items[0].value;
2587-
if (value == NULL)
2588-
;
2589-
else if (!strcmp(value, "file"))
2590+
if (ATTR_UNSET(value))
2591+
return SYMLINK_TYPE_UNSPECIFIED;
2592+
if (!strcmp(value, "file"))
25902593
return SYMLINK_TYPE_FILE;
2591-
else if (!strcmp(value, "dir"))
2594+
if (!strcmp(value, "dir") || !strcmp(value, "directory"))
25922595
return SYMLINK_TYPE_DIRECTORY;
25932596

2597+
warning(_("ignoring invalid symlink type '%s' for '%s'"), value, link);
25942598
return SYMLINK_TYPE_UNSPECIFIED;
25952599
}
25962600

2597-
int symlink(const char *target, const char *link)
2601+
int mingw_create_symlink(struct index_state *index, const char *target, const char *link)
25982602
{
25992603
wchar_t wtarget[MAX_LONG_PATH], wlink[MAX_LONG_PATH];
26002604
int len;
@@ -2614,7 +2618,7 @@ int symlink(const char *target, const char *link)
26142618
if (wtarget[len] == '/')
26152619
wtarget[len] = '\\';
26162620

2617-
switch (check_symlink_attr(link)) {
2621+
switch (check_symlink_attr(index, link)) {
26182622
case SYMLINK_TYPE_UNSPECIFIED:
26192623
/* Create a phantom symlink: it is initially created as a file
26202624
* symlink, but may change to a directory symlink later if/when

compat/mingw.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,10 @@ int setitimer(int type, struct itimerval *in, struct itimerval *out);
214214
int sigaction(int sig, struct sigaction *in, struct sigaction *out);
215215
int link(const char *oldpath, const char *newpath);
216216
int uname(struct utsname *buf);
217-
int symlink(const char *target, const char *link);
218217
int readlink(const char *path, char *buf, size_t bufsiz);
218+
struct index_state;
219+
int mingw_create_symlink(struct index_state *index, const char *target, const char *link);
220+
#define create_symlink mingw_create_symlink
219221

220222
/*
221223
* replacements of existing functions

entry.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ static int write_entry(struct cache_entry *ce,
289289
if (!has_symlinks || to_tempfile)
290290
goto write_file_entry;
291291

292-
ret = symlink(new_blob, path);
292+
ret = create_symlink(state ? state->istate : NULL, new_blob, path);
293293
free(new_blob);
294294
if (ret)
295295
return error_errno("unable to create symlink %s", path);

git-compat-util.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,15 @@ static inline char *git_find_last_dir_sep(const char *path)
405405
#define find_last_dir_sep git_find_last_dir_sep
406406
#endif
407407

408+
#ifndef create_symlink
409+
struct index_state;
410+
static inline int git_create_symlink(struct index_state *index, const char *target, const char *link)
411+
{
412+
return symlink(target, link);
413+
}
414+
#define create_symlink git_create_symlink
415+
#endif
416+
408417
#ifndef query_user_email
409418
#define query_user_email() NULL
410419
#endif

merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ static int update_file_flags(struct merge_options *o,
10111011
char *lnk = xmemdupz(buf, size);
10121012
safe_create_leading_directories_const(path);
10131013
unlink(path);
1014-
if (symlink(lnk, path))
1014+
if (create_symlink(&o->orig_index, lnk, path))
10151015
ret = err(o, _("failed to symlink '%s': %s"),
10161016
path, strerror(errno));
10171017
free(lnk);

refs/files-backend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,7 @@ static int create_ref_symlink(struct ref_lock *lock, const char *target)
17861786
#ifndef NO_SYMLINK_HEAD
17871787
char *ref_path = get_locked_file_path(&lock->lk);
17881788
unlink(ref_path);
1789-
ret = symlink(target, ref_path);
1789+
ret = create_symlink(NULL, target, ref_path);
17901790
free(ref_path);
17911791

17921792
if (ret)

0 commit comments

Comments
 (0)