Skip to content

Commit

Permalink
default color.status.branch to "same as header"
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
peff authored and gitster committed Dec 10, 2010
1 parent 1d28232 commit 148135f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions color.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,8 @@ int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...)
va_end(args);
return r;
}

int color_is_nil(const char *c)
{
return !strcmp(c, "NIL");
}
5 changes: 5 additions & 0 deletions color.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
#define GIT_COLOR_BG_MAGENTA "\033[45m"
#define GIT_COLOR_BG_CYAN "\033[46m"

/* A special value meaning "no color selected" */
#define GIT_COLOR_NIL "NIL"

/*
* This variable stores the value of color.ui
*/
Expand All @@ -62,4 +65,6 @@ int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
__attribute__((format (printf, 3, 4)))
int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);

int color_is_nil(const char *color);

#endif /* COLOR_H */
7 changes: 5 additions & 2 deletions wt-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ static char default_wt_status_colors[][COLOR_MAXLEN] = {
GIT_COLOR_RED, /* WT_STATUS_UNMERGED */
GIT_COLOR_GREEN, /* WT_STATUS_LOCAL_BRANCH */
GIT_COLOR_RED, /* WT_STATUS_REMOTE_BRANCH */
GIT_COLOR_NORMAL, /* WT_STATUS_ONBRANCH */
GIT_COLOR_NIL, /* WT_STATUS_ONBRANCH */
};

static const char *color(int slot, struct wt_status *s)
{
return s->use_color > 0 ? s->color_palette[slot] : "";
const char *c = s->use_color > 0 ? s->color_palette[slot] : "";
if (slot == WT_STATUS_ONBRANCH && color_is_nil(c))
c = s->color_palette[WT_STATUS_HEADER];
return c;
}

void wt_status_prepare(struct wt_status *s)
Expand Down

0 comments on commit 148135f

Please sign in to comment.