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/ignore.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/ignore.c')
-rw-r--r-- | src/ignore.c | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/ignore.c b/src/ignore.c index 9ead96ba6..eb9fd8a9e 100644 --- a/src/ignore.c +++ b/src/ignore.c @@ -105,7 +105,7 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match size_t i; git_attr_fnmatch *rule; char *path; - git_buf buf = GIT_BUF_INIT; + git_str buf = GIT_STR_INIT; *out = 0; @@ -115,12 +115,12 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match /* path of the file relative to the workdir, so we match the rules in subdirs */ if (match->containing_dir) { - git_buf_puts(&buf, match->containing_dir); + git_str_puts(&buf, match->containing_dir); } - if (git_buf_puts(&buf, match->pattern) < 0) + if (git_str_puts(&buf, match->pattern) < 0) return -1; - path = git_buf_detach(&buf); + path = git_str_detach(&buf); git_vector_foreach(rules, i, rule) { if (!(rule->flags & GIT_ATTR_FNMATCH_HASWILD)) { @@ -133,12 +133,12 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match continue; } - git_buf_clear(&buf); + git_str_clear(&buf); if (rule->containing_dir) - git_buf_puts(&buf, rule->containing_dir); - git_buf_puts(&buf, rule->pattern); + git_str_puts(&buf, rule->containing_dir); + git_str_puts(&buf, rule->pattern); - if (git_buf_oom(&buf)) + if (git_str_oom(&buf)) goto out; /* @@ -151,7 +151,7 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match effective_flags &= ~WM_PATHNAME; /* if we found a match, we want to keep this rule */ - if ((wildmatch(git_buf_cstr(&buf), path, effective_flags)) == WM_MATCH) { + if ((wildmatch(git_str_cstr(&buf), path, effective_flags)) == WM_MATCH) { *out = 1; error = 0; goto out; @@ -162,7 +162,7 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match out: git__free(path); - git_buf_dispose(&buf); + git_str_dispose(&buf); return error; } @@ -295,7 +295,7 @@ int git_ignore__for_path( { int error = 0; const char *workdir = git_repository_workdir(repo); - git_buf infopath = GIT_BUF_INIT; + git_str infopath = GIT_STR_INIT; GIT_ASSERT_ARG(repo); GIT_ASSERT_ARG(ignores); @@ -314,19 +314,19 @@ int git_ignore__for_path( /* given a unrooted path in a non-bare repo, resolve it */ if (workdir && git_path_root(path) < 0) { - git_buf local = GIT_BUF_INIT; + git_str local = GIT_STR_INIT; if ((error = git_path_dirname_r(&local, path)) < 0 || (error = git_path_resolve_relative(&local, 0)) < 0 || (error = git_path_to_dir(&local)) < 0 || - (error = git_buf_joinpath(&ignores->dir, workdir, local.ptr)) < 0 || + (error = git_str_joinpath(&ignores->dir, workdir, local.ptr)) < 0 || (error = git_path_validate_workdir_buf(repo, &ignores->dir)) < 0) { /* Nothing, we just want to stop on the first error */ } - git_buf_dispose(&local); + git_str_dispose(&local); } else { - if (!(error = git_buf_joinpath(&ignores->dir, path, ""))) + if (!(error = git_str_joinpath(&ignores->dir, path, ""))) error = git_path_validate_filesystem(ignores->dir.ptr, ignores->dir.size); } @@ -349,7 +349,7 @@ int git_ignore__for_path( } /* load .git/info/exclude if possible */ - if ((error = git_repository_item_path(&infopath, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 || + if ((error = git_repository__item_path(&infopath, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 || (error = push_ignore_file(ignores, &ignores->ign_global, infopath.ptr, GIT_IGNORE_FILE_INREPO)) < 0) { if (error != GIT_ENOTFOUND) goto cleanup; @@ -363,7 +363,7 @@ int git_ignore__for_path( git_repository_attr_cache(repo)->cfg_excl_file); cleanup: - git_buf_dispose(&infopath); + git_str_dispose(&infopath); if (error < 0) git_ignore__free(ignores); @@ -372,7 +372,7 @@ cleanup: int git_ignore__push_dir(git_ignores *ign, const char *dir) { - if (git_buf_joinpath(&ign->dir, ign->dir.ptr, dir) < 0) + if (git_str_joinpath(&ign->dir, ign->dir.ptr, dir) < 0) return -1; ign->depth++; @@ -409,7 +409,7 @@ int git_ignore__pop_dir(git_ignores *ign) } if (--ign->depth > 0) { - git_buf_rtruncate_at_char(&ign->dir, '/'); + git_str_rtruncate_at_char(&ign->dir, '/'); git_path_to_dir(&ign->dir); } @@ -435,7 +435,7 @@ void git_ignore__free(git_ignores *ignores) } git_vector_free(&ignores->ign_global); - git_buf_dispose(&ignores->dir); + git_str_dispose(&ignores->dir); } static bool ignore_lookup_in_rules( @@ -604,7 +604,7 @@ int git_ignore__check_pathspec_for_exact_ignores( size_t i; git_attr_fnmatch *match; int ignored; - git_buf path = GIT_BUF_INIT; + git_str path = GIT_STR_INIT; const char *filename; git_index *idx; @@ -645,7 +645,7 @@ int git_ignore__check_pathspec_for_exact_ignores( } git_index_free(idx); - git_buf_dispose(&path); + git_str_dispose(&path); return error; } |