Skip to content

Commit e8c744d

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1967b60 commit e8c744d

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

add-patch.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,17 @@ static size_t inc_mod(size_t a, size_t m)
14181418
return a < m - 1 ? a + 1 : 0;
14191419
}
14201420

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+
14211432
static int patch_update_file(struct add_p_state *s,
14221433
struct file_diff *file_diff)
14231434
{
@@ -1572,6 +1583,8 @@ static int patch_update_file(struct add_p_state *s,
15721583
if (hunk->use == UNDECIDED_HUNK)
15731584
hunk->use = USE_HUNK;
15741585
}
1586+
if (!get_first_undecided(file_diff, &hunk_index))
1587+
hunk_index = 0;
15751588
} else if (hunk->use == UNDECIDED_HUNK) {
15761589
hunk->use = USE_HUNK;
15771590
}
@@ -1582,6 +1595,8 @@ static int patch_update_file(struct add_p_state *s,
15821595
if (hunk->use == UNDECIDED_HUNK)
15831596
hunk->use = SKIP_HUNK;
15841597
}
1598+
if (!get_first_undecided(file_diff, &hunk_index))
1599+
hunk_index = 0;
15851600
} else if (hunk->use == UNDECIDED_HUNK) {
15861601
hunk->use = SKIP_HUNK;
15871602
}

t/t3701-add-interactive.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,24 +1364,24 @@ test_expect_success 'options J, K roll over' '
13641364
test_cmp expect actual
13651365
'
13661366

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)' '
13681368
test_write_lines a b c d e f g h i j k l m n o p q >file &&
13691369
git add file &&
13701370
test_write_lines X b c d e f g h X j k l m n o p X >file &&
13711371
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 &&
13741374
sed -n -e "s-/.*--" -e "s/^(//p" <out >actual &&
13751375
test_cmp expect actual
13761376
'
13771377

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)' '
13791379
test_write_lines a b c d e f g h i j k l m n o p q >file &&
13801380
git add file &&
13811381
test_write_lines X b c d e f g h X j k l m n o p X >file &&
13821382
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 &&
13851385
sed -n -e "s-/.*--" -e "s/^(//p" <out >actual &&
13861386
test_cmp expect actual
13871387
'

0 commit comments

Comments
 (0)