mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-05 15:33:51 +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);
|
hFind = FindFirstFileW(wbuf, &ffd);
|
||||||
if (INVALID_HANDLE_VALUE == hFind) {
|
if (INVALID_HANDLE_VALUE == hFind) {
|
||||||
giterr_set(GITERR_OS, "Couldn't open '%s'", path);
|
giterr_set(GITERR_OS, "Couldn't open '%s'", path);
|
||||||
|
git_buf_free(&pathbuf);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (!git_path_is_dot_or_dotdotW(ffd.cFileName)) {
|
if (!git_path_is_dot_or_dotdotW(ffd.cFileName)) {
|
||||||
retval = false;
|
retval = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} while (FindNextFileW(hFind, &ffd) != 0);
|
} 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_as_utf8 filter;
|
||||||
git_win32_path filter_w;
|
git_win32_path filter_w;
|
||||||
git__DIR *new = NULL;
|
git__DIR *new = NULL;
|
||||||
|
size_t dirlen;
|
||||||
|
|
||||||
if (!dir || !init_filter(filter, sizeof(filter), dir))
|
if (!dir || !init_filter(filter, sizeof(filter), dir))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
new = git__calloc(1, sizeof(*new));
|
dirlen = strlen(dir);
|
||||||
|
|
||||||
|
new = git__calloc(sizeof(*new) + dirlen + 1, 1);
|
||||||
if (!new)
|
if (!new)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
memcpy(new->dir, dir, dirlen);
|
||||||
new->dir = git__strdup(dir);
|
|
||||||
if (!new->dir)
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
git_win32_path_from_c(filter_w, filter);
|
git_win32_path_from_c(filter_w, filter);
|
||||||
new->h = FindFirstFileW(filter_w, &new->f);
|
new->h = FindFirstFileW(filter_w, &new->f);
|
||||||
|
|
||||||
if (new->h == INVALID_HANDLE_VALUE) {
|
if (new->h == INVALID_HANDLE_VALUE) {
|
||||||
giterr_set(GITERR_OS, "Could not open directory '%s'", dir);
|
giterr_set(GITERR_OS, "Could not open directory '%s'", dir);
|
||||||
goto fail;
|
git__free(new);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
new->first = 1;
|
new->first = 1;
|
||||||
return new;
|
return new;
|
||||||
|
|
||||||
fail:
|
|
||||||
git__free(new->dir);
|
|
||||||
git__free(new);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int git__readdir_ext(
|
int git__readdir_ext(
|
||||||
@ -133,8 +129,7 @@ int git__closedir(git__DIR *d)
|
|||||||
FindClose(d->h);
|
FindClose(d->h);
|
||||||
d->h = INVALID_HANDLE_VALUE;
|
d->h = INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
git__free(d->dir);
|
|
||||||
d->dir = NULL;
|
|
||||||
git__free(d);
|
git__free(d);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,8 @@ typedef struct {
|
|||||||
HANDLE h;
|
HANDLE h;
|
||||||
WIN32_FIND_DATAW f;
|
WIN32_FIND_DATAW f;
|
||||||
struct git__dirent entry;
|
struct git__dirent entry;
|
||||||
char *dir;
|
|
||||||
int first;
|
int first;
|
||||||
|
char dir[GIT_FLEX_ARRAY];
|
||||||
} git__DIR;
|
} git__DIR;
|
||||||
|
|
||||||
extern git__DIR *git__opendir(const char *);
|
extern git__DIR *git__opendir(const char *);
|
||||||
|
@ -514,10 +514,10 @@ p_gmtime_r (const time_t *timer, struct tm *result)
|
|||||||
#else
|
#else
|
||||||
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
|
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _TIMEZONE_DEFINED
|
#ifndef _TIMEZONE_DEFINED
|
||||||
#define _TIMEZONE_DEFINED
|
#define _TIMEZONE_DEFINED
|
||||||
struct timezone
|
struct timezone
|
||||||
{
|
{
|
||||||
int tz_minuteswest; /* minutes W of Greenwich */
|
int tz_minuteswest; /* minutes W of Greenwich */
|
||||||
int tz_dsttime; /* type of dst correction */
|
int tz_dsttime; /* type of dst correction */
|
||||||
|
@ -66,12 +66,13 @@ char *cl_getenv(const char *name)
|
|||||||
if (alloc_len <= 0)
|
if (alloc_len <= 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
alloc_len = GIT_WIN_PATH_UTF8;
|
|
||||||
cl_assert(value_utf16 = git__calloc(alloc_len, sizeof(wchar_t)));
|
cl_assert(value_utf16 = git__calloc(alloc_len, sizeof(wchar_t)));
|
||||||
|
|
||||||
GetEnvironmentVariableW(name_utf16, value_utf16, alloc_len);
|
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__utf16_to_8(value_utf8, alloc_len, value_utf16);
|
||||||
|
|
||||||
git__free(value_utf16);
|
git__free(value_utf16);
|
||||||
|
Loading…
Reference in New Issue
Block a user