Пример #1
0
int git_config_early(config_fn_t fn, void *data, const char *repo_config)
{
	int ret = 0, found = 0;
	const char *home = NULL;

	/* Setting $GIT_CONFIG makes git read _only_ the given config file. */
	if (config_exclusive_filename)
		return git_config_from_file(fn, config_exclusive_filename, data);
	if (git_config_system() && !access(git_etc_gitconfig(), R_OK)) {
		ret += git_config_from_file(fn, git_etc_gitconfig(),
					    data);
		found += 1;
	}

	home = getenv("HOME");
	if (home) {
		char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
		if (!access(user_config, R_OK)) {
			ret += git_config_from_file(fn, user_config, data);
			found += 1;
		}
		free(user_config);
	}

	if (repo_config && !access(repo_config, R_OK)) {
		ret += git_config_from_file(fn, repo_config, data);
		found += 1;
	}

	ret += git_config_from_parameters(fn, data);
	if (config_parameters)
		found += 1;

	return ret == 0 ? found : ret;
}
Пример #2
0
static int module_sanitize_config(int argc, const char **argv, const char *prefix)
{
	struct strbuf sanitized_config = STRBUF_INIT;

	if (argc > 1)
		usage(_("git submodule--helper sanitize-config"));

	git_config_from_parameters(sanitize_submodule_config, &sanitized_config);
	if (sanitized_config.len)
		printf("%s\n", sanitized_config.buf);

	strbuf_release(&sanitized_config);

	return 0;
}
Пример #3
0
static void prepare_submodule_repo_env(struct argv_array *out)
{
	const char * const *var;

	for (var = local_repo_env; *var; var++) {
		if (!strcmp(*var, CONFIG_DATA_ENVIRONMENT)) {
			struct strbuf sanitized_config = STRBUF_INIT;
			git_config_from_parameters(sanitize_submodule_config,
						   &sanitized_config);
			argv_array_pushf(out, "%s=%s", *var, sanitized_config.buf);
			strbuf_release(&sanitized_config);
		} else {
			argv_array_push(out, *var);
		}
	}

}
Пример #4
0
int git_config_early(config_fn_t fn, void *data, const char *repo_config)
{
	int ret = 0, found = 0;
	const char *home = NULL;

	/* Setting $GIT_CONFIG makes git read _only_ the given config file. */
	if (config_exclusive_filename)
		return git_config_from_file(fn, config_exclusive_filename, data);
	if (git_config_system() && !access(git_etc_gitconfig(), R_OK)) {
		ret += git_config_from_file(fn, git_etc_gitconfig(),
					    data);
		found += 1;
	}

	home = getenv("HOME");
	if (home) {
		char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
		if (!access(user_config, R_OK)) {
			ret += git_config_from_file(fn, user_config, data);
			found += 1;
		}
		free(user_config);
	}

	if (repo_config && !access(repo_config, R_OK)) {
		ret += git_config_from_file(fn, repo_config, data);
		found += 1;
	}

	switch (git_config_from_parameters(fn, data)) {
	case -1: /* error */
		die("unable to parse command-line config");
		break;
	case 0: /* found nothing */
		break;
	default: /* found at least one item */
		found++;
		break;
	}

	return ret == 0 ? found : ret;
}
Пример #5
0
static int get_value(const char *key_, const char *regex_)
{
    int ret = -1;
    char *global = NULL, *xdg = NULL, *repo_config = NULL;
    const char *system_wide = NULL, *local;
    struct config_include_data inc = CONFIG_INCLUDE_INIT;
    config_fn_t fn;
    void *data;

    local = given_config_file;
    if (!local) {
        local = repo_config = git_pathdup("config");
        if (git_config_system())
            system_wide = git_etc_gitconfig();
        home_config_paths(&global, &xdg, "config");
    }

    if (use_key_regexp) {
        char *tl;

        /*
         * NEEDSWORK: this naive pattern lowercasing obviously does not
         * work for more complex patterns like "^[^.]*Foo.*bar".
         * Perhaps we should deprecate this altogether someday.
         */

        key = xstrdup(key_);
        for (tl = key + strlen(key) - 1;
                tl >= key && *tl != '.';
                tl--)
            *tl = tolower(*tl);
        for (tl = key; *tl && *tl != '.'; tl++)
            *tl = tolower(*tl);

        key_regexp = (regex_t*)xmalloc(sizeof(regex_t));
        if (regcomp(key_regexp, key, REG_EXTENDED)) {
            fprintf(stderr, "Invalid key pattern: %s\n", key_);
            free(key);
            goto free_strings;
        }
    } else {
        if (git_config_parse_key(key_, &key, NULL))
            goto free_strings;
    }

    if (regex_) {
        if (regex_[0] == '!') {
            do_not_match = 1;
            regex_++;
        }

        regexp = (regex_t*)xmalloc(sizeof(regex_t));
        if (regcomp(regexp, regex_, REG_EXTENDED)) {
            fprintf(stderr, "Invalid pattern: %s\n", regex_);
            goto free_strings;
        }
    }

    fn = show_config;
    data = NULL;
    if (respect_includes) {
        inc.fn = fn;
        inc.data = data;
        fn = git_config_include;
        data = &inc;
    }

    if (do_all && system_wide)
        git_config_from_file(fn, system_wide, data);
    if (do_all && xdg)
        git_config_from_file(fn, xdg, data);
    if (do_all && global)
        git_config_from_file(fn, global, data);
    if (do_all)
        git_config_from_file(fn, local, data);
    git_config_from_parameters(fn, data);
    if (!do_all && !seen)
        git_config_from_file(fn, local, data);
    if (!do_all && !seen && global)
        git_config_from_file(fn, global, data);
    if (!do_all && !seen && xdg)
        git_config_from_file(fn, xdg, data);
    if (!do_all && !seen && system_wide)
        git_config_from_file(fn, system_wide, data);

    free(key);
    if (regexp) {
        regfree(regexp);
        free(regexp);
    }

    if (do_all)
        ret = !seen;
    else
        ret = (seen == 1) ? 0 : seen > 1 ? 2 : 1;

free_strings:
    free(repo_config);
    free(global);
    free(xdg);
    return ret;
}
Пример #6
0
static int get_value(const char *key_, const char *regex_)
{
	int ret = -1;
	char *global = NULL, *repo_config = NULL;
	const char *system_wide = NULL, *local;

	local = config_exclusive_filename;
	if (!local) {
		const char *home = getenv("HOME");
		local = repo_config = git_pathdup("config");
		if (home)
			global = xstrdup(mkpath("%s/.gitconfig", home));
		if (git_config_system())
			system_wide = git_etc_gitconfig();
	}

	if (use_key_regexp) {
		char *tl;

		/*
		 * NEEDSWORK: this naive pattern lowercasing obviously does not
		 * work for more complex patterns like "^[^.]*Foo.*bar".
		 * Perhaps we should deprecate this altogether someday.
		 */

		key = xstrdup(key_);
		for (tl = key + strlen(key) - 1;
		     tl >= key && *tl != '.';
		     tl--)
			*tl = tolower(*tl);
		for (tl = key; *tl && *tl != '.'; tl++)
			*tl = tolower(*tl);

		key_regexp = (regex_t*)xmalloc(sizeof(regex_t));
		if (regcomp(key_regexp, key, REG_EXTENDED)) {
			fprintf(stderr, "Invalid key pattern: %s\n", key_);
			free(key);
			goto free_strings;
		}
	} else {
		if (git_config_parse_key(key_, &key, NULL))
			goto free_strings;
	}

	if (regex_) {
		if (regex_[0] == '!') {
			do_not_match = 1;
			regex_++;
		}

		regexp = (regex_t*)xmalloc(sizeof(regex_t));
		if (regcomp(regexp, regex_, REG_EXTENDED)) {
			fprintf(stderr, "Invalid pattern: %s\n", regex_);
			goto free_strings;
		}
	}

	if (do_all && system_wide)
		git_config_from_file(show_config, system_wide, NULL);
	if (do_all && global)
		git_config_from_file(show_config, global, NULL);
	if (do_all)
		git_config_from_file(show_config, local, NULL);
	git_config_from_parameters(show_config, NULL);
	if (!do_all && !seen)
		git_config_from_file(show_config, local, NULL);
	if (!do_all && !seen && global)
		git_config_from_file(show_config, global, NULL);
	if (!do_all && !seen && system_wide)
		git_config_from_file(show_config, system_wide, NULL);

	free(key);
	if (regexp) {
		regfree(regexp);
		free(regexp);
	}

	if (do_all)
		ret = !seen;
	else
		ret = (seen == 1) ? 0 : seen > 1 ? 2 : 1;

free_strings:
	free(repo_config);
	free(global);
	return ret;
}