summaryrefslogtreecommitdiff
path: root/add-patch.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2019-12-13 08:07:53 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-12-13 20:37:13 (GMT)
commit7584dd3c66012e327f9cd7589d4f95ab2373cd47 (patch)
treef7b8c7f65351426883b3f524639ed5e3b9f8571b /add-patch.c
parent12c24cf850d280dd08dfe7361603b7089007fe3a (diff)
downloadgit-7584dd3c66012e327f9cd7589d4f95ab2373cd47.zip
git-7584dd3c66012e327f9cd7589d4f95ab2373cd47.tar.gz
git-7584dd3c66012e327f9cd7589d4f95ab2373cd47.tar.bz2
built-in add -p: offer a helpful error message when hunk navigation failed
... just like the Perl version currently does... Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'add-patch.c')
-rw-r--r--add-patch.c44
1 files changed, 33 insertions, 11 deletions
diff --git a/add-patch.c b/add-patch.c
index dab2ff2..f59471c 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -34,6 +34,18 @@ struct add_p_state {
size_t hunk_nr, hunk_alloc;
};
+static void err(struct add_p_state *s, const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ fputs(s->s.error_color, stderr);
+ vfprintf(stderr, fmt, args);
+ fputs(s->s.reset_color, stderr);
+ fputc('\n', stderr);
+ va_end(args);
+}
+
static void setup_child_process(struct add_p_state *s,
struct child_process *cp, ...)
{
@@ -368,17 +380,27 @@ soft_increment:
if (hunk->use == UNDECIDED_HUNK)
hunk->use = SKIP_HUNK;
}
- } else if (hunk_index && s->answer.buf[0] == 'K')
- hunk_index--;
- else if (hunk_index + 1 < s->hunk_nr &&
- s->answer.buf[0] == 'J')
- hunk_index++;
- else if (undecided_previous >= 0 &&
- s->answer.buf[0] == 'k')
- hunk_index = undecided_previous;
- else if (undecided_next >= 0 && s->answer.buf[0] == 'j')
- hunk_index = undecided_next;
- else
+ } else if (s->answer.buf[0] == 'K') {
+ if (hunk_index)
+ hunk_index--;
+ else
+ err(s, _("No previous hunk"));
+ } else if (s->answer.buf[0] == 'J') {
+ if (hunk_index + 1 < s->hunk_nr)
+ hunk_index++;
+ else
+ err(s, _("No next hunk"));
+ } else if (s->answer.buf[0] == 'k') {
+ if (undecided_previous >= 0)
+ hunk_index = undecided_previous;
+ else
+ err(s, _("No previous hunk"));
+ } else if (s->answer.buf[0] == 'j') {
+ if (undecided_next >= 0)
+ hunk_index = undecided_next;
+ else
+ err(s, _("No next hunk"));
+ } else
color_fprintf(stdout, s->s.help_color,
_(help_patch_text));
}