| 1241 | } |
| 1242 | |
| 1243 | static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk) |
| 1244 | { |
| 1245 | size_t i; |
| 1246 | |
| 1247 | strbuf_reset(&s->buf); |
| 1248 | strbuf_commented_addf(&s->buf, comment_line_str, |
| 1249 | _("Manual hunk edit mode -- see bottom for " |
| 1250 | "a quick guide.\n")); |
| 1251 | render_hunk(s, hunk, 0, 0, &s->buf); |
| 1252 | strbuf_commented_addf(&s->buf, comment_line_str, |
| 1253 | _("---\n" |
| 1254 | "To remove '%c' lines, make them ' ' lines " |
| 1255 | "(context).\n" |
| 1256 | "To remove '%c' lines, delete them.\n" |
| 1257 | "Lines starting with %s will be removed.\n"), |
| 1258 | s->mode->is_reverse ? '+' : '-', |
| 1259 | s->mode->is_reverse ? '-' : '+', |
| 1260 | comment_line_str); |
| 1261 | strbuf_commented_addf(&s->buf, comment_line_str, "%s", |
| 1262 | _(s->mode->edit_hunk_hint)); |
| 1263 | /* |
| 1264 | * TRANSLATORS: 'it' refers to the patch mentioned in the previous |
| 1265 | * messages. |
| 1266 | */ |
| 1267 | strbuf_commented_addf(&s->buf, comment_line_str, |
| 1268 | _("If it does not apply cleanly, you will be " |
| 1269 | "given an opportunity to\n" |
| 1270 | "edit again. If all lines of the hunk are " |
| 1271 | "removed, then the edit is\n" |
| 1272 | "aborted and the hunk is left unchanged.\n")); |
| 1273 | |
| 1274 | if (strbuf_edit_interactively(s->r, &s->buf, |
| 1275 | "addp-hunk-edit.diff", NULL) < 0) |
| 1276 | return -1; |
| 1277 | |
| 1278 | /* strip out commented lines */ |
| 1279 | hunk->start = s->plain.len; |
| 1280 | for (i = 0; i < s->buf.len; ) { |
| 1281 | size_t next = find_next_line(&s->buf, i); |
| 1282 | |
| 1283 | if (!starts_with(s->buf.buf + i, comment_line_str)) |
| 1284 | strbuf_add(&s->plain, s->buf.buf + i, next - i); |
| 1285 | i = next; |
| 1286 | } |
| 1287 | |
| 1288 | hunk->end = s->plain.len; |
| 1289 | if (hunk->end == hunk->start) |
| 1290 | /* The user aborted editing by deleting everything */ |
| 1291 | return 0; |
| 1292 | |
| 1293 | recolor_hunk(s, hunk); |
| 1294 | |
| 1295 | /* |
| 1296 | * If the hunk header is intact, parse it, otherwise simply use the |
| 1297 | * hunk header prior to editing (which will adjust `hunk->start` to |
| 1298 | * skip the hunk header). |
| 1299 | */ |
| 1300 | if (s->plain.buf[hunk->start] == '@' && |
no test coverage detected