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

Function gi_add_pattern

src/discover/gitignore.c:203–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

201/* ── Pattern parsing ─────────────────────────────────────────────── */
202
203static void gi_add_pattern(cbm_gitignore_t *gi, const char *line, int len) {
204 /* Trim trailing whitespace */
205 while (len > 0 && (line[len - SKIP_ONE] == ' ' || line[len - SKIP_ONE] == '\t' ||
206 line[len - SKIP_ONE] == '\r')) {
207 len--;
208 }
209 if (len == 0) {
210 return;
211 }
212
213 gi_pattern_t p = {0};
214
215 /* Check for negation */
216 const char *start = line;
217 if (*start == '!') {
218 p.negated = true;
219 start++;
220 len--;
221 }
222
223 if (len == 0) {
224 return;
225 }
226
227 /* Check for trailing / (directory-only) */
228 if (start[len - SKIP_ONE] == '/') {
229 p.dir_only = true;
230 len--;
231 }
232
233 if (len == 0) {
234 return;
235 }
236
237 /* Check for leading / (rooted) */
238 if (*start == '/') {
239 p.rooted = true;
240 start++;
241 len--;
242 }
243
244 if (len == 0) {
245 return;
246 }
247
248 /* Check if pattern contains / anywhere (makes it rooted) */
249 if (!p.rooted) {
250 for (int i = 0; i < len; i++) {
251 if (start[i] == '/') {
252 p.rooted = true;
253 break;
254 }
255 }
256 }
257
258 /* Copy pattern */
259 p.pattern = malloc(len + SKIP_ONE);
260 if (!p.pattern) {

Callers 1

cbm_gitignore_parseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected