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

Function get_value

builtin/config.c:538–652  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

536}
537
538static int get_value(const struct config_location_options *opts,
539 const struct config_display_options *display_opts,
540 const char *key_, const char *regex_,
541 unsigned get_value_flags, unsigned flags)
542{
543 int ret = CONFIG_GENERIC_ERROR;
544 struct strbuf_list values = {NULL};
545 struct collect_config_data data = {
546 .display_opts = display_opts,
547 .values = &values,
548 .get_value_flags = get_value_flags,
549 .flags = flags,
550 };
551 char *key = NULL;
552 int i;
553
554 if (get_value_flags & GET_VALUE_KEY_REGEXP) {
555 char *tl;
556
557 /*
558 * NEEDSWORK: this naive pattern lowercasing obviously does not
559 * work for more complex patterns like "^[^.]*Foo.*bar".
560 * Perhaps we should deprecate this altogether someday.
561 */
562
563 key = xstrdup(key_);
564 for (tl = key + strlen(key) - 1;
565 tl >= key && *tl != '.';
566 tl--)
567 *tl = tolower(*tl);
568 for (tl = key; *tl && *tl != '.'; tl++)
569 *tl = tolower(*tl);
570
571 data.key_regexp = (regex_t*)xmalloc(sizeof(regex_t));
572 if (regcomp(data.key_regexp, key, REG_EXTENDED)) {
573 error(_("invalid key pattern: %s"), key_);
574 FREE_AND_NULL(data.key_regexp);
575 ret = CONFIG_INVALID_PATTERN;
576 goto free_strings;
577 }
578 } else {
579 if (git_config_parse_key(key_, &key, NULL)) {
580 ret = CONFIG_INVALID_KEY;
581 goto free_strings;
582 }
583
584 data.key = key;
585 }
586
587 if (regex_ && (flags & CONFIG_FLAGS_FIXED_VALUE))
588 data.value_pattern = regex_;
589 else if (regex_) {
590 if (regex_[0] == '!') {
591 data.do_not_match = 1;
592 regex_++;
593 }
594
595 data.regexp = (regex_t*)xmalloc(sizeof(regex_t));

Callers 2

cmd_config_getFunction · 0.70
cmd_config_actionsFunction · 0.70

Calls 12

xstrdupFunction · 0.85
regcompFunction · 0.85
errorFunction · 0.85
git_config_parse_keyFunction · 0.85
config_with_optionsFunction · 0.85
kvi_from_paramFunction · 0.85
strbuf_initFunction · 0.85
strbuf_releaseFunction · 0.85
regfreeFunction · 0.85
format_configFunction · 0.70
xmallocFunction · 0.50
dieFunction · 0.50

Tested by

no test coverage detected