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

[PATCH 5/5] add--interactive: add option to autosplit hunks

From
Jeff King <peff@peff.net>
Date
Jul 27, 2011, 08:06 UTC
Message-ID
<20110727080601.GE14002@sigill.intra.peff.net>
In-Reply-To
<20110727080303.GA8105@sigill.intra.peff.net>

It is sometimes useful to see changes in their smallest possible form, rather than complete hunks with overlapping context. You can do this manually, of course, with the 's'plit hunk command. But when filtering hunks, you may want to pre-split to give your filtering a finer granularity.

This patch adds only the perl infrastructure; to expose this to the user, the various callers of add--interactive need to pass the new option through to the perl script.

Signed-off-by: Jeff King <peff@peff.net>
---
 git-add--interactive.perl |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 917b2a9..41c7c6f 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -88,6 +88,7 @@ my $patch_mode;
 my $patch_mode_revision;
 my @patch_mode_hunk_filter;
 my $patch_mode_negate_filter;
+my $patch_mode_autosplit;
 
 sub apply_patch;
 sub apply_patch_for_checkout_commit;
@@ -1291,6 +1292,10 @@ sub patch_update_file {
 	my $path = shift;
 	my ($head, @hunk) = parse_diff($path);
 
+	if ($patch_mode_autosplit) {
+		@hunk = map { split_hunk($_->{TEXT}, $_->{DISPLAY}) } @hunk;
+	}
+
 	if (@patch_mode_hunk_filter) {
 		@hunk = grep { want_hunk($_) } @hunk;
 		return unless @hunk;
@@ -1594,6 +1599,9 @@ sub process_args {
 		elsif ($ARGV[0] eq '--negate-hunk-filter') {
 			$patch_mode_negate_filter = 1;
 		}
+		elsif ($ARGV[0] eq '--split-hunks') {
+			$patch_mode_autosplit = 1;
+		}
 		else {
 			last;
 		}
-- 
1.7.5.4.31.ge4d5e
Previous: Jeff King
Message 19 of 19 in “feature request: git add--interactive --patch on regex-matched hunks only”
  1. Nguyen Thai Ngoc DuyJul 24, 2011
  2. Jeff KingJul 25, 2011
  3. Junio C HamanoJul 25, 2011
  4. Jeff KingJul 26, 2011
  5. Nguyen Thai Ngoc DuyJul 26, 2011
  6. Jeff KingJul 26, 2011
  7. Nguyen Thai Ngoc DuyJul 26, 2011
  8. Jeff KingJul 26, 2011
  9. Nguyen Thai Ngoc DuyJul 26, 2011
  10. Nguyen Thai Ngoc DuyJul 26, 2011
  11. Jeff KingJul 27, 2011
  12. Nguyen Thai Ngoc DuyJul 27, 2011
  13. Jeff KingJul 27, 2011
  14. Jeff KingJul 27, 2011
  15. 1/5 add--interactive: refactor patch mode argument processingJeff King, Jul 27, 2011
  16. 2/5 add--interactive: factor out regex error handlingJeff King, Jul 27, 2011
  17. 3/5 add--interactive: allow hunk filtering on command lineJeff King, Jul 27, 2011
  18. 4/5 add--interactive: allow negatation of hunk filtersJeff King, Jul 27, 2011
  19. 5/5 add--interactive: add option to autosplit hunksJeff King, Jul 27, 2011

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.