Git fork

add-patch: let options a and d roll over like y and n

Options a and d stage and unstage all undecided hunks towards the bottom
of the array of hunks, respectively, and then roll over to the very
first hunk. The first part is similar to y and n if the current hunk is
the last one in the array, but they roll over to the next undecided
hunk if there is any. That's more useful; do it for a and d as well.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

René Scharfe and committed by
Junio C Hamano
e8c744dd 1967b606

+21 -6
+15
add-patch.c
··· 1418 1418 return a < m - 1 ? a + 1 : 0; 1419 1419 } 1420 1420 1421 + static bool get_first_undecided(const struct file_diff *file_diff, size_t *idx) 1422 + { 1423 + for (size_t i = 0; i < file_diff->hunk_nr; i++) { 1424 + if (file_diff->hunk[i].use == UNDECIDED_HUNK) { 1425 + *idx = i; 1426 + return true; 1427 + } 1428 + } 1429 + return false; 1430 + } 1431 + 1421 1432 static int patch_update_file(struct add_p_state *s, 1422 1433 struct file_diff *file_diff) 1423 1434 { ··· 1572 1583 if (hunk->use == UNDECIDED_HUNK) 1573 1584 hunk->use = USE_HUNK; 1574 1585 } 1586 + if (!get_first_undecided(file_diff, &hunk_index)) 1587 + hunk_index = 0; 1575 1588 } else if (hunk->use == UNDECIDED_HUNK) { 1576 1589 hunk->use = USE_HUNK; 1577 1590 } ··· 1582 1595 if (hunk->use == UNDECIDED_HUNK) 1583 1596 hunk->use = SKIP_HUNK; 1584 1597 } 1598 + if (!get_first_undecided(file_diff, &hunk_index)) 1599 + hunk_index = 0; 1585 1600 } else if (hunk->use == UNDECIDED_HUNK) { 1586 1601 hunk->use = SKIP_HUNK; 1587 1602 }
+6 -6
t/t3701-add-interactive.sh
··· 1364 1364 test_cmp expect actual 1365 1365 ' 1366 1366 1367 - test_expect_success 'options y, n, j, k, e roll over to next undecided (1)' ' 1367 + test_expect_success 'options y, n, a, d, j, k, e roll over to next undecided (1)' ' 1368 1368 test_write_lines a b c d e f g h i j k l m n o p q >file && 1369 1369 git add file && 1370 1370 test_write_lines X b c d e f g h X j k l m n o p X >file && 1371 1371 test_set_editor : && 1372 - test_write_lines g3 y g3 n g3 j g3 e k q | git add -p >out && 1373 - test_write_lines 1 3 1 3 1 3 1 3 1 2 >expect && 1372 + test_write_lines g3 y g3 n g3 a g3 d g3 j g3 e k q | git add -p >out && 1373 + test_write_lines 1 3 1 3 1 3 1 3 1 3 1 3 1 2 >expect && 1374 1374 sed -n -e "s-/.*--" -e "s/^(//p" <out >actual && 1375 1375 test_cmp expect actual 1376 1376 ' 1377 1377 1378 - test_expect_success 'options y, n, j, k, e roll over to next undecided (2)' ' 1378 + test_expect_success 'options y, n, a, d, j, k, e roll over to next undecided (2)' ' 1379 1379 test_write_lines a b c d e f g h i j k l m n o p q >file && 1380 1380 git add file && 1381 1381 test_write_lines X b c d e f g h X j k l m n o p X >file && 1382 1382 test_set_editor : && 1383 - test_write_lines y g3 y g3 n g3 j g3 e g1 k q | git add -p >out && 1384 - test_write_lines 1 2 3 2 3 2 3 2 3 2 1 2 >expect && 1383 + test_write_lines y g3 y g3 n g3 a g3 d g3 j g3 e g1 k q | git add -p >out && 1384 + test_write_lines 1 2 3 2 3 2 3 2 3 2 3 2 3 2 1 2 >expect && 1385 1385 sed -n -e "s-/.*--" -e "s/^(//p" <out >actual && 1386 1386 test_cmp expect actual 1387 1387 '