mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-05 13:38:27 +00:00
Minor win32 fixes and improvements
This is just a bunch of small fixes that I noticed while looking at the UTF8 and UTF16 path stuff. It fixes a slowdown in looking for an empty directory (not exiting loop asap), makes the dir name in the git__DIR structure be a GIT_FLEX_ARRAY to save an allocation, and fixes some slightly odd assumptions in the cl_getenv helper.
This commit is contained in:
parent
841034a35e
commit
ee0656012c
@ -497,12 +497,14 @@ bool git_path_is_empty_dir(const char *path)
|
||||
hFind = FindFirstFileW(wbuf, &ffd);
|
||||
if (INVALID_HANDLE_VALUE == hFind) {
|
||||
giterr_set(GITERR_OS, "Couldn't open '%s'", path);
|
||||
git_buf_free(&pathbuf);
|
||||
return false;
|
||||
}
|
||||
|
||||
do {
|
||||
if (!git_path_is_dot_or_dotdotW(ffd.cFileName)) {
|
||||
retval = false;
|
||||
break;
|
||||
}
|
||||
} while (FindNextFileW(hFind, &ffd) != 0);
|
||||
|
||||
|
@ -27,33 +27,29 @@ git__DIR *git__opendir(const char *dir)
|
||||
git_win32_path_as_utf8 filter;
|
||||
git_win32_path filter_w;
|
||||
git__DIR *new = NULL;
|
||||
size_t dirlen;
|
||||
|
||||
if (!dir || !init_filter(filter, sizeof(filter), dir))
|
||||
return NULL;
|
||||
|
||||
new = git__calloc(1, sizeof(*new));
|
||||
dirlen = strlen(dir);
|
||||
|
||||
new = git__calloc(sizeof(*new) + dirlen + 1, 1);
|
||||
if (!new)
|
||||
return NULL;
|
||||
|
||||
new->dir = git__strdup(dir);
|
||||
if (!new->dir)
|
||||
goto fail;
|
||||
memcpy(new->dir, dir, dirlen);
|
||||
|
||||
git_win32_path_from_c(filter_w, filter);
|
||||
new->h = FindFirstFileW(filter_w, &new->f);
|
||||
|
||||
if (new->h == INVALID_HANDLE_VALUE) {
|
||||
giterr_set(GITERR_OS, "Could not open directory '%s'", dir);
|
||||
goto fail;
|
||||
git__free(new);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
new->first = 1;
|
||||
return new;
|
||||
|
||||
fail:
|
||||
git__free(new->dir);
|
||||
git__free(new);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int git__readdir_ext(
|
||||
@ -133,8 +129,7 @@ int git__closedir(git__DIR *d)
|
||||
FindClose(d->h);
|
||||
d->h = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
git__free(d->dir);
|
||||
d->dir = NULL;
|
||||
|
||||
git__free(d);
|
||||
return 0;
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ typedef struct {
|
||||
HANDLE h;
|
||||
WIN32_FIND_DATAW f;
|
||||
struct git__dirent entry;
|
||||
char *dir;
|
||||
int first;
|
||||
char dir[GIT_FLEX_ARRAY];
|
||||
} git__DIR;
|
||||
|
||||
extern git__DIR *git__opendir(const char *);
|
||||
|
@ -66,12 +66,13 @@ char *cl_getenv(const char *name)
|
||||
if (alloc_len <= 0)
|
||||
return NULL;
|
||||
|
||||
alloc_len = GIT_WIN_PATH_UTF8;
|
||||
cl_assert(value_utf16 = git__calloc(alloc_len, sizeof(wchar_t)));
|
||||
|
||||
GetEnvironmentVariableW(name_utf16, value_utf16, alloc_len);
|
||||
|
||||
cl_assert(value_utf8 = git__malloc(alloc_len));
|
||||
alloc_len = alloc_len * 4 + 1; /* worst case UTF16->UTF8 growth */
|
||||
cl_assert(value_utf8 = git__calloc(alloc_len, 1));
|
||||
|
||||
git__utf16_to_8(value_utf8, alloc_len, value_utf16);
|
||||
|
||||
git__free(value_utf16);
|
||||
|
Loading…
Reference in New Issue
Block a user