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 const char *get_git_namespace(void) 164 { 165 static const char *namespace; 166 - 167 struct strbuf buf = STRBUF_INIT; 168 - struct strbuf **components, **c; 169 const char *raw_namespace; 170 171 if (namespace) 172 return namespace; ··· 178 } 179 180 strbuf_addstr(&buf, raw_namespace); 181 - components = strbuf_split(&buf, '/'); 182 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); 187 if (check_refname_format(buf.buf, 0)) 188 die(_("bad git namespace path \"%s\""), raw_namespace); 189 strbuf_addch(&buf, '/');
··· 163 const char *get_git_namespace(void) 164 { 165 static const char *namespace; 166 struct strbuf buf = STRBUF_INIT; 167 const char *raw_namespace; 168 + struct string_list components = STRING_LIST_INIT_DUP; 169 + struct string_list_item *item; 170 171 if (namespace) 172 return namespace; ··· 178 } 179 180 strbuf_addstr(&buf, raw_namespace); 181 + 182 + string_list_split(&components, buf.buf, "/", -1); 183 strbuf_reset(&buf); 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); 192 if (check_refname_format(buf.buf, 0)) 193 die(_("bad git namespace path \"%s\""), raw_namespace); 194 strbuf_addch(&buf, '/');