@matheusbsbs / matheus-bagliano / commits / 0e854a280a
Fork 0

git config: reorganize get_color*

In preparation for parseopt. Also remove some unecessary comments since the usage is described in the documentation. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed Feb 21, 2009 at 02:48 UTC 0e854a280a0b064f48ee308ef16283e321a9aa6e
1 file changed +18 -44
builtin-config.c
+18 -44
@@ -192,29 +192,8 @@ static int git_get_color_config(const char *var, const char *value, void *cb)
192 return 0;
193 }
194
195 -static int get_color(int argc, const char **argv)
195 +static void get_color(const char *def_color)
196 {
197 - /*
198 - * grab the color setting for the given slot from the configuration,
199 - * or parse the default value if missing, and return ANSI color
200 - * escape sequence.
201 - *
202 - * e.g.
203 - * git config --get-color color.diff.whitespace "blue reverse"
204 - */
205 - const char *def_color = NULL;
206 -
207 - switch (argc) {
208 - default:
209 - usage(git_config_set_usage);
210 - case 2:
211 - def_color = argv[1];
212 - /* fallthru */
213 - case 1:
214 - get_color_slot = argv[0];
215 - break;
216 - }
217 -
197 get_color_found = 0;
198 parsed_color[0] = '\0';
199 git_config(git_get_color_config, NULL);
@@ -223,7 +202,6 @@ static int get_color(int argc, const char **argv)
202 color_parse(def_color, "command line", parsed_color);
203
204 fputs(parsed_color, stdout);
226 - return 0;
205 }
206
207 static int stdout_is_tty;
@@ -247,24 +225,10 @@ static int git_get_colorbool_config(const char *var, const char *value,
225 return 0;
226 }
227
250 -static int get_colorbool(int argc, const char **argv)
228 +static int get_colorbool(int print)
229 {
252 - /*
253 - * git config --get-colorbool <slot> [<stdout-is-tty>]
254 - *
255 - * returns "true" or "false" depending on how <slot>
256 - * is configured.
257 - */
258 -
259 - if (argc == 2)
260 - stdout_is_tty = git_config_bool("command line", argv[1]);
261 - else if (argc == 1)
262 - stdout_is_tty = isatty(1);
263 - else
264 - usage(git_config_set_usage);
230 get_colorbool_found = -1;
231 get_diff_color_found = -1;
267 - get_colorbool_slot = argv[0];
232 git_config(git_get_colorbool_config, NULL);
233
234 if (get_colorbool_found < 0) {
@@ -274,12 +238,11 @@ static int get_colorbool(int argc, const char **argv)
238 get_colorbool_found = git_use_color_default;
239 }
240
277 - if (argc == 1) {
278 - return get_colorbool_found ? 0 : 1;
279 - } else {
241 + if (print) {
242 printf("%s\n", get_colorbool_found ? "true" : "false");
243 return 0;
282 - }
244 + } else
245 + return get_colorbool_found ? 0 : 1;
246 }
247
248 int cmd_config(int argc, const char **argv, const char *unused_prefix)
@@ -363,9 +326,20 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)
326 }
327 return 0;
328 } else if (!strcmp(argv[1], "--get-color")) {
366 - return get_color(argc-2, argv+2);
329 + if (argc > 4 || argc < 3)
330 + usage(git_config_set_usage);
331 + get_color_slot = argv[2];
332 + get_color(argv[3]);
333 + return 0;
334 } else if (!strcmp(argv[1], "--get-colorbool")) {
368 - return get_colorbool(argc-2, argv+2);
335 + if (argc == 4)
336 + stdout_is_tty = git_config_bool("command line", argv[3]);
337 + else if (argc == 3)
338 + stdout_is_tty = isatty(1);
339 + else
340 + usage(git_config_set_usage);
341 + get_colorbool_slot = argv[2];
342 + return get_colorbool(argc != 3);
343 } else if (!strcmp(argv[1], "--edit") || !strcmp(argv[1], "-e")) {
344 if (argc != 2)
345 usage(git_config_set_usage);