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

Re: [PATCH] Add path-limiting to git-add--interactive

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 22, 2007, 09:45 UTC
Message-ID
<7vd4u27gvn.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<7vpry27id0.fsf@gitster.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 20 quoted lines
> Wincent Colaiuta <win@wincent.com> writes:
>
>> @@ -56,9 +56,14 @@ sub list_modified {
>>  	my ($only) = @_;
>>  	my (%data, @return);
>>  	my ($add, $del, $adddel, $file);
>> +	my @tracked = grep {
>> +		defined run_cmd_pipe(qw(git ls-files
>> +			                --exclude-standard --), $_)
>> +	} @ARGV;
>> +	return if $#tracked == -1 && $#ARGV != -1;
>
> Eek.  why?
>
> Did you mean to say:
>
>     my @tracked = run_cmd_pipe(gw(git ls-files --exclude-standard --) @ARGV);
>
> It would also make sense to use --error-unmatch and perhaps --with-tree=HEAD
> like git-commit.sh does.

Actually, the ls-files need to be chomped, but I'd prefer to run -z form of the command and split with NUL. Does run_cmd_pipe() crap^Wstuff support that?

On top of:
 * refactor patch_update_cmd,
 * teach builtin-add to pass multiple paths,
 * add path-limiting to git-add--interacgtive (with an obvious
   suggested above),

the attached patch teaches [p]atch subcommand to take multiple selections. With these, you can do:

	$ git add -i 'u*.h'
	What now> p
                   staged     unstaged path
          1:    unchanged        +1/-0 unpack-trees.h
          2:    unchanged        +1/-0 utf8.h
        Patch update>> *
        diff --git a/unpack-trees.h b/unpack-trees.h
	...
        Stage this hunk [y/n/a/d/?]? y
        ...
	diff --git a/utf8.h b/utf8.h
        ...

-- >8 -- git-add -i: allow multiple selection in [p]atch subcommand

This allows more than one files from the list to be chosen from the patch subcommand instead of going through the file one by one.

This also updates the "list-and-choose" UI for usability. When the prompt ends with ">>", if you type '*' to choose all choices, the prompt immediately returns the choice without requiring an extra empty line to confirm the selection.

---
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 9236ffc..372dc2c 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -256,7 +256,7 @@ sub list_and_choose {
 				$chosen[$i] = $choose;
 			}
 		}
-		last if ($opts->{IMMEDIATE});
+		last if ($opts->{IMMEDIATE} || $line eq '*');
 	}
 	for ($i = 0; $i < @stuff; $i++) {
 		if ($chosen[$i]) {
@@ -563,12 +563,12 @@ sub patch_update_cmd {
 	@mods = grep { !($_->{BINARY}) } @mods;
 	return if (!@mods);
 
-	my ($it) = list_and_choose({ PROMPT => 'Patch update',
-				     SINGLETON => 1,
-				     IMMEDIATE => 1,
-				     HEADER => $status_head, },
-				   @mods);
-	patch_update_file($it->{VALUE}) if ($it);
+	my (@them) = list_and_choose({ PROMPT => 'Patch update',
+				       HEADER => $status_head, },
+				     @mods);
+	for (@them) {
+		patch_update_file($_->{VALUE});
+	}
 }
 
 sub patch_update_file {
Previous: Junio C HamanoNext: Wincent Colaiuta
Message 26 of 39 in “teaching git-add--interactive to accept a file param”
  1. teaching git-add--interactive to accept a file paramWincent Colaiuta, Nov 21, 2007
  2. 1/4 Refactor patch_update_cmdWincent Colaiuta, Nov 21, 2007
  3. 2/4 Teach git-add--interactive to accept a file path to patchWincent Colaiuta, Nov 21, 2007
  4. 3/4 Teach builtin-add to pass a path argument to git-add--interactiveWincent Colaiuta, Nov 21, 2007
  5. 4/4 Document optional file parameter to git-add--interactiveWincent Colaiuta, Nov 21, 2007
  6. Jeff KingNov 21, 2007
  7. Wincent ColaiutaNov 21, 2007
  8. Junio C HamanoNov 21, 2007
  9. Wincent ColaiutaNov 21, 2007
  10. Updates: teaching git-add--interactive to accept a file paramWincent Colaiuta, Nov 22, 2007
  11. 1/4 Suppress spurious linefeeds in git-add--interactiveWincent Colaiuta, Nov 22, 2007
  12. 2/4 Teach git-add--interactive to accept multiple file paramsWincent Colaiuta, Nov 22, 2007
  13. 3/4 Teach builtin-add to pass multiple paths to git-add--interactiveWincent Colaiuta, Nov 22, 2007
  14. 4/4 Update git-add documentation for multiple interactive pathsWincent Colaiuta, Nov 22, 2007
  15. Jeff KingNov 22, 2007
  16. Wincent ColaiutaNov 22, 2007
  17. Jeff KingNov 22, 2007
  18. Wincent ColaiutaNov 22, 2007
  19. Jeff KingNov 22, 2007
  20. Jeff KingNov 22, 2007
  21. Wincent ColaiutaNov 22, 2007
  22. Junio C HamanoNov 22, 2007
  23. Junio C HamanoNov 22, 2007
  24. Add path-limiting to git-add--interactiveWincent Colaiuta, Nov 22, 2007
  25. Junio C HamanoNov 22, 2007
  26. Junio C HamanoNov 22, 2007
  27. Wincent ColaiutaNov 22, 2007
  28. Wincent ColaiutaNov 22, 2007
  29. Wincent ColaiutaNov 22, 2007
  30. Jeff KingNov 22, 2007
  31. Junio C HamanoNov 22, 2007
  32. Jeff KingNov 22, 2007
  33. Wincent ColaiutaNov 22, 2007
  34. Jeff KingNov 22, 2007
  35. Junio C HamanoNov 22, 2007
  36. Jeff KingNov 22, 2007
  37. Wincent ColaiutaNov 22, 2007
  38. Junio C HamanoNov 22, 2007
  39. Wincent ColaiutaNov 22, 2007

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.