@matheusbsbs / matheus-bagliano / commits / 806e2ad7fe
Fork 0

Split up default "core" config parsing into helper routine

It makes the code a bit easier to read, and in theory a bit faster too (no need to compare all the different "core.*" strings against non-core config options). The config system really should get something of a complete overhaul, but in the absense of that, this at least improves on it a tiny bit. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Torvalds committed Jun 18, 2008 at 14:37 UTC 806e2ad7fe2d94e1ecae904c33b822b3dfac57f6
1 file changed +26 -16
config.c
+26 -16
@@ -332,7 +332,7 @@ int git_config_string(const char **dest, const char *var, const char *value)
332 return 0;
333 }
334
335 -int git_default_config(const char *var, const char *value, void *dummy)
335 +static int git_default_core_config(const char *var, const char *value)
336 {
337 /* This needs a better name */
338 if (!strcmp(var, "core.filemode")) {
@@ -444,6 +444,31 @@ int git_default_config(const char *var, const char *value, void *dummy)
444 return 0;
445 }
446
447 + if (!strcmp(var, "core.pager"))
448 + return git_config_string(&pager_program, var, value);
449 +
450 + if (!strcmp(var, "core.editor"))
451 + return git_config_string(&editor_program, var, value);
452 +
453 + if (!strcmp(var, "core.excludesfile"))
454 + return git_config_string(&excludes_file, var, value);
455 +
456 + if (!strcmp(var, "core.whitespace")) {
457 + if (!value)
458 + return config_error_nonbool(var);
459 + whitespace_rule_cfg = parse_whitespace_rule(value);
460 + return 0;
461 + }
462 +
463 + /* Add other config variables here and to Documentation/config.txt. */
464 + return 0;
465 +}
466 +
467 +int git_default_config(const char *var, const char *value, void *dummy)
468 +{
469 + if (!prefixcmp(var, "core."))
470 + return git_default_core_config(var, value);
471 +
472 if (!strcmp(var, "user.name")) {
473 if (!value)
474 return config_error_nonbool(var);
@@ -473,21 +498,6 @@ int git_default_config(const char *var, const char *value, void *dummy)
498 return 0;
499 }
500
476 - if (!strcmp(var, "core.pager"))
477 - return git_config_string(&pager_program, var, value);
478 -
479 - if (!strcmp(var, "core.editor"))
480 - return git_config_string(&editor_program, var, value);
481 -
482 - if (!strcmp(var, "core.excludesfile"))
483 - return git_config_string(&excludes_file, var, value);
484 -
485 - if (!strcmp(var, "core.whitespace")) {
486 - if (!value)
487 - return config_error_nonbool(var);
488 - whitespace_rule_cfg = parse_whitespace_rule(value);
489 - return 0;
490 - }
501 if (!strcmp(var, "branch.autosetupmerge")) {
502 if (value && !strcasecmp(value, "always")) {
503 git_branch_track = BRANCH_TRACK_ALWAYS;