@matheusbsbs / matheus-bagliano / commits / 148135fc24
Fork 0

default color.status.branch to "same as header"

This gives it the same behavior as we had prior to 1d28232 (status: show branchname with a configurable color). To do this we need the concept of a "NIL" color, which is provided by color.[ch]. The implementation is very simple; in particular, there are no precautions taken against code accidentally printing the NIL. This should be fine in practice because: 1. You can't input a NIL color in the config, so it must come from the in-code defaults. Which means it is up the client code to handle the NILs it defines. 2. If we do ever print a NIL, it will be obvious what the problem is, and the bug can be fixed. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Dec 9, 2010 at 12:27 UTC 148135fc24dce1e61cfd7fcedea4210095099e78
3 files changed +15 -2
color.c
+5
@@ -211,3 +211,8 @@ int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...)
211 va_end(args);
212 return r;
213 }
214 +
215 +int color_is_nil(const char *c)
216 +{
217 + return !strcmp(c, "NIL");
218 +}
color.h
+5
@@ -43,6 +43,9 @@
43 #define GIT_COLOR_BG_MAGENTA "\033[45m"
44 #define GIT_COLOR_BG_CYAN "\033[46m"
45
46 +/* A special value meaning "no color selected" */
47 +#define GIT_COLOR_NIL "NIL"
48 +
49 /*
50 * This variable stores the value of color.ui
51 */
@@ -62,4 +65,6 @@ int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
65 __attribute__((format (printf, 3, 4)))
66 int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);
67
68 +int color_is_nil(const char *color);
69 +
70 #endif /* COLOR_H */
wt-status.c
+5 -2
@@ -21,12 +21,15 @@ static char default_wt_status_colors[][COLOR_MAXLEN] = {
21 GIT_COLOR_RED, /* WT_STATUS_UNMERGED */
22 GIT_COLOR_GREEN, /* WT_STATUS_LOCAL_BRANCH */
23 GIT_COLOR_RED, /* WT_STATUS_REMOTE_BRANCH */
24 - GIT_COLOR_NORMAL, /* WT_STATUS_ONBRANCH */
24 + GIT_COLOR_NIL, /* WT_STATUS_ONBRANCH */
25 };
26
27 static const char *color(int slot, struct wt_status *s)
28 {
29 - return s->use_color > 0 ? s->color_palette[slot] : "";
29 + const char *c = s->use_color > 0 ? s->color_palette[slot] : "";
30 + if (slot == WT_STATUS_ONBRANCH && color_is_nil(c))
31 + c = s->color_palette[WT_STATUS_HEADER];
32 + return c;
33 }
34
35 void wt_status_prepare(struct wt_status *s)