diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2021-09-07 17:53:49 -0400 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2021-10-17 09:49:01 -0400 |
commit | f0e693b18afbe1de37d7da5b5a8967b6c87d8e53 (patch) | |
tree | be5e1cdbfa218ba81ec06bf45e45cfeb7f79a2a5 /src/attr.c | |
parent | 5346be3ddd3bcf19779c5d62e71f8442a0171133 (diff) | |
download | libgit2-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/attr.c')
-rw-r--r-- | src/attr.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/attr.c b/src/attr.c index 95b49e3de..5849e701f 100644 --- a/src/attr.c +++ b/src/attr.c @@ -338,7 +338,7 @@ GIT_INLINE(int) preload_attr_file( } static int system_attr_file( - git_buf *out, + git_str *out, git_attr_session *attr_session) { int error; @@ -366,11 +366,11 @@ static int system_attr_file( if (attr_session->sysdir.size == 0) return GIT_ENOTFOUND; - /* We can safely provide a git_buf with no allocation (asize == 0) to - * a consumer. This allows them to treat this as a regular `git_buf`, - * but their call to `git_buf_dispose` will not attempt to free it. + /* We can safely provide a git_str with no allocation (asize == 0) to + * a consumer. This allows them to treat this as a regular `git_str`, + * but their call to `git_str_dispose` will not attempt to free it. */ - git_buf_attach_notowned( + git_str_attach_notowned( out, attr_session->sysdir.ptr, attr_session->sysdir.size); return 0; } @@ -380,7 +380,7 @@ static int attr_setup( git_attr_session *attr_session, git_attr_options *opts) { - git_buf system = GIT_BUF_INIT, info = GIT_BUF_INIT; + git_str system = GIT_STR_INIT, info = GIT_STR_INIT; git_attr_file_source index_source = { GIT_ATTR_FILE_SOURCE_INDEX, NULL, GIT_ATTR_FILE, NULL }; git_attr_file_source head_source = { GIT_ATTR_FILE_SOURCE_HEAD, NULL, GIT_ATTR_FILE, NULL }; git_attr_file_source commit_source = { GIT_ATTR_FILE_SOURCE_COMMIT, NULL, GIT_ATTR_FILE, NULL }; @@ -411,7 +411,7 @@ static int attr_setup( git_repository_attr_cache(repo)->cfg_attr_file)) < 0) goto out; - if ((error = git_repository_item_path(&info, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 || + if ((error = git_repository__item_path(&info, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 || (error = preload_attr_file(repo, attr_session, info.ptr, GIT_ATTR_FILE_INREPO)) < 0) { if (error != GIT_ENOTFOUND) goto out; @@ -447,8 +447,8 @@ static int attr_setup( attr_session->init_setup = 1; out: - git_buf_dispose(&system); - git_buf_dispose(&info); + git_str_dispose(&system); + git_str_dispose(&info); return error; } @@ -625,7 +625,7 @@ static int collect_attr_files( git_vector *files) { int error = 0; - git_buf dir = GIT_BUF_INIT, attrfile = GIT_BUF_INIT; + git_str dir = GIT_STR_INIT, attrfile = GIT_STR_INIT; const char *workdir = git_repository_workdir(repo); attr_walk_up_info info = { NULL }; @@ -653,7 +653,7 @@ static int collect_attr_files( * - $GIT_PREFIX/etc/gitattributes */ - if ((error = git_repository_item_path(&attrfile, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 || + if ((error = git_repository__item_path(&attrfile, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 || (error = push_attr_file(repo, attr_session, files, attrfile.ptr, GIT_ATTR_FILE_INREPO)) < 0) { if (error != GIT_ENOTFOUND) goto cleanup; @@ -693,8 +693,8 @@ static int collect_attr_files( cleanup: if (error < 0) release_attr_files(files); - git_buf_dispose(&attrfile); - git_buf_dispose(&dir); + git_str_dispose(&attrfile); + git_str_dispose(&dir); return error; } |