diff options
| author | Junio C Hamano <gitster@pobox.com> | 2025-08-21 13:47:00 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-08-21 13:47:00 -0700 |
| commit | 54fef16542ef1d83b4b99d9b5e9ffd19e1942517 (patch) | |
| tree | 86359eb57d6ea330d34b15e8ed81dcbcfc17c4b7 /environment.c | |
| parent | Merge branch 'jc/string-list-split' (diff) | |
| parent | trace2: do not use strbuf_split*() (diff) | |
| download | git-54fef16542ef1d83b4b99d9b5e9ffd19e1942517.tar.gz git-54fef16542ef1d83b4b99d9b5e9ffd19e1942517.zip | |
Merge branch 'jc/strbuf-split'
Arrays of strbuf is often a wrong data structure to use, and
strbuf_split*() family of functions that create them often have
better alternatives.
Update several code paths and replace strbuf_split*().
* jc/strbuf-split:
trace2: do not use strbuf_split*()
trace2: trim_trailing_newline followed by trim is a no-op
sub-process: do not use strbuf_split*()
environment: do not use strbuf_split*()
config: do not use strbuf_split()
notes: do not use strbuf_split*()
merge-tree: do not use strbuf_split*()
clean: do not use strbuf_split*() [part 2]
clean: do not pass the whole structure when it is not necessary
clean: do not use strbuf_split*() [part 1]
clean: do not pass strbuf by value
wt-status: avoid strbuf_split*()
Diffstat (limited to 'environment.c')
| -rw-r--r-- | environment.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/environment.c b/environment.c index ae1427bb9e..59040e2d0f 100644 --- a/environment.c +++ b/environment.c @@ -175,10 +175,10 @@ int have_git_dir(void) const char *get_git_namespace(void) { static const char *namespace; - struct strbuf buf = STRBUF_INIT; - struct strbuf **components, **c; const char *raw_namespace; + struct string_list components = STRING_LIST_INIT_DUP; + struct string_list_item *item; if (namespace) return namespace; @@ -190,12 +190,17 @@ const char *get_git_namespace(void) } strbuf_addstr(&buf, raw_namespace); - components = strbuf_split(&buf, '/'); + + string_list_split(&components, buf.buf, "/", -1); strbuf_reset(&buf); - for (c = components; *c; c++) - if (strcmp((*c)->buf, "/") != 0) - strbuf_addf(&buf, "refs/namespaces/%s", (*c)->buf); - strbuf_list_free(components); + + for_each_string_list_item(item, &components) { + if (item->string[0]) + strbuf_addf(&buf, "refs/namespaces/%s/", item->string); + } + string_list_clear(&components, 0); + + strbuf_trim_trailing_dir_sep(&buf); if (check_refname_format(buf.buf, 0)) die(_("bad git namespace path \"%s\""), raw_namespace); strbuf_addch(&buf, '/'); |
