MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / slug_from_branch

Function slug_from_branch

src/git/git_context.c:214–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

212}
213
214static char *slug_from_branch(const char *branch, bool detached) {
215 const char *fallback = detached ? "detached" : "working-tree";
216 const char *src = detached ? fallback : (branch && branch[0] ? branch : fallback);
217 size_t len = strlen(src);
218 char *slug = (char *)malloc(len + 1);
219 if (!slug) {
220 return NULL;
221 }
222
223 size_t j = 0;
224 bool in_dash = false;
225 for (size_t i = 0; i < len; i++) {
226 unsigned char c = (unsigned char)src[i];
227 if (isalnum(c) || c == '-' || c == '_' || c == '.') {
228 if (j == 0 && c == '-') {
229 in_dash = true;
230 continue;
231 }
232 slug[j++] = (char)c;
233 in_dash = false;
234 } else if (j > 0 && !in_dash) {
235 slug[j++] = '-';
236 in_dash = true;
237 }
238 }
239 while (j > 0 && slug[j - 1] == '-') {
240 j--;
241 }
242 slug[j] = '\0';
243
244 if (slug[0] == '\0') {
245 free(slug);
246 return git_strdup(fallback);
247 }
248 return slug;
249}
250
251void cbm_git_context_free(cbm_git_context_t *ctx) {
252 if (!ctx) {

Callers 1

cbm_git_context_resolveFunction · 0.85

Calls 1

git_strdupFunction · 0.85

Tested by

no test coverage detected