summaryrefslogtreecommitdiff
path: root/src/win32/findfile.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-09-07 17:53:49 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2021-10-17 09:49:01 -0400
commitf0e693b18afbe1de37d7da5b5a8967b6c87d8e53 (patch)
treebe5e1cdbfa218ba81ec06bf45e45cfeb7f79a2a5 /src/win32/findfile.c
parent5346be3ddd3bcf19779c5d62e71f8442a0171133 (diff)
downloadlibgit2-ethomson/gitstr.tar.gz
str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstr
libgit2 has two distinct requirements that were previously solved by `git_buf`. We require: 1. A general purpose string class that provides a number of utility APIs for manipulating data (eg, concatenating, truncating, etc). 2. A structure that we can use to return strings to callers that they can take ownership of. By using a single class (`git_buf`) for both of these purposes, we have confused the API to the point that refactorings are difficult and reasoning about correctness is also difficult. Move the utility class `git_buf` to be called `git_str`: this represents its general purpose, as an internal string buffer class. The name also is an homage to Junio Hamano ("gitstr"). The public API remains `git_buf`, and has a much smaller footprint. It is generally only used as an "out" param with strict requirements that follow the documentation. (Exceptions exist for some legacy APIs to avoid breaking callers unnecessarily.) Utility functions exist to convert a user-specified `git_buf` to a `git_str` so that we can call internal functions, then converting it back again.
Diffstat (limited to 'src/win32/findfile.c')
-rw-r--r--src/win32/findfile.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/win32/findfile.c b/src/win32/findfile.c
index 40d2d518a..caa79398a 100644
--- a/src/win32/findfile.c
+++ b/src/win32/findfile.c
@@ -34,7 +34,7 @@ static int git_win32__expand_path(_findfile_path *dest, const wchar_t *src)
return 0;
}
-static int win32_path_to_8(git_buf *dest, const wchar_t *src)
+static int win32_path_to_8(git_str *dest, const wchar_t *src)
{
git_win32_utf8_path utf8_path;
@@ -46,7 +46,7 @@ static int win32_path_to_8(git_buf *dest, const wchar_t *src)
/* Convert backslashes to forward slashes */
git_path_mkposix(utf8_path);
- return git_buf_sets(dest, utf8_path);
+ return git_str_sets(dest, utf8_path);
}
static wchar_t *win32_walkpath(wchar_t *path, wchar_t *buf, size_t buflen)
@@ -70,7 +70,7 @@ static wchar_t *win32_walkpath(wchar_t *path, wchar_t *buf, size_t buflen)
return (path != base) ? path : NULL;
}
-static int win32_find_git_in_path(git_buf *buf, const wchar_t *gitexe, const wchar_t *subdir)
+static int win32_find_git_in_path(git_str *buf, const wchar_t *gitexe, const wchar_t *subdir)
{
wchar_t *env = _wgetenv(L"PATH"), lastch;
_findfile_path root;
@@ -106,7 +106,7 @@ static int win32_find_git_in_path(git_buf *buf, const wchar_t *gitexe, const wch
}
static int win32_find_git_in_registry(
- git_buf *buf, const HKEY hive, const wchar_t *key, const wchar_t *subdir)
+ git_str *buf, const HKEY hive, const wchar_t *key, const wchar_t *subdir)
{
HKEY hKey;
int error = GIT_ENOTFOUND;
@@ -141,12 +141,12 @@ static int win32_find_git_in_registry(
}
static int win32_find_existing_dirs(
- git_buf *out, const wchar_t *tmpl[])
+ git_str *out, const wchar_t *tmpl[])
{
_findfile_path path16;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- git_buf_clear(out);
+ git_str_clear(out);
for (; *tmpl != NULL; tmpl++) {
if (!git_win32__expand_path(&path16, *tmpl) &&
@@ -156,43 +156,43 @@ static int win32_find_existing_dirs(
win32_path_to_8(&buf, path16.path);
if (buf.size)
- git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
+ git_str_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
}
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
- return (git_buf_oom(out) ? -1 : 0);
+ return (git_str_oom(out) ? -1 : 0);
}
-int git_win32__find_system_dirs(git_buf *out, const wchar_t *subdir)
+int git_win32__find_system_dirs(git_str *out, const wchar_t *subdir)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
/* directories where git.exe & git.cmd are found */
if (!win32_find_git_in_path(&buf, L"git.exe", subdir) && buf.size)
- git_buf_set(out, buf.ptr, buf.size);
+ git_str_set(out, buf.ptr, buf.size);
else
- git_buf_clear(out);
+ git_str_clear(out);
if (!win32_find_git_in_path(&buf, L"git.cmd", subdir) && buf.size)
- git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
+ git_str_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
/* directories where git is installed according to registry */
if (!win32_find_git_in_registry(
&buf, HKEY_CURRENT_USER, REG_MSYSGIT_INSTALL_LOCAL, subdir) && buf.size)
- git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
+ git_str_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
if (!win32_find_git_in_registry(
&buf, HKEY_LOCAL_MACHINE, REG_MSYSGIT_INSTALL, subdir) && buf.size)
- git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
+ git_str_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
- return (git_buf_oom(out) ? -1 : 0);
+ return (git_str_oom(out) ? -1 : 0);
}
-int git_win32__find_global_dirs(git_buf *out)
+int git_win32__find_global_dirs(git_str *out)
{
static const wchar_t *global_tmpls[4] = {
L"%HOME%\\",
@@ -204,7 +204,7 @@ int git_win32__find_global_dirs(git_buf *out)
return win32_find_existing_dirs(out, global_tmpls);
}
-int git_win32__find_xdg_dirs(git_buf *out)
+int git_win32__find_xdg_dirs(git_str *out)
{
static const wchar_t *global_tmpls[7] = {
L"%XDG_CONFIG_HOME%\\git",
@@ -219,7 +219,7 @@ int git_win32__find_xdg_dirs(git_buf *out)
return win32_find_existing_dirs(out, global_tmpls);
}
-int git_win32__find_programdata_dirs(git_buf *out)
+int git_win32__find_programdata_dirs(git_str *out)
{
static const wchar_t *programdata_tmpls[2] = {
L"%PROGRAMDATA%\\Git",