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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Jan 06, 2008 at 02:51:24AM -0800, Junio C Hamano wrote:

> 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@xxxxxxxx>
---
 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

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux