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

Re: feature request: git add--interactive --patch on regex-matched hunks only

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 25, 2011, 23:44 UTC
Message-ID
<7vbowiq62m.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20110725215553.GA23145@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 5 quoted lines
> However, I'm not sure I would trust my regex to actually get all of the
> changes needed for the refactoring (e.g., there might be nearby hunks
> related to the refactoring that are not specifically in the same hunk as
> the word "foo"). So I tend to just "git add -p" and flip through the
> changes manually.
Yes, that is a valid concern.
> You can already skip around in the hunk list using "/regex". Might that
> be enough for you? I think you're stuck typing "/yoursearch" over and
> over, though. It would be nice if doing just "/" would search again for
> the previous regex.

Yes, I think that makes a lot more sense than the current "Ah, empty? ask from the terminal" behaviour.

 git-add--interactive.perl |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 8f0839d..0b6f8a6 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1257,7 +1257,7 @@ sub display_hunks {
 
 sub patch_update_file {
 	my $quit = 0;
-	my ($ix, $num);
+	my ($ix, $num, $last_search_string);
 	my $path = shift;
 	my ($head, @hunk) = parse_diff($path);
 	($head, my $mode, my $deletion) = parse_diff_header($head);
@@ -1395,11 +1395,12 @@ sub patch_update_file {
 			}
 			elsif ($line =~ m|^/(.*)|) {
 				my $regex = $1;
-				if ($1 eq "") {
-					print colored $prompt_color, "search for regex? ";
-					$regex = <STDIN>;
-					if (defined $regex) {
-						chomp $regex;
+				if ($regex eq "") {
+					if ($last_search_string) {
+						$regex = $last_search_string;
+					} else {
+						error_msg "Need a regexp to search\n";
+						next;
 					}
 				}
 				my $search_string;
@@ -1412,6 +1413,7 @@ sub patch_update_file {
 					error_msg "Malformed search regexp $exp: $err\n";
 					next;
 				}
+				$last_search_string = $regex;
 				my $iy = $ix;
 				while (1) {
 					my $text = join ("", @{$hunk[$iy]{TEXT}});
Previous: Jeff KingNext: Jeff King
Message 3 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.