built-in add -p: only show the applicable parts of the help text
When displaying the only hunk in a file's diff, the prompt already excludes the commands to navigate to the previous/next hunk. Let's also let the `?` command show only the help lines corresponding to the commands that are displayed in the prompt. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Dec 13, 2019 at 08:08 UTC
54d9d9b2eebe1c8f8b54626f98a5e1414ce766ba
1 file changed
+28
-4
add-patch.c
+28
-4
@@ -1008,8 +1008,10 @@ N_("y - stage this hunk\n"
1008
"n - do not stage this hunk\n"
1009
"q - quit; do not stage this hunk or any of the remaining ones\n"
1010
"a - stage this and all the remaining hunks\n"
1011
- "d - do not stage this hunk nor any of the remaining hunks\n"
1012
- "j - leave this hunk undecided, see next undecided hunk\n"
1011
+ "d - do not stage this hunk nor any of the remaining hunks\n");
1012
+
1013
+static const char help_patch_remainder[] =
1014
+N_("j - leave this hunk undecided, see next undecided hunk\n"
1015
"J - leave this hunk undecided, see next hunk\n"
1016
"k - leave this hunk undecided, see previous undecided hunk\n"
1017
"K - leave this hunk undecided, see previous hunk\n"
@@ -1246,9 +1248,31 @@ soft_increment:
1248
hunk->use = USE_HUNK;
1249
goto soft_increment;
1250
}
1249
- } else
1250
- color_fprintf(stdout, s->s.help_color,
1251
+ } else {
1252
+ const char *p = _(help_patch_remainder), *eol = p;
1253
+
1254
+ color_fprintf(stdout, s->s.help_color, "%s",
1255
_(help_patch_text));
1256
+
1257
+ /*
1258
+ * Show only those lines of the remainder that are
1259
+ * actually applicable with the current hunk.
1260
+ */
1261
+ for (; *p; p = eol + (*eol == '\n')) {
1262
+ eol = strchrnul(p, '\n');
1263
+
1264
+ /*
1265
+ * `s->buf` still contains the part of the
1266
+ * commands shown in the prompt that are not
1267
+ * always available.
1268
+ */
1269
+ if (*p != '?' && !strchr(s->buf.buf, *p))
1270
+ continue;
1271
+
1272
+ color_fprintf_ln(stdout, s->s.help_color,
1273
+ "%.*s", (int)(eol - p), p);
1274
+ }
1275
+ }
1276
}
1277
1278
/* Any hunk to be used? */