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

Re: What's in git.git (stable frozen)

From
Jeff King <peff@peff.net>
Date
Jan 6, 2008, 11:17 UTC
Message-ID
<20080106111725.GA11603@coredump.intra.peff.net>
In-Reply-To
<7vejcv5is3.fsf@gitster.siamese.dyndns.org>
On Sun, Jan 06, 2008 at 02:51:24AM -0800, Junio C Hamano wrote:
Show 10 quoted lines
> It may make more sense to:
> 
>  * unset $prompt_color and friends when color.interactive says
>    "not to color the menus";
> 
>  * unset $fraginfo_color and diff related ones when color.diff
>    says "diff is monochrome";
> 
> upfront, and then change "sub colored" to just check if $color
> is unset, instead of checking $use_color.
Something like this (instead of my last patch):

-- >8 -- add--interactive: fix "colored" function semantics

Since color.interactive is just for the menus, the "colored" function can't use it to determine whether to show colors (this was visible as a bug in which the headers of split hunks were not colored if color.diff was set but color.interactive was not).

The new semantics are:
  - colors which are unused are set to undef; the "colored"
    function knows not to do anything with them
  - menu colors are set only when color.interactive is true
  - diff colors are set only when color.diff is true
Signed-off-by: Jeff King <peff@peff.net>
---
 git-add--interactive.perl |   39 +++++++++++++++------------------------
 1 files changed, 15 insertions(+), 24 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 5bdcca8..17ca5b8 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -3,38 +3,29 @@
 use strict;
 use Git;
 
-# Prompt colors:
-my ($prompt_color, $header_color, $help_color, $normal_color);
-# Diff colors:
-my ($fraginfo_color);
-
-my ($use_color, $diff_use_color);
 my $repo = Git->repository();
 
-$use_color = $repo->get_colorbool('color.interactive');
-
-if ($use_color) {
-	# Set interactive colors:
+my $menu_use_color = $repo->get_colorbool('color.interactive');
+my ($prompt_color, $header_color, $help_color) =
+	$menu_use_color ? (
+		$repo->get_color('color.interactive.prompt', 'bold blue'),
+		$repo->get_color('color.interactive.header', 'bold'),
+		$repo->get_color('color.interactive.help', 'red bold'),
+	) : ();
 
-	# Grab the 3 main colors in git color string format, with sane
-	# (visible) defaults:
-	$prompt_color = $repo->get_color("color.interactive.prompt", "bold blue");
-	$header_color = $repo->get_color("color.interactive.header", "bold");
-	$help_color = $repo->get_color("color.interactive.help", "red bold");
-	$normal_color = $repo->get_color("", "reset");
-}
+my $diff_use_color = $repo->get_colorbool('color.diff');
+my ($fraginfo_color) =
+	$diff_use_color ? (
+		$repo->get_color('color.diff.frag', 'cyan'),
+	) : ();
 
-# Do we also set diff colors?
-$diff_use_color = $repo->get_colorbool('color.diff');
-if ($diff_use_color) {
-	$fraginfo_color = $repo->get_color("color.diff.frag", "cyan");
-}
+my $normal_color = $repo->get_color("", "reset");
 
 sub colored {
 	my $color = shift;
 	my $string = join("", @_);
 
-	if ($use_color) {
+	if (defined $color) {
 		# Put a color code at the beginning of each line, a reset at the end
 		# color after newlines that are not at the end of the string
 		$string =~ s/(\n+)(.)/$1$color$2/g;
@@ -300,7 +291,7 @@ sub highlight_prefix {
 		return "$prefix$remainder";
 	}
 
-	if (!$use_color) {
+	if (!$menu_use_color) {
 		return "[$prefix]$remainder";
 	}
 
-- 
1.5.4.rc2.1148.gf9fe3-dirty
Previous: Junio C HamanoNext: Junio C Hamano
Message 62 of 72 in “What's in git/spearce.git (stable)”
  1. Shawn O. PearceOct 22, 2007
  2. What's in git.git (stable)Junio C Hamano, Nov 1, 2007
  3. What's in git.git (stable)Junio C Hamano, Nov 4, 2007
  4. What's in git.git (stable)Junio C Hamano, Nov 8, 2007
  5. Pierre HabouzitNov 8, 2007
  6. What's in git.git (stable)Junio C Hamano, Nov 12, 2007
  7. What's in git.git (stable)Junio C Hamano, Nov 15, 2007
  8. What's in git.git (stable)Junio C Hamano, Nov 17, 2007
  9. What's in git.git (stable)Junio C Hamano, Nov 25, 2007
  10. What's in git.git (stable)Junio C Hamano, Dec 1, 2007
  11. What's in git.git (stable)Junio C Hamano, Dec 4, 2007
  12. What's in git.git (stable)Junio C Hamano, Dec 5, 2007
  13. What's in git.git (stable)Junio C Hamano, Dec 7, 2007
  14. What's in git.git (stable)Junio C Hamano, Dec 9, 2007
  15. v1.5.4 plansJunio C Hamano, Dec 10, 2007
  16. Jeff KingDec 10, 2007
  17. Junio C HamanoDec 11, 2007
  18. Junio C HamanoDec 11, 2007
  19. Jeff KingDec 11, 2007
  20. Junio C HamanoDec 11, 2007
  21. Jeff KingDec 11, 2007
  22. Junio C HamanoDec 11, 2007
  23. Jeff KingDec 11, 2007
  24. Jeff KingDec 11, 2007
  25. Jeff KingDec 11, 2007
  26. 2/2 git-svn: get color config from --get-colorboolJeff King, Dec 11, 2007
  27. Eric WongDec 12, 2007
  28. Jeff KingDec 11, 2007
  29. Andreas EricssonDec 11, 2007
  30. Jeff KingDec 11, 2007
  31. Nicolas PitreDec 11, 2007
  32. Johannes SchindelinDec 11, 2007
  33. Nicolas PitreDec 11, 2007
  34. Kristian HøgsbergDec 11, 2007
  35. Junio C HamanoDec 11, 2007
  36. Eric WongDec 12, 2007
  37. Junio C HamanoDec 12, 2007
  38. David D. KilzerDec 12, 2007
  39. David D. KilzerDec 31, 2007
  40. Fix race condition in t9119-git-svn-info.shDavid D. Kilzer, Dec 31, 2007
  41. Junio C HamanoDec 31, 2007
  42. Remove duplication in t9119-git-svn-info.shDavid D. Kilzer, Dec 31, 2007
  43. Eric WongJan 2, 2008
  44. David D. KilzerJan 2, 2008
  45. Junio C HamanoJan 2, 2008
  46. Junio C HamanoJan 2, 2008
  47. What's in git.git (stable frozen)Junio C Hamano, Dec 13, 2007
  48. git-commit: squelch needless message during an empty mergeJunio C Hamano, Dec 13, 2007
  49. Jeff KingDec 13, 2007
  50. Johannes SixtDec 13, 2007
  51. What's in git.git (stable frozen)Junio C Hamano, Dec 17, 2007
  52. What's in git.git (stable frozen)Junio C Hamano, Dec 23, 2007
  53. What's in git.git (stable frozen)Junio C Hamano, Jan 5, 2008
  54. Dan McGeeJan 5, 2008
  55. Junio C HamanoJan 6, 2008
  56. Junio C HamanoJan 6, 2008
  57. Dan McGeeJan 6, 2008
  58. Junio C HamanoJan 6, 2008
  59. Jeff KingJan 6, 2008
  60. Jeff KingJan 6, 2008
  61. Junio C HamanoJan 6, 2008
  62. Jeff KingJan 6, 2008
  63. Junio C HamanoJan 6, 2008
  64. Jeff KingJan 6, 2008
  65. Junio C HamanoJan 6, 2008
  66. Jeff KingJan 7, 2008
  67. Junio C HamanoJan 7, 2008
  68. Paul MackerrasJan 7, 2008
  69. Christian StimmingJan 7, 2008
  70. Junio C HamanoJan 7, 2008
  71. Steffen ProhaskaDec 17, 2007
  72. Junio C HamanoJan 5, 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.