MCPcopy Create free account
hub / github.com/git/git / normalize_value

Function normalize_value

builtin/config.c:654–704  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

652}
653
654static char *normalize_value(const char *key, const char *value,
655 int type, struct key_value_info *kvi)
656{
657 if (!value)
658 return NULL;
659
660 if (type == 0 || type == TYPE_PATH || type == TYPE_EXPIRY_DATE)
661 /*
662 * We don't do normalization for TYPE_PATH here: If
663 * the path is like ~/foobar/, we prefer to store
664 * "~/foobar/" in the config file, and to expand the ~
665 * when retrieving the value.
666 * Also don't do normalization for expiry dates.
667 */
668 return xstrdup(value);
669 if (type == TYPE_INT)
670 return xstrfmt("%"PRId64, git_config_int64(key, value, kvi));
671 if (type == TYPE_BOOL)
672 return xstrdup(git_config_bool(key, value) ? "true" : "false");
673 if (type == TYPE_BOOL_OR_INT) {
674 int is_bool, v;
675 v = git_config_bool_or_int(key, value, kvi, &is_bool);
676 if (!is_bool)
677 return xstrfmt("%d", v);
678 else
679 return xstrdup(v ? "true" : "false");
680 }
681 if (type == TYPE_BOOL_OR_STR) {
682 int v = git_parse_maybe_bool(value);
683 if (v < 0)
684 return xstrdup(value);
685 else
686 return xstrdup(v ? "true" : "false");
687 }
688 if (type == TYPE_COLOR) {
689 char v[COLOR_MAXLEN];
690 if (git_config_color(v, key, value))
691 die(_("cannot parse color '%s'"), value);
692
693 /*
694 * The contents of `v` now contain an ANSI escape
695 * sequence, not suitable for including within a
696 * configuration file. Treat the above as a
697 * "sanity-check", and return the given value, which we
698 * know is representable as valid color code.
699 */
700 return xstrdup(value);
701 }
702
703 BUG("cannot normalize type %d", type);
704}
705
706struct get_color_config_data {
707 int get_color_found;

Callers 2

cmd_config_setFunction · 0.85
cmd_config_actionsFunction · 0.85

Calls 8

xstrdupFunction · 0.85
xstrfmtFunction · 0.85
git_config_int64Function · 0.85
git_config_boolFunction · 0.85
git_config_bool_or_intFunction · 0.85
git_parse_maybe_boolFunction · 0.85
git_config_colorFunction · 0.85
dieFunction · 0.50

Tested by

no test coverage detected