summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cf5c51e)
raw | patch | inline | side by side (parent: cf5c51e)
author | Matthias Kestenholz <mk@spinlock.ch> | |
Mon, 18 Feb 2008 07:26:03 +0000 (08:26 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 18 Feb 2008 08:00:38 +0000 (00:00 -0800) |
Signed-off-by: Matthias Kestenholz <mk@spinlock.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config.txt | patch | blob | history | |
builtin-branch.c | patch | blob | history | |
builtin-commit.c | patch | blob | history | |
builtin-diff.c | patch | blob | history | |
builtin-log.c | patch | blob | history | |
color.c | patch | blob | history | |
color.h | patch | blob | history | |
diff.c | patch | blob | history | |
diff.h | patch | blob | history | |
wt-status.c | patch | blob | history |
index f2f6a774e044e03e78d83e4e77aedcff122f5688..7b676710bab0709970abe7411d2246c0eb2b34b8 100644 (file)
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
commit.template::
Specify a file to use as the template for new commit messages.
+color.ui::
+ When set to `always`, always use colors in all git commands which
+ are capable of colored output. When false (or `never`), never. When
+ set to `true` or `auto`, use colors only when the output is to the
+ terminal. When more specific variables of color.* are set, they always
+ take precedence over this setting. Defaults to false.
+
diff.autorefreshindex::
When using `git diff` to compare with work tree
files, do not consider stat-only change as changed.
diff --git a/builtin-branch.c b/builtin-branch.c
index e414c8898317736d632064d6c0545d7d128c6bc8..9edf2eb8162eb7214e1b4d76dca8949c63e72847 100644 (file)
--- a/builtin-branch.c
+++ b/builtin-branch.c
static int branch_track = 1;
-static int branch_use_color;
+static int branch_use_color = -1;
static char branch_colors[][COLOR_MAXLEN] = {
"\033[m", /* reset */
"", /* PLAIN (normal) */
branch_track = git_config_bool(var, value);
return 0;
}
- return git_default_config(var, value);
+ return git_color_default_config(var, value);
}
static const char *branch_get_color(enum color_branch ix)
{
- if (branch_use_color)
+ if (branch_use_color > 0)
return branch_colors[ix];
return "";
}
};
git_config(git_branch_config);
+
+ if (branch_use_color == -1)
+ branch_use_color = git_use_color_default;
+
track = branch_track;
argc = parse_options(argc, argv, options, builtin_branch_usage, 0);
if (!!delete + !!rename + !!force_create > 1)
diff --git a/builtin-commit.c b/builtin-commit.c
index 6612b4f40504fea0cd9aec4463c20d8982bfbaeb..065e1f7b7fbf426210d08062800ed81448a30d4a 100644 (file)
--- a/builtin-commit.c
+++ b/builtin-commit.c
#include "cache.h"
#include "cache-tree.h"
+#include "color.h"
#include "dir.h"
#include "builtin.h"
#include "diff.h"
git_config(git_status_config);
+ if (wt_status_use_color == -1)
+ wt_status_use_color = git_use_color_default;
+
argc = parse_and_validate_options(argc, argv, builtin_status_usage);
index_file = prepare_index(argc, argv, prefix);
diff --git a/builtin-diff.c b/builtin-diff.c
index 8d7a5697f2b429f6240a89e28422f48ef18aee3b..8f53f52dcbe74c1fdb6b7a54a8b250537bc821ee 100644 (file)
--- a/builtin-diff.c
+++ b/builtin-diff.c
* Copyright (c) 2006 Junio C Hamano
*/
#include "cache.h"
+#include "color.h"
#include "commit.h"
#include "blob.h"
#include "tag.h"
prefix = setup_git_directory_gently(&nongit);
git_config(git_diff_ui_config);
+
+ if (diff_use_color_default == -1)
+ diff_use_color_default = git_use_color_default;
+
init_revisions(&rev, prefix);
rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
diff --git a/builtin-log.c b/builtin-log.c
index 99d69f079132ed67e2d5bc83bf95e6e60ba22f6f..f2216d3187735799d60ddd9b9a50c783fe338f2d 100644 (file)
--- a/builtin-log.c
+++ b/builtin-log.c
* 2006 Junio Hamano
*/
#include "cache.h"
+#include "color.h"
#include "commit.h"
#include "diff.h"
#include "revision.h"
struct rev_info rev;
git_config(git_log_config);
+
+ if (diff_use_color_default == -1)
+ diff_use_color_default = git_use_color_default;
+
init_revisions(&rev, prefix);
rev.diff = 1;
rev.simplify_history = 0;
int i, count, ret = 0;
git_config(git_log_config);
+
+ if (diff_use_color_default == -1)
+ diff_use_color_default = git_use_color_default;
+
init_revisions(&rev, prefix);
rev.diff = 1;
rev.combine_merges = 1;
struct rev_info rev;
git_config(git_log_config);
+
+ if (diff_use_color_default == -1)
+ diff_use_color_default = git_use_color_default;
+
init_revisions(&rev, prefix);
init_reflog_walk(&rev.reflog_info);
rev.abbrev_commit = 1;
struct rev_info rev;
git_config(git_log_config);
+
+ if (diff_use_color_default == -1)
+ diff_use_color_default = git_use_color_default;
+
init_revisions(&rev, prefix);
rev.always_show_header = 1;
cmd_log_init(argc, argv, prefix, &rev);
index cb70340420b6285786b988d4a98d2023a37d4ffc..12a6453f90eb4ce2b39f85762bf3acd1cff2b9f2 100644 (file)
--- a/color.c
+++ b/color.c
#define COLOR_RESET "\033[m"
+int git_use_color_default = 0;
+
static int parse_color(const char *name, int len)
{
static const char * const color_names[] = {
@@ -143,6 +145,16 @@ int git_config_colorbool(const char *var, const char *value, int stdout_is_tty)
return 0;
}
+int git_color_default_config(const char *var, const char *value)
+{
+ if (!strcmp(var, "color.ui")) {
+ git_use_color_default = git_config_colorbool(var, value, -1);
+ return 0;
+ }
+
+ return git_default_config(var, value);
+}
+
static int color_vfprintf(FILE *fp, const char *color, const char *fmt,
va_list args, const char *trail)
{
index ff63513d39b1553e65230ef98583549506670950..ecda5569a2cccabaf16fcf0aad3bce57dfb3aca4 100644 (file)
--- a/color.h
+++ b/color.h
/* "\033[1;38;5;2xx;48;5;2xxm\0" is 23 bytes */
#define COLOR_MAXLEN 24
+/*
+ * This variable stores the value of color.ui
+ */
+extern int git_use_color_default;
+
+
+/*
+ * Use this instead of git_default_config if you need the value of color.ui.
+ */
+int git_color_default_config(const char *var, const char *value);
+
int git_config_colorbool(const char *var, const char *value, int stdout_is_tty);
void color_parse(const char *var, const char *value, char *dst);
int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
index 58fe7750f9ca7d63192164a3ac8da27553489d11..c30c252272d51f22e66ebf1b0c531f4bfa473651 100644 (file)
--- a/diff.c
+++ b/diff.c
static int diff_detect_rename_default;
static int diff_rename_limit_default = 100;
-static int diff_use_color_default;
+int diff_use_color_default = -1;
static const char *external_diff_cmd_cfg;
int diff_auto_refresh_index = 1;
}
}
- return git_default_config(var, value);
+ return git_color_default_config(var, value);
}
static char *quote_two(const char *one, const char *two)
options->change = diff_change;
options->add_remove = diff_addremove;
- if (diff_use_color_default)
+ if (diff_use_color_default > 0)
DIFF_OPT_SET(options, COLOR_DIFF);
else
DIFF_OPT_CLR(options, COLOR_DIFF);
index 073d5cbf1ba97acf527770d912870cda01195489..8e73f07d7e35cd414c0f5cf347516e39921a7dd1 100644 (file)
--- a/diff.h
+++ b/diff.h
extern int git_diff_basic_config(const char *var, const char *value);
extern int git_diff_ui_config(const char *var, const char *value);
+extern int diff_use_color_default;
extern void diff_setup(struct diff_options *);
extern int diff_opt_parse(struct diff_options *, const char **, int);
extern int diff_setup_done(struct diff_options *);
diff --git a/wt-status.c b/wt-status.c
index 0b060934e218f1d6fb95777ea7dd7faef1c2dd93..32d780af1e4f6e701f75d9759dfd4ebec56e6425 100644 (file)
--- a/wt-status.c
+++ b/wt-status.c
#include "diffcore.h"
int wt_status_relative_paths = 1;
-int wt_status_use_color = 0;
+int wt_status_use_color = -1;
static char wt_status_colors[][COLOR_MAXLEN] = {
"", /* WT_STATUS_HEADER: normal */
"\033[32m", /* WT_STATUS_UPDATED: green */
static const char* color(int slot)
{
- return wt_status_use_color ? wt_status_colors[slot] : "";
+ return wt_status_use_color > 0 ? wt_status_colors[slot] : "";
}
void wt_status_prepare(struct wt_status *s)
wt_status_relative_paths = git_config_bool(k, v);
return 0;
}
- return git_default_config(k, v);
+ return git_color_default_config(k, v);
}