Skip to content

Commit 39d66dd

Browse files
committed
Merge branch 'js/prep-symlink-windows'
Further preparation to upstream symbolic link support on Windows. * js/prep-symlink-windows: trim_last_path_component(): avoid hard-coding the directory separator strbuf_readlink(): support link targets that exceed 2*PATH_MAX strbuf_readlink(): avoid calling `readlink()` twice in corner-cases init: do parse _all_ core.* settings early mingw: do resolve symlinks in `getcwd()`
2 parents bc5cbbe + aa7b886 commit 39d66dd

File tree

6 files changed

+18
-20
lines changed

6 files changed

+18
-20
lines changed

compat/mingw.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,18 +1239,16 @@ char *mingw_getcwd(char *pointer, int len)
12391239
{
12401240
wchar_t cwd[MAX_PATH], wpointer[MAX_PATH];
12411241
DWORD ret = GetCurrentDirectoryW(ARRAY_SIZE(cwd), cwd);
1242+
HANDLE hnd;
12421243

12431244
if (!ret || ret >= ARRAY_SIZE(cwd)) {
12441245
errno = ret ? ENAMETOOLONG : err_win_to_posix(GetLastError());
12451246
return NULL;
12461247
}
1247-
ret = GetLongPathNameW(cwd, wpointer, ARRAY_SIZE(wpointer));
1248-
if (!ret && GetLastError() == ERROR_ACCESS_DENIED) {
1249-
HANDLE hnd = CreateFileW(cwd, 0,
1250-
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
1251-
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
1252-
if (hnd == INVALID_HANDLE_VALUE)
1253-
return NULL;
1248+
hnd = CreateFileW(cwd, 0,
1249+
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
1250+
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
1251+
if (hnd != INVALID_HANDLE_VALUE) {
12541252
ret = GetFinalPathNameByHandleW(hnd, wpointer, ARRAY_SIZE(wpointer), 0);
12551253
CloseHandle(hnd);
12561254
if (!ret || ret >= ARRAY_SIZE(wpointer))
@@ -1259,13 +1257,11 @@ char *mingw_getcwd(char *pointer, int len)
12591257
return NULL;
12601258
return pointer;
12611259
}
1262-
if (!ret || ret >= ARRAY_SIZE(wpointer))
1263-
return NULL;
1264-
if (GetFileAttributesW(wpointer) == INVALID_FILE_ATTRIBUTES) {
1260+
if (GetFileAttributesW(cwd) == INVALID_FILE_ATTRIBUTES) {
12651261
errno = ENOENT;
12661262
return NULL;
12671263
}
1268-
if (xwcstoutf(pointer, wpointer, len) < 0)
1264+
if (xwcstoutf(pointer, cwd, len) < 0)
12691265
return NULL;
12701266
convert_slashes(pointer);
12711267
return pointer;

environment.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ static enum fsync_component parse_fsync_components(const char *var, const char *
324324
return (current & ~negative) | positive;
325325
}
326326

327-
static int git_default_core_config(const char *var, const char *value,
328-
const struct config_context *ctx, void *cb)
327+
int git_default_core_config(const char *var, const char *value,
328+
const struct config_context *ctx, void *cb)
329329
{
330330
/* This needs a better name */
331331
if (!strcmp(var, "core.filemode")) {

environment.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ const char *strip_namespace(const char *namespaced_ref);
106106

107107
int git_default_config(const char *, const char *,
108108
const struct config_context *, void *);
109+
int git_default_core_config(const char *var, const char *value,
110+
const struct config_context *ctx, void *cb);
109111

110112
/*
111113
* TODO: All the below state either explicitly or implicitly relies on

lockfile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ static void trim_last_path_component(struct strbuf *path)
1919
int i = path->len;
2020

2121
/* back up past trailing slashes, if any */
22-
while (i && path->buf[i - 1] == '/')
22+
while (i && is_dir_sep(path->buf[i - 1]))
2323
i--;
2424

2525
/*
2626
* then go backwards until a slash, or the beginning of the
2727
* string
2828
*/
29-
while (i && path->buf[i - 1] != '/')
29+
while (i && !is_dir_sep(path->buf[i - 1]))
3030
i--;
3131

3232
strbuf_setlen(path, i);

setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2693,7 +2693,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
26932693
* have set up the repository format such that we can evaluate
26942694
* includeIf conditions correctly in the case of re-initialization.
26952695
*/
2696-
repo_config(the_repository, platform_core_config, NULL);
2696+
repo_config(the_repository, git_default_core_config, NULL);
26972697

26982698
safe_create_dir(the_repository, git_dir, 0);
26992699

strbuf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ ssize_t strbuf_write(struct strbuf *sb, FILE *f)
566566
return sb->len ? fwrite(sb->buf, 1, sb->len, f) : 0;
567567
}
568568

569-
#define STRBUF_MAXLINK (2*PATH_MAX)
569+
#define STRBUF_MAXLINK (32767)
570570

571571
int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint)
572572
{
@@ -578,12 +578,12 @@ int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint)
578578
while (hint < STRBUF_MAXLINK) {
579579
ssize_t len;
580580

581-
strbuf_grow(sb, hint);
582-
len = readlink(path, sb->buf, hint);
581+
strbuf_grow(sb, hint + 1);
582+
len = readlink(path, sb->buf, hint + 1);
583583
if (len < 0) {
584584
if (errno != ERANGE)
585585
break;
586-
} else if (len < hint) {
586+
} else if (len <= hint) {
587587
strbuf_setlen(sb, len);
588588
return 0;
589589
}

0 commit comments

Comments
 (0)