Git fork

environment: do not use strbuf_split*()

environment.c:get_git_namespace() learns the raw namespace from an
environment variable, splits it at "/", and appends them after
"refs/namespaces/"; the reason why it splits first is so that an
empty string resulting from double slashes can be omitted.

The split pieces do not need to be edited in any way, so an array of
strbufs is a wrong data structure to use. Instead split into a
string list and use the pieces from there.

Signed-off-by: Junio C Hamano <gitster@pobox.com>

+12 -7
+12 -7
environment.c
··· 163 163 const char *get_git_namespace(void) 164 164 { 165 165 static const char *namespace; 166 - 167 166 struct strbuf buf = STRBUF_INIT; 168 - struct strbuf **components, **c; 169 167 const char *raw_namespace; 168 + struct string_list components = STRING_LIST_INIT_DUP; 169 + struct string_list_item *item; 170 170 171 171 if (namespace) 172 172 return namespace; ··· 178 178 } 179 179 180 180 strbuf_addstr(&buf, raw_namespace); 181 - components = strbuf_split(&buf, '/'); 181 + 182 + string_list_split(&components, buf.buf, "/", -1); 182 183 strbuf_reset(&buf); 183 - for (c = components; *c; c++) 184 - if (strcmp((*c)->buf, "/") != 0) 185 - strbuf_addf(&buf, "refs/namespaces/%s", (*c)->buf); 186 - strbuf_list_free(components); 184 + 185 + for_each_string_list_item(item, &components) { 186 + if (item->string[0]) 187 + strbuf_addf(&buf, "refs/namespaces/%s/", item->string); 188 + } 189 + string_list_clear(&components, 0); 190 + 191 + strbuf_trim_trailing_dir_sep(&buf); 187 192 if (check_refname_format(buf.buf, 0)) 188 193 die(_("bad git namespace path \"%s\""), raw_namespace); 189 194 strbuf_addch(&buf, '/');