mirror of
https://github.com/git/git.git
synced 2026-01-10 10:13:33 +00:00
add-patch: let options y, n, j, and e roll over to next undecided
The options y, n, and e mark the current hunk as decided. If there's another undecided hunk towards the bottom of the hunk array they go there. If there isn't, but there is another undecided hunk towards the top then they go to the very first hunk, no matter if it has already been decided on. The option j does basically the same move. Technically it is not allowed if there's no undecided hunk towards the bottom, but the variable "permitted" is never reset, so this permission is retained from the very first hunk. That may a bug, but this behavior is at least consistent with y, n, and e and arguably more useful than refusing to move. Improve the roll-over behavior of these four options by moving to the first undecided hunk instead of hunk 1, consistent with what they do when not rolling over. Also adjust the error message for j, as it will only be shown if there's no other undecided hunk in either direction. Reported-by: Windl, Ulrich <u.windl@ukr.de> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
c309b65a7c
commit
171c1688cc
@@ -342,7 +342,7 @@ patch::
|
|||||||
d - do not stage this hunk or any of the later hunks in the file
|
d - do not stage this hunk or any of the later hunks in the file
|
||||||
g - select a hunk to go to
|
g - select a hunk to go to
|
||||||
/ - search for a hunk matching the given regex
|
/ - search for a hunk matching the given regex
|
||||||
j - go to the next undecided hunk
|
j - go to the next undecided hunk, roll over at the bottom
|
||||||
J - go to the next hunk, roll over at the bottom
|
J - go to the next hunk, roll over at the bottom
|
||||||
k - go to the previous undecided hunk
|
k - go to the previous undecided hunk
|
||||||
K - go to the previous hunk
|
K - go to the previous hunk
|
||||||
|
|||||||
13
add-patch.c
13
add-patch.c
@@ -1397,7 +1397,7 @@ static size_t display_hunks(struct add_p_state *s,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const char help_patch_remainder[] =
|
static const char help_patch_remainder[] =
|
||||||
N_("j - go to the next undecided hunk\n"
|
N_("j - go to the next undecided hunk, roll over at the bottom\n"
|
||||||
"J - go to the next hunk, roll over at the bottom\n"
|
"J - go to the next hunk, roll over at the bottom\n"
|
||||||
"k - go to the previous undecided hunk\n"
|
"k - go to the previous undecided hunk\n"
|
||||||
"K - go to the previous hunk\n"
|
"K - go to the previous hunk\n"
|
||||||
@@ -1408,6 +1408,11 @@ N_("j - go to the next undecided hunk\n"
|
|||||||
"p - print the current hunk, 'P' to use the pager\n"
|
"p - print the current hunk, 'P' to use the pager\n"
|
||||||
"? - print help\n");
|
"? - print help\n");
|
||||||
|
|
||||||
|
static size_t inc_mod(size_t a, size_t m)
|
||||||
|
{
|
||||||
|
return a < m - 1 ? a + 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int patch_update_file(struct add_p_state *s,
|
static int patch_update_file(struct add_p_state *s,
|
||||||
struct file_diff *file_diff)
|
struct file_diff *file_diff)
|
||||||
{
|
{
|
||||||
@@ -1451,7 +1456,9 @@ static int patch_update_file(struct add_p_state *s,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = hunk_index + 1; i < file_diff->hunk_nr; i++)
|
for (i = inc_mod(hunk_index, file_diff->hunk_nr);
|
||||||
|
i != hunk_index;
|
||||||
|
i = inc_mod(i, file_diff->hunk_nr))
|
||||||
if (file_diff->hunk[i].use == UNDECIDED_HUNK) {
|
if (file_diff->hunk[i].use == UNDECIDED_HUNK) {
|
||||||
undecided_next = i;
|
undecided_next = i;
|
||||||
break;
|
break;
|
||||||
@@ -1594,7 +1601,7 @@ soft_increment:
|
|||||||
if (permitted & ALLOW_GOTO_NEXT_UNDECIDED_HUNK)
|
if (permitted & ALLOW_GOTO_NEXT_UNDECIDED_HUNK)
|
||||||
hunk_index = undecided_next;
|
hunk_index = undecided_next;
|
||||||
else
|
else
|
||||||
err(s, _("No next hunk"));
|
err(s, _("No other undecided hunk"));
|
||||||
} else if (s->answer.buf[0] == 'g') {
|
} else if (s->answer.buf[0] == 'g') {
|
||||||
char *pend;
|
char *pend;
|
||||||
unsigned long response;
|
unsigned long response;
|
||||||
|
|||||||
@@ -1364,4 +1364,26 @@ test_expect_success 'option J rolls over' '
|
|||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'options y, n, j, e roll over to next undecided (1)' '
|
||||||
|
test_write_lines a b c d e f g h i j k l m n o p q >file &&
|
||||||
|
git add file &&
|
||||||
|
test_write_lines X b c d e f g h X j k l m n o p X >file &&
|
||||||
|
test_set_editor : &&
|
||||||
|
test_write_lines g3 y g3 n g3 j g3 e q | git add -p >out &&
|
||||||
|
test_write_lines 1 3 1 3 1 3 1 3 1 >expect &&
|
||||||
|
sed -n -e "s-/.*--" -e "s/^(//p" <out >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'options y, n, j, e roll over to next undecided (2)' '
|
||||||
|
test_write_lines a b c d e f g h i j k l m n o p q >file &&
|
||||||
|
git add file &&
|
||||||
|
test_write_lines X b c d e f g h X j k l m n o p X >file &&
|
||||||
|
test_set_editor : &&
|
||||||
|
test_write_lines y g3 y g3 n g3 j g3 e q | git add -p >out &&
|
||||||
|
test_write_lines 1 2 3 2 3 2 3 2 3 2 >expect &&
|
||||||
|
sed -n -e "s-/.*--" -e "s/^(//p" <out >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|||||||
Reference in New Issue
Block a user