| 1388 | } |
| 1389 | |
| 1390 | static int edit_hunk_loop(struct add_p_state *s, |
| 1391 | struct file_diff *file_diff, struct hunk *hunk) |
| 1392 | { |
| 1393 | size_t plain_len = s->plain.len, colored_len = s->colored.len; |
| 1394 | struct hunk backup; |
| 1395 | |
| 1396 | backup = *hunk; |
| 1397 | |
| 1398 | for (;;) { |
| 1399 | int res = edit_hunk_manually(s, hunk); |
| 1400 | if (res == 0) { |
| 1401 | /* abandoned */ |
| 1402 | *hunk = backup; |
| 1403 | return -1; |
| 1404 | } |
| 1405 | |
| 1406 | if (res > 0) { |
| 1407 | hunk->delta += |
| 1408 | recount_edited_hunk(s, hunk, |
| 1409 | backup.header.old_count, |
| 1410 | backup.header.new_count); |
| 1411 | if (!run_apply_check(s, file_diff)) |
| 1412 | return 0; |
| 1413 | } |
| 1414 | |
| 1415 | /* Drop edits (they were appended to s->plain) */ |
| 1416 | strbuf_setlen(&s->plain, plain_len); |
| 1417 | strbuf_setlen(&s->colored, colored_len); |
| 1418 | *hunk = backup; |
| 1419 | |
| 1420 | /* |
| 1421 | * TRANSLATORS: do not translate [y/n] |
| 1422 | * The program will only accept that input at this point. |
| 1423 | * Consider translating (saying "no" discards!) as |
| 1424 | * (saying "n" for "no" discards!) if the translation |
| 1425 | * of the word "no" does not start with n. |
| 1426 | */ |
| 1427 | res = prompt_yesno(s, _("Your edited hunk does not apply. " |
| 1428 | "Edit again (saying \"no\" discards!) " |
| 1429 | "[y/n]? ")); |
| 1430 | if (res < 1) |
| 1431 | return -1; |
| 1432 | } |
| 1433 | } |
| 1434 | |
| 1435 | static int apply_for_checkout(struct add_p_state *s, struct strbuf *diff, |
| 1436 | int is_reverse) |
no test coverage detected