| 323 | } |
| 324 | |
| 325 | cbm_diff_t *cbm_diff_parse(const char *text, size_t len) { |
| 326 | if (!text && len > 0) { |
| 327 | return NULL; |
| 328 | } |
| 329 | CBMArena arena; |
| 330 | cbm_arena_init_sized(&arena, DF_ARENA_BLOCK); |
| 331 | cbm_diff_t *d = cbm_arena_calloc(&arena, sizeof(*d)); |
| 332 | if (!d) { |
| 333 | cbm_arena_destroy(&arena); |
| 334 | return NULL; |
| 335 | } |
| 336 | d->arena = arena; /* the diff lives in its own arena */ |
| 337 | d->complete = true; |
| 338 | df_reader_t rd = {.p = text, .end = text ? text + len : text}; |
| 339 | if (!df_read(d, &rd)) { |
| 340 | cbm_diff_free(d); |
| 341 | return NULL; |
| 342 | } |
| 343 | if (d->file_count > 1) { |
| 344 | qsort(d->files, (size_t)d->file_count, sizeof(*d->files), df_cmp_file); |
| 345 | } |
| 346 | return d; |
| 347 | } |
| 348 | |
| 349 | void cbm_diff_free(cbm_diff_t *d) { |
| 350 | if (!d) { |
no test coverage detected