| 141 | } |
| 142 | |
| 143 | const char *get_git_namespace(void) |
| 144 | { |
| 145 | static const char *namespace; |
| 146 | struct strbuf buf = STRBUF_INIT; |
| 147 | const char *raw_namespace; |
| 148 | struct string_list components = STRING_LIST_INIT_DUP; |
| 149 | struct string_list_item *item; |
| 150 | |
| 151 | if (namespace) |
| 152 | return namespace; |
| 153 | |
| 154 | raw_namespace = getenv(GIT_NAMESPACE_ENVIRONMENT); |
| 155 | if (!raw_namespace || !*raw_namespace) { |
| 156 | namespace = ""; |
| 157 | return namespace; |
| 158 | } |
| 159 | |
| 160 | strbuf_addstr(&buf, raw_namespace); |
| 161 | |
| 162 | string_list_split(&components, buf.buf, "/", -1); |
| 163 | strbuf_reset(&buf); |
| 164 | |
| 165 | for_each_string_list_item(item, &components) { |
| 166 | if (item->string[0]) |
| 167 | strbuf_addf(&buf, "refs/namespaces/%s/", item->string); |
| 168 | } |
| 169 | string_list_clear(&components, 0); |
| 170 | |
| 171 | strbuf_trim_trailing_dir_sep(&buf); |
| 172 | if (check_refname_format(buf.buf, 0)) |
| 173 | die(_("bad git namespace path \"%s\""), raw_namespace); |
| 174 | strbuf_addch(&buf, '/'); |
| 175 | |
| 176 | namespace = strbuf_detach(&buf, NULL); |
| 177 | |
| 178 | return namespace; |
| 179 | } |
| 180 | |
| 181 | const char *strip_namespace(const char *namespaced_ref) |
| 182 | { |
no test coverage detected