git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 0/2] add -p: a couple of hunk splitting fixes

From
PGPhillip Wood via GitGitGadget <gitgitgadget@gmail.com>
Date
Sep 25, 2025, 15:10 UTC
Message-ID
<pull.1863.v3.git.1758813038.gitgitgadget@gmail.com>
In-Reply-To
<pull.1863.v2.git.1757950144.gitgitgadget@gmail.com>

Thanks to Junio for his comments on V2. I have removed the dependency on WITH_BREAKING_CHANGES in favor of "lets change it and see if anyone screams"

Changes since V2: Remove dependency on WITH_BREAKING_CHANGES and change the behavior unconditionally. This takes us back to V1 with (hopefully) better commit messages and a style fix in the tests.

V2 Cover Letter: Thanks to Justin and Junio for their comments in V1. Sorry for the long delay in re-rolling - I thought I'd sent these ages ago and then discovered that they weren't upstream and realized I had not, in fact, sent them after-all.

Changes since V1:
 * Patch 1: The new hunks created by splitting a hunk are now only marked as
   "undecided" when WITH_BREAKING_CHANGES is enabled.
 * Patch 2: Reworded commit message and added a space before a redirection
   in the test
V1 Cover Letter:

This series fixes a couple of infelicities when splitting hunks that have already been selected or edited which I noticed a while ago when preparing the test for 'pw/add-patch-with-suppress-blank-empty'.

Phillip Wood (2):
  add -p: mark split hunks as undecided
  add-patch: update hunk splitability after editing
 add-patch.c                | 15 +++++++++++++--
 t/t3701-add-interactive.sh | 31 +++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 2 deletions(-)
base-commit: 4975ec3473b4bc61bc8a3df1ef29d0b7e7959e87
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1863%2Fphillipwood%2Fadd-p-split-hunks-are-undecided-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1863/phillipwood/add-p-split-hunks-are-undecided-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/1863
Range-diff vs v2:
 1:  3e2ec7b37f ! 1:  4935dde399 add -p: mark split hunks as undecided
     @@ Commit message
          the split hunks they will now have to do more work re-selecting the
          remaining split hunks. However, changing the selection of any of the
          other newly created hunks is now much simpler as the user no-longer has
     -    to navigate back to them in order to change their selected state. Due
     -    to concerns that users may be relying on the current behaviour [1]
     -    this change is guarded by WITH_BREAKING_CHANGES.
     -
     -    [1] https://lore.kernel.org/git/xmqqjz9b6xr1.fsf@gitster.g
     +    to navigate back to them in order to change their selected state.
      
          Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
      
     - ## Documentation/BreakingChanges.adoc ##
     -@@ Documentation/BreakingChanges.adoc: A prerequisite for this change is that the ecosystem is ready to support the
     - "reftable" format. Most importantly, alternative implementations of Git like
     - JGit, libgit2 and Gitoxide need to support it.
     - 
     -+* The behavior of "git add -p" has been changed so that splitting a
     -+  hunk that has already been marked as selected or unselected will now
     -+  prompt the user to select each of the new hunks created by the
     -+  split instead of them inheriting their state from the original hunk.
     -+
     - === Removals
     - 
     - * Support for grafting commits has long been superseded by git-replace(1).
     -
       ## add-patch.c ##
      @@ add-patch.c: static int split_hunk(struct add_p_state *s, struct file_diff *file_diff,
       			* sizeof(*hunk));
       	hunk = file_diff->hunk + hunk_index;
       	hunk->splittable_into = 1;
     -+#ifdef WITH_BREAKING_CHANGES
      +	hunk->use = UNDECIDED_HUNK;
     -+#endif
       	memset(hunk + 1, 0, (splittable_into - 1) * sizeof(*hunk));
       
       	header = &hunk->header;
     @@ add-patch.c: next_hunk_line:
       
       		hunk++;
       		hunk->splittable_into = 1;
     -+#ifdef WITH_BREAKING_CHANGES
     +-		hunk->use = hunk[-1].use;
      +		hunk->use = UNDECIDED_HUNK;
     -+#else
     - 		hunk->use = hunk[-1].use;
     -+#endif
       		header = &hunk->header;
       
       		header->old_count = header->new_count = context_line_count;
     @@ t/t3701-add-interactive.sh: do
       	'
       done
       
     -+test_expect_success WITH_BREAKING_CHANGES 'splitting previous hunk marks split hunks as undecided' '
     ++test_expect_success 'splitting previous hunk marks split hunks as undecided' '
      +	test_write_lines a " " b c d e f g h i j k >file &&
      +	git add file &&
      +	test_write_lines x " " b y d e f g h i j x >file &&
 2:  3a831b1a2d ! 2:  390686dbb3 add-patch: update hunk splitability after editing
     @@ add-patch.c: static ssize_t recount_edited_hunk(struct add_p_state *s, struct hu
       
      
       ## t/t3701-add-interactive.sh ##
     -@@ t/t3701-add-interactive.sh: test_expect_success WITH_BREAKING_CHANGES 'splitting previous hunk marks split h
     +@@ t/t3701-add-interactive.sh: test_expect_success 'splitting previous hunk marks split hunks as undecided' '
       	test_cmp expect actual
       '
       
     @@ t/t3701-add-interactive.sh: test_expect_success WITH_BREAKING_CHANGES 'splitting
      +	test_write_lines A b c d E f g h i j k l M n >file &&
      +	(
      +		test_set_editor "$(pwd)/fake-editor.sh" &&
     -+		if test_have_prereq WITH_BREAKING_CHANGES
     -+		then
     -+			test_write_lines e K s j y n y q
     -+		else
     -+			test_write_lines e K s n K n y q
     -+		fi | git add -p file
     ++		test_write_lines e K s j y n y q | git add -p file
      +	) &&
      +	git cat-file blob :file >actual &&
      +	test_write_lines a b d e f g h i j k l M n >expect &&
-- 
gitgitgadget
Previous: Phillip Wood via GitGitGadgetNext: Phillip Wood via GitGitGadget
Message 21 of 27 in “add -p: a couple of hunk splitting fixes”
  1. 0/2 add -p: a couple of hunk splitting fixesPhillip Wood via GitGitGadget, Feb 21, 2025
  2. 1/2 add -p: mark split hunks as undecidedPhillip Wood via GitGitGadget, Feb 21, 2025
  3. Justin ToblerFeb 21, 2025
  4. Junio C HamanoFeb 21, 2025
  5. phillip.wood123@gmail.comFeb 26, 2025
  6. Junio C HamanoFeb 26, 2025
  7. phillip.wood123@gmail.comFeb 27, 2025
  8. Junio C HamanoFeb 27, 2025
  9. Phillip WoodFeb 28, 2025
  10. Junio C HamanoFeb 28, 2025
  11. Phillip WoodMar 4, 2025
  12. 2/2 add-patch: update hunk splitability after editingPhillip Wood via GitGitGadget, Feb 21, 2025
  13. Justin ToblerFeb 21, 2025
  14. Junio C HamanoFeb 21, 2025
  15. 0/2 add -p: a couple of hunk splitting fixesPhillip Wood via GitGitGadget, Sep 15, 2025
  16. 1/2 add -p: mark split hunks as undecidedPhillip Wood via GitGitGadget, Sep 15, 2025
  17. Junio C HamanoSep 15, 2025
  18. Phillip WoodSep 16, 2025
  19. Junio C HamanoSep 16, 2025
  20. 2/2 add-patch: update hunk splitability after editingPhillip Wood via GitGitGadget, Sep 15, 2025
  21. 0/2 add -p: a couple of hunk splitting fixesPhillip Wood via GitGitGadget, Sep 25, 2025
  22. 1/2 add -p: mark split hunks as undecidedPhillip Wood via GitGitGadget, Sep 25, 2025
  23. Junio C HamanoSep 25, 2025
  24. Phillip WoodSep 26, 2025
  25. Junio C HamanoSep 26, 2025
  26. Phillip WoodOct 8, 2025
  27. 2/2 add-patch: update hunk splitability after editingPhillip Wood via GitGitGadget, Sep 25, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.