From: "Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>,
Phillip Wood <phillip.wood123@gmail.com>,
Phillip Wood <phillip.wood@dunelm.org.uk>
Subject: [PATCH v2 0/2] add-patch: handle splitting hunks with diff.suppressBlankEmpty
Date: Sat, 20 Jul 2024 16:01:58 +0000 [thread overview]
Message-ID: <pull.1763.v2.git.1721491320.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1763.git.1721312619822.gitgitgadget@gmail.com>
This is an alternative to jk/add-patch-with-suppress-blank-empty which was
recently discarded from next. I hope that normalizing the context marker
will simplify any future changes to the code.
Changes since V1
* Updated merge_hunks() to use normalize_marker() as spotted by Junio
* Updated the test so it checks merge_hunks() as well.
Phillip Wood (2):
add-patch: handle splitting hunks with diff.suppressBlankEmpty
add-patch: use normalize_marker() when recounting edited hunk
add-patch.c | 23 +++++++++++++++--------
t/t3701-add-interactive.sh | 19 +++++++++++++++++++
2 files changed, 34 insertions(+), 8 deletions(-)
base-commit: 790a17fb19d6eadd16c52e5d284a5c6921744766
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1763%2Fphillipwood%2Fadd-p-suppress-blank-empty-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1763/phillipwood/add-p-suppress-blank-empty-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1763
Range-diff vs v1:
1: fd09e66727a ! 1: 34d8fd44a97 add-patch: handle splitting hunks with diff.suppressBlankEmpty
@@ add-patch.c: static void complete_file(char marker, struct hunk *hunk)
}
+/* Empty context lines may omit the leading ' ' */
-+static int normalize_marker(char *p)
++static int normalize_marker(const char *p)
+{
+ return p[0] == '\n' || (p[0] == '\r' && p[1] == '\n') ? ' ' : p[0];
+}
@@ add-patch.c: static int parse_diff(struct add_p_state *s, const struct pathspec
p = eol == pend ? pend : eol + 1;
hunk->end = p - plain->buf;
+@@ add-patch.c: static int merge_hunks(struct add_p_state *s, struct file_diff *file_diff,
+ (int)(hunk->end - hunk->start),
+ plain + hunk->start);
+
+- if (plain[overlap_end] != ' ')
++ if (normalize_marker(&plain[overlap_end]) != ' ')
+ return error(_("expected context line "
+ "#%d in\n%.*s"),
+ (int)(j + 1),
@@ add-patch.c: static int split_hunk(struct add_p_state *s, struct file_diff *file_diff,
context_line_count = 0;
while (splittable_into > 1) {
- ch = s->plain.buf[current];
-+ ch = normalize_marker(s->plain.buf + current);
++ ch = normalize_marker(&s->plain.buf[current]);
if (!ch)
BUG("buffer overrun while splitting hunks");
@@ t/t3701-add-interactive.sh: test_expect_success 'reset -p with unmerged files' '
+test_expect_success 'hunk splitting works with diff.suppressBlankEmpty' '
+ test_config diff.suppressBlankEmpty true &&
-+ test_write_lines a b c "" d e f >file &&
++ write_script fake-editor.sh <<-\EOF &&
++ tr F G <"$1" >"$1.tmp" &&
++ mv "$1.tmp" "$1"
++ EOF
++
++ test_write_lines a b "" c d "" e f "" >file &&
+ git add file &&
-+ test_write_lines p q r "" s t u >file &&
-+ test_write_lines s n y q | git add -p &&
++ test_write_lines A b "" c D "" e F "" >file &&
++ (
++ test_set_editor "$(pwd)/fake-editor.sh" &&
++ test_write_lines s n y e q | git add -p file
++ ) &&
+ git cat-file blob :file >actual &&
-+ test_write_lines a b c "" s t u >expect &&
++ test_write_lines a b "" c D "" e G "" >expect &&
+ test_cmp expect actual
+'
+
-: ----------- > 2: 7bdcd2df012 add-patch: use normalize_marker() when recounting edited hunk
--
gitgitgadget
next prev parent reply other threads:[~2024-07-20 16:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-18 14:23 [PATCH] add-patch: handle splitting hunks with diff.suppressBlankEmpty Phillip Wood via GitGitGadget
2024-07-18 16:29 ` Junio C Hamano
2024-07-19 15:17 ` Phillip Wood
2024-07-20 16:01 ` Phillip Wood via GitGitGadget [this message]
2024-07-20 16:01 ` [PATCH v2 1/2] " Phillip Wood via GitGitGadget
2024-07-20 16:02 ` [PATCH v2 2/2] add-patch: use normalize_marker() when recounting edited hunk Phillip Wood via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.1763.v2.git.1721491320.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
--cc=phillip.wood123@gmail.com \
--cc=phillip.wood@dunelm.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).