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

Re: summaries in git add --patch[PATCH 2/2]

From
William Pursell <bill.pursell@gmail.com>
Date
Dec 3, 2008, 20:39 UTC
Message-ID
<4936EE68.6030009@gmail.com>
In-Reply-To
<7vskp6j95x.fsf@gitster.siamese.dyndns.org>
 From 57b5eab3f64a40ebe9aca122b5c6db1ab5c26116 Mon Sep 17 00:00:00 2001
From: William Pursell <bill.pursell@gmail.com>
Date: Wed, 3 Dec 2008 20:26:36 +0000
Subject: [PATCH 2/2] Implemented 'g' command to goto a hunk.

When a minor change is made while the working directory is in a bit of a mess (and the user should have done a stash before making the minor edit, but didn't) it is somewhat difficult to wade through all of the hunks using git add --patch. This allows one to jump to the hunk that needs to be staged without having to respond 'n' to each preceding hunk.

Signed-off-by: William Pursell <bill.pursell@gmail.com>
---
  git-add--interactive.perl |   25 +++++++++++++++++++++++++
  1 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index daf8d5d..98ce8e3 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -800,6 +800,7 @@ y - stage this hunk
  n - do not stage this hunk
  a - stage this and all the remaining hunks in the file
  d - do not stage this hunk nor any of the remaining hunks in the file
+g - select a hunk to goto
  j - leave this hunk undecided, see next undecided hunk
  J - leave this hunk undecided, see next hunk
  k - leave this hunk undecided, see previous undecided hunk
@@ -943,6 +944,9 @@ sub patch_update_file {
  		if ($ix < $num - 1) {
  			$other .= '/J';
  		}
+		if ($num > 1) {
+			$other .= '/g';
+		}
  		for ($i = 0; $i < $num; $i++) {
  			if (!defined $hunk[$i]{USE}) {
  				$undecided = 1;
@@ -976,6 +980,27 @@ sub patch_update_file {
  				}
  				next;
  			}
+			elsif ($other =~ 'g' && $line =~ /^g(.*)/) {
+				my $response = $1;
+				my $i = 0;
+				chomp $response;
+				while (not $response) {
+					my $extra = "";
+					$i = display_hunks (\@hunk, $i);
+					$extra = "(<ret> to see more): " if ($i != $num);
+					print "goto which hunk? $extra";
+					$response = <STDIN>;
+					chomp $response;
+				}
+				if ($response !~ /^\s*\d+$/) {
+					print STDERR "Invalid number: '$response'\n";
+				} elsif (0 < $response && $response <= $num) {
+					$ix = $response - 1;
+				} else {
+					print STDERR "Sorry, only $num hunks available.\n";
+				}
+				next;
+			}
  			elsif ($line =~ /^d/i) {
  				while ($ix < $num) {
  					if (!defined $hunk[$ix]{USE}) {
-- 
1.6.1.rc1.37.g83daf.dirty



-- 
William Pursell
Previous: Junio C HamanoNext: Junio C Hamano
Message 15 of 19 in “summaries in git add --patch”
  1. William PursellNov 27, 2008
  2. Jakub NarebskiNov 27, 2008
  3. Junio C HamanoNov 28, 2008
  4. William PursellNov 28, 2008
  5. William PursellNov 28, 2008
  6. Junio C HamanoNov 28, 2008
  7. William PursellNov 29, 2008
  8. Junio C HamanoDec 3, 2008
  9. William PursellDec 3, 2008
  10. Junio C HamanoDec 3, 2008
  11. William PursellDec 4, 2008
  12. Junio C HamanoDec 4, 2008
  13. William PursellDec 4, 2008
  14. Junio C HamanoDec 5, 2008
  15. William PursellDec 3, 2008
  16. Junio C HamanoDec 3, 2008
  17. William PursellDec 4, 2008
  18. Junio C HamanoDec 4, 2008
  19. William PursellDec 4, 2008

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.