Skip to content

Commit 17b9c75

Browse files
committed
Merge branch 'dd/list-objects-filter-options-wo-strbuf-split'
The way combined list-object filter options are parsed has been revamped. * dd/list-objects-filter-options-wo-strbuf-split: list-objects-filter-options: avoid strbuf_split_str() worktree: do not pass strbuf by value
2 parents 2d57632 + f21967e commit 17b9c75

File tree

5 files changed

+33
-37
lines changed

5 files changed

+33
-37
lines changed

builtin/worktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ static int add_worktree(const char *path, const char *refname,
539539

540540
strbuf_reset(&sb);
541541
strbuf_addf(&sb, "%s/gitdir", sb_repo.buf);
542-
write_worktree_linking_files(sb_git, sb, opts->relative_paths);
542+
write_worktree_linking_files(sb_git.buf, sb.buf, opts->relative_paths);
543543
strbuf_reset(&sb);
544544
strbuf_addf(&sb, "%s/commondir", sb_repo.buf);
545545
write_file(sb.buf, "../..");

list-objects-filter-options.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ int gently_parse_list_objects_filter(
125125
static const char *RESERVED_NON_WS = "~`!@#$^&*()[]{}\\;'\",<>?";
126126

127127
static int has_reserved_character(
128-
struct strbuf *sub_spec, struct strbuf *errbuf)
128+
const char *sub_spec, struct strbuf *errbuf)
129129
{
130-
const char *c = sub_spec->buf;
130+
const char *c = sub_spec;
131131
while (*c) {
132132
if (*c <= ' ' || strchr(RESERVED_NON_WS, *c)) {
133133
strbuf_addf(
@@ -144,7 +144,7 @@ static int has_reserved_character(
144144

145145
static int parse_combine_subfilter(
146146
struct list_objects_filter_options *filter_options,
147-
struct strbuf *subspec,
147+
const char *subspec,
148148
struct strbuf *errbuf)
149149
{
150150
size_t new_index = filter_options->sub_nr;
@@ -155,7 +155,7 @@ static int parse_combine_subfilter(
155155
filter_options->sub_alloc);
156156
list_objects_filter_init(&filter_options->sub[new_index]);
157157

158-
decoded = url_percent_decode(subspec->buf);
158+
decoded = url_percent_decode(subspec);
159159

160160
result = has_reserved_character(subspec, errbuf);
161161
if (result)
@@ -182,34 +182,34 @@ static int parse_combine_filter(
182182
const char *arg,
183183
struct strbuf *errbuf)
184184
{
185-
struct strbuf **subspecs = strbuf_split_str(arg, '+', 0);
186-
size_t sub;
185+
const char *p = arg;
186+
struct strbuf sub = STRBUF_INIT;
187187
int result = 0;
188188

189-
if (!subspecs[0]) {
189+
if (!*p) {
190190
strbuf_addstr(errbuf, _("expected something after combine:"));
191191
result = 1;
192192
goto cleanup;
193193
}
194194

195-
for (sub = 0; subspecs[sub] && !result; sub++) {
196-
if (subspecs[sub + 1]) {
197-
/*
198-
* This is not the last subspec. Remove trailing "+" so
199-
* we can parse it.
200-
*/
201-
size_t last = subspecs[sub]->len - 1;
202-
assert(subspecs[sub]->buf[last] == '+');
203-
strbuf_remove(subspecs[sub], last, 1);
204-
}
205-
result = parse_combine_subfilter(
206-
filter_options, subspecs[sub], errbuf);
195+
while (*p && !result) {
196+
const char *end = strchrnul(p, '+');
197+
198+
strbuf_reset(&sub);
199+
strbuf_add(&sub, p, end - p);
200+
201+
if (sub.len)
202+
result = parse_combine_subfilter(filter_options, sub.buf, errbuf);
203+
204+
if (!*end)
205+
break;
206+
p = end + 1;
207207
}
208+
strbuf_release(&sub);
208209

209210
filter_options->choice = LOFC_COMBINE;
210211

211212
cleanup:
212-
strbuf_list_free(subspecs);
213213
if (result)
214214
list_objects_filter_release(filter_options);
215215
return result;

t/t6112-rev-list-filters-objects.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,6 @@ test_expect_success 'combine:... with non-encoded reserved chars' '
483483
"must escape char in sub-filter-spec: .\~."
484484
'
485485

486-
test_expect_success 'validate err msg for "combine:<valid-filter>+"' '
487-
expect_invalid_filter_spec combine:tree:2+ "expected .tree:<depth>."
488-
'
489-
490486
test_expect_success 'combine:... with edge-case hex digits: Ff Aa 0 9' '
491487
git -C r3 rev-list --objects --filter="combine:tree:2+bl%6Fb:n%6fne" \
492488
HEAD >actual &&

worktree.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ void update_worktree_location(struct worktree *wt, const char *path_,
445445
strbuf_realpath(&path, path_, 1);
446446
strbuf_addf(&dotgit, "%s/.git", path.buf);
447447
if (fspathcmp(wt->path, path.buf)) {
448-
write_worktree_linking_files(dotgit, gitdir, use_relative_paths);
448+
write_worktree_linking_files(dotgit.buf, gitdir.buf, use_relative_paths);
449449

450450
free(wt->path);
451451
wt->path = strbuf_detach(&path, NULL);
@@ -685,7 +685,7 @@ static void repair_gitfile(struct worktree *wt,
685685

686686
if (repair) {
687687
fn(0, wt->path, repair, cb_data);
688-
write_worktree_linking_files(dotgit, gitdir, use_relative_paths);
688+
write_worktree_linking_files(dotgit.buf, gitdir.buf, use_relative_paths);
689689
}
690690

691691
done:
@@ -743,7 +743,7 @@ void repair_worktree_after_gitdir_move(struct worktree *wt, const char *old_path
743743
if (!file_exists(dotgit.buf))
744744
goto done;
745745

746-
write_worktree_linking_files(dotgit, gitdir, is_relative_path);
746+
write_worktree_linking_files(dotgit.buf, gitdir.buf, is_relative_path);
747747
done:
748748
strbuf_release(&gitdir);
749749
strbuf_release(&dotgit);
@@ -915,7 +915,7 @@ void repair_worktree_at_path(const char *path,
915915

916916
if (repair) {
917917
fn(0, gitdir.buf, repair, cb_data);
918-
write_worktree_linking_files(dotgit, gitdir, use_relative_paths);
918+
write_worktree_linking_files(dotgit.buf, gitdir.buf, use_relative_paths);
919919
}
920920
done:
921921
free(dotgit_contents);
@@ -1089,17 +1089,17 @@ int init_worktree_config(struct repository *r)
10891089
return res;
10901090
}
10911091

1092-
void write_worktree_linking_files(struct strbuf dotgit, struct strbuf gitdir,
1092+
void write_worktree_linking_files(const char *dotgit, const char *gitdir,
10931093
int use_relative_paths)
10941094
{
10951095
struct strbuf path = STRBUF_INIT;
10961096
struct strbuf repo = STRBUF_INIT;
10971097
struct strbuf tmp = STRBUF_INIT;
10981098

1099-
strbuf_addbuf(&path, &dotgit);
1099+
strbuf_addstr(&path, dotgit);
11001100
strbuf_strip_suffix(&path, "/.git");
11011101
strbuf_realpath(&path, path.buf, 1);
1102-
strbuf_addbuf(&repo, &gitdir);
1102+
strbuf_addstr(&repo, gitdir);
11031103
strbuf_strip_suffix(&repo, "/gitdir");
11041104
strbuf_realpath(&repo, repo.buf, 1);
11051105

@@ -1112,11 +1112,11 @@ void write_worktree_linking_files(struct strbuf dotgit, struct strbuf gitdir,
11121112
}
11131113

11141114
if (use_relative_paths) {
1115-
write_file(gitdir.buf, "%s/.git", relative_path(path.buf, repo.buf, &tmp));
1116-
write_file(dotgit.buf, "gitdir: %s", relative_path(repo.buf, path.buf, &tmp));
1115+
write_file(gitdir, "%s/.git", relative_path(path.buf, repo.buf, &tmp));
1116+
write_file(dotgit, "gitdir: %s", relative_path(repo.buf, path.buf, &tmp));
11171117
} else {
1118-
write_file(gitdir.buf, "%s/.git", path.buf);
1119-
write_file(dotgit.buf, "gitdir: %s", repo.buf);
1118+
write_file(gitdir, "%s/.git", path.buf);
1119+
write_file(dotgit, "gitdir: %s", repo.buf);
11201120
}
11211121

11221122
strbuf_release(&path);

worktree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ int init_worktree_config(struct repository *r);
240240
* dotgit: "/path/to/foo/.git"
241241
* gitdir: "/path/to/repo/worktrees/foo/gitdir"
242242
*/
243-
void write_worktree_linking_files(struct strbuf dotgit, struct strbuf gitdir,
243+
void write_worktree_linking_files(const char *dotgit, const char *gitdir,
244244
int use_relative_paths);
245245

246246
#endif

0 commit comments

Comments
 (0)