* Scan the path for conflicts, do the "handle_path()" thing above, and * return the number of conflict hunks found. */
| 466 | * return the number of conflict hunks found. |
| 467 | */ |
| 468 | static int handle_file(struct index_state *istate, |
| 469 | const char *path, unsigned char *hash, const char *output) |
| 470 | { |
| 471 | int has_conflicts = 0; |
| 472 | struct rerere_io_file io; |
| 473 | int marker_size = ll_merge_marker_size(istate, path); |
| 474 | |
| 475 | memset(&io, 0, sizeof(io)); |
| 476 | io.io.getline = rerere_file_getline; |
| 477 | io.input = fopen(path, "r"); |
| 478 | io.io.wrerror = 0; |
| 479 | if (!io.input) |
| 480 | return error_errno(_("could not open '%s'"), path); |
| 481 | |
| 482 | if (output) { |
| 483 | io.io.output = fopen(output, "w"); |
| 484 | if (!io.io.output) { |
| 485 | error_errno(_("could not write '%s'"), output); |
| 486 | fclose(io.input); |
| 487 | return -1; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | has_conflicts = handle_path(hash, (struct rerere_io *)&io, marker_size); |
| 492 | |
| 493 | fclose(io.input); |
| 494 | if (io.io.wrerror) |
| 495 | error(_("there were errors while writing '%s' (%s)"), |
| 496 | path, strerror(io.io.wrerror)); |
| 497 | if (io.io.output && fclose(io.io.output)) |
| 498 | io.io.wrerror = error_errno(_("failed to flush '%s'"), path); |
| 499 | |
| 500 | if (has_conflicts < 0) { |
| 501 | if (output) |
| 502 | unlink_or_warn(output); |
| 503 | return error(_("could not parse conflict hunks in '%s'"), path); |
| 504 | } |
| 505 | if (io.io.wrerror) |
| 506 | return -1; |
| 507 | return has_conflicts; |
| 508 | } |
| 509 | |
| 510 | /* |
| 511 | * Look at a cache entry at "i" and see if it is not conflicting, |
no test coverage detected