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

Function df_read

src/mcp/test_impact_diff.c:268–323  ·  view source on GitHub ↗

false = out of memory. */

Source from the content-addressed store, hash-verified

266
267/* false = out of memory. */
268static bool df_read(cbm_diff_t *d, df_reader_t *rd) {
269 cbm_diff_file_t *file = NULL;
270 df_hunks_t hunks = {0};
271 bool in_hunks = false; /* past the file's header lines */
272 df_line_t line;
273 while (df_next_line(rd, &line)) {
274 if (df_starts(&line, "diff ")) {
275 if (file) {
276 file->hunks = hunks.items;
277 file->hunk_count = hunks.count;
278 }
279 hunks = (df_hunks_t){0};
280 in_hunks = false;
281 file = NULL;
282 const char *path = df_header_path(d, &line);
283 if (!path) {
284 d->complete = false; /* a header this reader does not read */
285 continue;
286 }
287 file = df_add_file(d, path);
288 if (!file) {
289 return false;
290 }
291 continue;
292 }
293 int old_count = 0;
294 int new_start = 0;
295 int new_count = 0;
296 if (file && df_hunk_header(&line, &old_count, &new_start, &new_count)) {
297 in_hunks = true;
298 cbm_diff_hunk_t *hunk = df_add_hunk(d, &hunks);
299 if (!hunk) {
300 return false;
301 }
302 hunk->start = new_start;
303 hunk->count = new_count;
304 df_status_t status = df_hunk_body(d, rd, hunk, old_count, new_count);
305 if (status == DF_NO_MEMORY) {
306 return false;
307 }
308 d->complete = d->complete && status == DF_OK;
309 continue;
310 }
311 if (line.len == 0 && !file) {
312 continue; /* blank lines around the diff */
313 }
314 if (!file || in_hunks || !df_file_header_line(&line, file)) {
315 d->complete = false;
316 }
317 }
318 if (file) {
319 file->hunks = hunks.items;
320 file->hunk_count = hunks.count;
321 }
322 return true;
323}
324
325cbm_diff_t *cbm_diff_parse(const char *text, size_t len) {

Callers 1

cbm_diff_parseFunction · 0.85

Calls 8

df_next_lineFunction · 0.85
df_startsFunction · 0.85
df_header_pathFunction · 0.85
df_add_fileFunction · 0.85
df_hunk_headerFunction · 0.85
df_add_hunkFunction · 0.85
df_hunk_bodyFunction · 0.85
df_file_header_lineFunction · 0.85

Tested by

no test coverage detected