13
14
static int use_size_cache;
15
16
-int diff_rename_limit_default = -1;
17
-
18
-int git_diff_config(const char *var, const char *value)
19
-{
20
- if (!strcmp(var, "diff.renamelimit")) {
21
- diff_rename_limit_default = git_config_int(var, value);
22
- return 0;
23
- }
24
-
25
- return git_default_config(var, value);
26
-}
16
+static int diff_rename_limit_default = -1;
17
+static int diff_use_color_default = 0;
18
19
enum color_diff {
20
DIFF_RESET = 0,
42
#define COLOR_CYAN "\033[36m"
43
#define COLOR_WHITE "\033[37m"
44
54
-#define COLOR_CYANBG "\033[46m"
55
-#define COLOR_GRAYBG "\033[47m" // Good for xterm
56
-
45
static const char *diff_colors[] = {
46
[DIFF_RESET] = COLOR_RESET,
47
[DIFF_PLAIN] = COLOR_NORMAL,
51
[DIFF_FILE_NEW] = COLOR_GREEN,
52
};
53
54
+static int parse_diff_color_slot(const char *var, int ofs)
55
+{
56
+ if (!strcasecmp(var+ofs, "plain"))
57
+ return DIFF_PLAIN;
58
+ if (!strcasecmp(var+ofs, "meta"))
59
+ return DIFF_METAINFO;
60
+ if (!strcasecmp(var+ofs, "frag"))
61
+ return DIFF_FRAGINFO;
62
+ if (!strcasecmp(var+ofs, "old"))
63
+ return DIFF_FILE_OLD;
64
+ if (!strcasecmp(var+ofs, "new"))
65
+ return DIFF_FILE_NEW;
66
+ die("bad config variable '%s'", var);
67
+}
68
+
69
+static const char *parse_diff_color_value(const char *value, const char *var)
70
+{
71
+ if (!strcasecmp(value, "normal"))
72
+ return COLOR_NORMAL;
73
+ if (!strcasecmp(value, "bold"))
74
+ return COLOR_BOLD;
75
+ if (!strcasecmp(value, "dim"))
76
+ return COLOR_DIM;
77
+ if (!strcasecmp(value, "ul"))
78
+ return COLOR_UL;
79
+ if (!strcasecmp(value, "blink"))
80
+ return COLOR_BLINK;
81
+ if (!strcasecmp(value, "reverse"))
82
+ return COLOR_REVERSE;
83
+ if (!strcasecmp(value, "reset"))
84
+ return COLOR_RESET;
85
+ if (!strcasecmp(value, "black"))
86
+ return COLOR_BLACK;
87
+ if (!strcasecmp(value, "red"))
88
+ return COLOR_RED;
89
+ if (!strcasecmp(value, "green"))
90
+ return COLOR_GREEN;
91
+ if (!strcasecmp(value, "yellow"))
92
+ return COLOR_YELLOW;
93
+ if (!strcasecmp(value, "blue"))
94
+ return COLOR_BLUE;
95
+ if (!strcasecmp(value, "magenta"))
96
+ return COLOR_MAGENTA;
97
+ if (!strcasecmp(value, "cyan"))
98
+ return COLOR_CYAN;
99
+ if (!strcasecmp(value, "white"))
100
+ return COLOR_WHITE;
101
+ die("bad config value '%s' for variable '%s'", value, var);
102
+}
103
+
104
+int git_diff_config(const char *var, const char *value)
105
+{
106
+ if (!strcmp(var, "diff.renamelimit")) {
107
+ diff_rename_limit_default = git_config_int(var, value);
108
+ return 0;
109
+ }
110
+ if (!strcmp(var, "diff.color")) {
111
+ if (!value)
112
+ diff_use_color_default = 1; /* bool */
113
+ else if (!strcasecmp(value, "auto"))
114
+ diff_use_color_default = isatty(1);
115
+ else if (!strcasecmp(value, "never"))
116
+ diff_use_color_default = 0;
117
+ else if (!strcasecmp(value, "always"))
118
+ diff_use_color_default = 1;
119
+ else
120
+ diff_use_color_default = git_config_bool(var, value);
121
+ return 0;
122
+ }
123
+ if (!strncmp(var, "diff.color.", 11)) {
124
+ int slot = parse_diff_color_slot(var, 11);
125
+ diff_colors[slot] = parse_diff_color_value(value, var);
126
+ return 0;
127
+ }
128
+ return git_default_config(var, value);
129
+}
130
+
131
static char *quote_one(const char *str)
132
{
133
int needlen;
1427
1428
options->change = diff_change;
1429
options->add_remove = diff_addremove;
1430
+ options->color_diff = diff_use_color_default;
1431
}
1432
1433
int diff_setup_done(struct diff_options *options)