aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2026-03-15 14:46:30 -0700
committerJunio C Hamano <gitster@pobox.com>2026-03-15 14:46:30 -0700
commit6e84af9ff4f271b636f3be2ee8daba0fb79c2f84 (patch)
treea046b36e90e1ca37dba24bc77f9cd650b12d2c94
parent795c338de725e13bd361214c6b768019fc45a2c1 (diff)
parentf21967e5415673824d501b318a252c6e8a91d6fb (diff)
downloadgit-6e84af9ff4f271b636f3be2ee8daba0fb79c2f84.tar.xz
Merge branch 'dd/list-objects-filter-options-wo-strbuf-split' into dd/cocci-do-not-pass-strbuf-by-value
* dd/list-objects-filter-options-wo-strbuf-split: list-objects-filter-options: avoid strbuf_split_str() worktree: do not pass strbuf by value
-rw-r--r--builtin/worktree.c2
-rw-r--r--list-objects-filter-options.c40
-rwxr-xr-xt/t6112-rev-list-filters-objects.sh4
-rw-r--r--worktree.c22
-rw-r--r--worktree.h2
5 files changed, 33 insertions, 37 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index bc2d0d645b..4035b1cb06 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -539,7 +539,7 @@ static int add_worktree(const char *path, const char *refname,
strbuf_reset(&sb);
strbuf_addf(&sb, "%s/gitdir", sb_repo.buf);
- write_worktree_linking_files(sb_git, sb, opts->relative_paths);
+ write_worktree_linking_files(sb_git.buf, sb.buf, opts->relative_paths);
strbuf_reset(&sb);
strbuf_addf(&sb, "%s/commondir", sb_repo.buf);
write_file(sb.buf, "../..");
diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c
index 7f3e7b8f50..cef67e5919 100644
--- a/list-objects-filter-options.c
+++ b/list-objects-filter-options.c
@@ -125,9 +125,9 @@ int gently_parse_list_objects_filter(
static const char *RESERVED_NON_WS = "~`!@#$^&*()[]{}\\;'\",<>?";
static int has_reserved_character(
- struct strbuf *sub_spec, struct strbuf *errbuf)
+ const char *sub_spec, struct strbuf *errbuf)
{
- const char *c = sub_spec->buf;
+ const char *c = sub_spec;
while (*c) {
if (*c <= ' ' || strchr(RESERVED_NON_WS, *c)) {
strbuf_addf(
@@ -144,7 +144,7 @@ static int has_reserved_character(
static int parse_combine_subfilter(
struct list_objects_filter_options *filter_options,
- struct strbuf *subspec,
+ const char *subspec,
struct strbuf *errbuf)
{
size_t new_index = filter_options->sub_nr;
@@ -155,7 +155,7 @@ static int parse_combine_subfilter(
filter_options->sub_alloc);
list_objects_filter_init(&filter_options->sub[new_index]);
- decoded = url_percent_decode(subspec->buf);
+ decoded = url_percent_decode(subspec);
result = has_reserved_character(subspec, errbuf);
if (result)
@@ -182,34 +182,34 @@ static int parse_combine_filter(
const char *arg,
struct strbuf *errbuf)
{
- struct strbuf **subspecs = strbuf_split_str(arg, '+', 0);
- size_t sub;
+ const char *p = arg;
+ struct strbuf sub = STRBUF_INIT;
int result = 0;
- if (!subspecs[0]) {
+ if (!*p) {
strbuf_addstr(errbuf, _("expected something after combine:"));
result = 1;
goto cleanup;
}
- for (sub = 0; subspecs[sub] && !result; sub++) {
- if (subspecs[sub + 1]) {
- /*
- * This is not the last subspec. Remove trailing "+" so
- * we can parse it.
- */
- size_t last = subspecs[sub]->len - 1;
- assert(subspecs[sub]->buf[last] == '+');
- strbuf_remove(subspecs[sub], last, 1);
- }
- result = parse_combine_subfilter(
- filter_options, subspecs[sub], errbuf);
+ while (*p && !result) {
+ const char *end = strchrnul(p, '+');
+
+ strbuf_reset(&sub);
+ strbuf_add(&sub, p, end - p);
+
+ if (sub.len)
+ result = parse_combine_subfilter(filter_options, sub.buf, errbuf);
+
+ if (!*end)
+ break;
+ p = end + 1;
}
+ strbuf_release(&sub);
filter_options->choice = LOFC_COMBINE;
cleanup:
- strbuf_list_free(subspecs);
if (result)
list_objects_filter_release(filter_options);
return result;
diff --git a/t/t6112-rev-list-filters-objects.sh b/t/t6112-rev-list-filters-objects.sh
index 0387f35a32..39211ef989 100755
--- a/t/t6112-rev-list-filters-objects.sh
+++ b/t/t6112-rev-list-filters-objects.sh
@@ -483,10 +483,6 @@ test_expect_success 'combine:... with non-encoded reserved chars' '
"must escape char in sub-filter-spec: .\~."
'
-test_expect_success 'validate err msg for "combine:<valid-filter>+"' '
- expect_invalid_filter_spec combine:tree:2+ "expected .tree:<depth>."
-'
-
test_expect_success 'combine:... with edge-case hex digits: Ff Aa 0 9' '
git -C r3 rev-list --objects --filter="combine:tree:2+bl%6Fb:n%6fne" \
HEAD >actual &&
diff --git a/worktree.c b/worktree.c
index 6e2f0f7828..7eba12c6ed 100644
--- a/worktree.c
+++ b/worktree.c
@@ -445,7 +445,7 @@ void update_worktree_location(struct worktree *wt, const char *path_,
strbuf_realpath(&path, path_, 1);
strbuf_addf(&dotgit, "%s/.git", path.buf);
if (fspathcmp(wt->path, path.buf)) {
- write_worktree_linking_files(dotgit, gitdir, use_relative_paths);
+ write_worktree_linking_files(dotgit.buf, gitdir.buf, use_relative_paths);
free(wt->path);
wt->path = strbuf_detach(&path, NULL);
@@ -684,7 +684,7 @@ static void repair_gitfile(struct worktree *wt,
if (repair) {
fn(0, wt->path, repair, cb_data);
- write_worktree_linking_files(dotgit, gitdir, use_relative_paths);
+ write_worktree_linking_files(dotgit.buf, gitdir.buf, use_relative_paths);
}
done:
@@ -742,7 +742,7 @@ void repair_worktree_after_gitdir_move(struct worktree *wt, const char *old_path
if (!file_exists(dotgit.buf))
goto done;
- write_worktree_linking_files(dotgit, gitdir, is_relative_path);
+ write_worktree_linking_files(dotgit.buf, gitdir.buf, is_relative_path);
done:
strbuf_release(&gitdir);
strbuf_release(&dotgit);
@@ -913,7 +913,7 @@ void repair_worktree_at_path(const char *path,
if (repair) {
fn(0, gitdir.buf, repair, cb_data);
- write_worktree_linking_files(dotgit, gitdir, use_relative_paths);
+ write_worktree_linking_files(dotgit.buf, gitdir.buf, use_relative_paths);
}
done:
free(dotgit_contents);
@@ -1087,17 +1087,17 @@ cleanup:
return res;
}
-void write_worktree_linking_files(struct strbuf dotgit, struct strbuf gitdir,
+void write_worktree_linking_files(const char *dotgit, const char *gitdir,
int use_relative_paths)
{
struct strbuf path = STRBUF_INIT;
struct strbuf repo = STRBUF_INIT;
struct strbuf tmp = STRBUF_INIT;
- strbuf_addbuf(&path, &dotgit);
+ strbuf_addstr(&path, dotgit);
strbuf_strip_suffix(&path, "/.git");
strbuf_realpath(&path, path.buf, 1);
- strbuf_addbuf(&repo, &gitdir);
+ strbuf_addstr(&repo, gitdir);
strbuf_strip_suffix(&repo, "/gitdir");
strbuf_realpath(&repo, repo.buf, 1);
@@ -1110,11 +1110,11 @@ void write_worktree_linking_files(struct strbuf dotgit, struct strbuf gitdir,
}
if (use_relative_paths) {
- write_file(gitdir.buf, "%s/.git", relative_path(path.buf, repo.buf, &tmp));
- write_file(dotgit.buf, "gitdir: %s", relative_path(repo.buf, path.buf, &tmp));
+ write_file(gitdir, "%s/.git", relative_path(path.buf, repo.buf, &tmp));
+ write_file(dotgit, "gitdir: %s", relative_path(repo.buf, path.buf, &tmp));
} else {
- write_file(gitdir.buf, "%s/.git", path.buf);
- write_file(dotgit.buf, "gitdir: %s", repo.buf);
+ write_file(gitdir, "%s/.git", path.buf);
+ write_file(dotgit, "gitdir: %s", repo.buf);
}
strbuf_release(&path);
diff --git a/worktree.h b/worktree.h
index 06efe26b83..f4e46be385 100644
--- a/worktree.h
+++ b/worktree.h
@@ -240,7 +240,7 @@ int init_worktree_config(struct repository *r);
* dotgit: "/path/to/foo/.git"
* gitdir: "/path/to/repo/worktrees/foo/gitdir"
*/
-void write_worktree_linking_files(struct strbuf dotgit, struct strbuf gitdir,
+void write_worktree_linking_files(const char *dotgit, const char *gitdir,
int use_relative_paths);
#endif