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

Function gi_add_pattern

src/discover/gitignore.c:176–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174/* ── Pattern parsing ─────────────────────────────────────────────── */
175
176static void gi_add_pattern(cbm_gitignore_t *gi, const char *line, int len) {
177 /* Trim trailing whitespace */
178 while (len > 0 && (line[len - SKIP_ONE] == ' ' || line[len - SKIP_ONE] == '\t' ||
179 line[len - SKIP_ONE] == '\r')) {
180 len--;
181 }
182 if (len == 0) {
183 return;
184 }
185
186 gi_pattern_t p = {0};
187
188 /* Check for negation */
189 const char *start = line;
190 if (*start == '!') {
191 p.negated = true;
192 start++;
193 len--;
194 }
195
196 if (len == 0) {
197 return;
198 }
199
200 /* Check for trailing / (directory-only) */
201 if (start[len - SKIP_ONE] == '/') {
202 p.dir_only = true;
203 len--;
204 }
205
206 if (len == 0) {
207 return;
208 }
209
210 /* Check for leading / (rooted) */
211 if (*start == '/') {
212 p.rooted = true;
213 start++;
214 len--;
215 }
216
217 if (len == 0) {
218 return;
219 }
220
221 /* Check if pattern contains / anywhere (makes it rooted) */
222 if (!p.rooted) {
223 for (int i = 0; i < len; i++) {
224 if (start[i] == '/') {
225 p.rooted = true;
226 break;
227 }
228 }
229 }
230
231 /* Copy pattern */
232 p.pattern = malloc(len + SKIP_ONE);
233 if (!p.pattern) {

Callers 1

cbm_gitignore_parseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected