Blame src/config.h

Packit ae9e2a
/*
Packit ae9e2a
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit ae9e2a
 *
Packit ae9e2a
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit ae9e2a
 * a Linking Exception. For full terms see the included COPYING file.
Packit ae9e2a
 */
Packit ae9e2a
#ifndef INCLUDE_config_h__
Packit ae9e2a
#define INCLUDE_config_h__
Packit ae9e2a
Packit ae9e2a
#include "git2.h"
Packit ae9e2a
#include "git2/config.h"
Packit ae9e2a
#include "vector.h"
Packit ae9e2a
#include "repository.h"
Packit ae9e2a
Packit ae9e2a
#define GIT_CONFIG_FILENAME_PROGRAMDATA "config"
Packit ae9e2a
#define GIT_CONFIG_FILENAME_SYSTEM "gitconfig"
Packit ae9e2a
#define GIT_CONFIG_FILENAME_GLOBAL ".gitconfig"
Packit ae9e2a
#define GIT_CONFIG_FILENAME_XDG    "config"
Packit ae9e2a
Packit ae9e2a
#define GIT_CONFIG_FILENAME_INREPO "config"
Packit ae9e2a
#define GIT_CONFIG_FILE_MODE 0666
Packit ae9e2a
Packit ae9e2a
struct git_config {
Packit ae9e2a
	git_refcount rc;
Packit ae9e2a
	git_vector files;
Packit ae9e2a
};
Packit ae9e2a
Packit ae9e2a
extern int git_config__global_location(git_buf *buf);
Packit ae9e2a
Packit ae9e2a
extern int git_config_rename_section(
Packit ae9e2a
	git_repository *repo,
Packit ae9e2a
	const char *old_section_name,	/* eg "branch.dummy" */
Packit ae9e2a
	const char *new_section_name);	/* NULL to drop the old section */
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Create a configuration file backend for ondisk files
Packit ae9e2a
 *
Packit ae9e2a
 * These are the normal `.gitconfig` files that Core Git
Packit ae9e2a
 * processes. Note that you first have to add this file to a
Packit ae9e2a
 * configuration object before you can query it for configuration
Packit ae9e2a
 * variables.
Packit ae9e2a
 *
Packit ae9e2a
 * @param out the new backend
Packit ae9e2a
 * @param path where the config file is located
Packit ae9e2a
 */
Packit ae9e2a
extern int git_config_file__ondisk(git_config_backend **out, const char *path);
Packit ae9e2a
Packit ae9e2a
extern int git_config__normalize_name(const char *in, char **out);
Packit ae9e2a
Packit ae9e2a
/* internal only: does not normalize key and sets out to NULL if not found */
Packit ae9e2a
extern int git_config__lookup_entry(
Packit ae9e2a
	git_config_entry **out,
Packit ae9e2a
	const git_config *cfg,
Packit ae9e2a
	const char *key,
Packit ae9e2a
	bool no_errors);
Packit ae9e2a
Packit ae9e2a
/* internal only: update and/or delete entry string with constraints */
Packit ae9e2a
extern int git_config__update_entry(
Packit ae9e2a
	git_config *cfg,
Packit ae9e2a
	const char *key,
Packit ae9e2a
	const char *value,
Packit ae9e2a
	bool overwrite_existing,
Packit ae9e2a
	bool only_if_existing);
Packit ae9e2a
Packit ae9e2a
/*
Packit ae9e2a
 * Lookup functions that cannot fail.  These functions look up a config
Packit ae9e2a
 * value and return a fallback value if the value is missing or if any
Packit ae9e2a
 * failures occur while trying to access the value.
Packit ae9e2a
 */
Packit ae9e2a
Packit ae9e2a
extern char *git_config__get_string_force(
Packit ae9e2a
	const git_config *cfg, const char *key, const char *fallback_value);
Packit ae9e2a
Packit ae9e2a
extern int git_config__get_bool_force(
Packit ae9e2a
	const git_config *cfg, const char *key, int fallback_value);
Packit ae9e2a
Packit ae9e2a
extern int git_config__get_int_force(
Packit ae9e2a
	const git_config *cfg, const char *key, int fallback_value);
Packit ae9e2a
Packit ae9e2a
/* API for repository cvar-style lookups from config - not cached, but
Packit ae9e2a
 * uses cvar value maps and fallbacks
Packit ae9e2a
 */
Packit ae9e2a
extern int git_config__cvar(
Packit ae9e2a
	int *out, git_config *config, git_cvar_cached cvar);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * The opposite of git_config_lookup_map_value, we take an enum value
Packit ae9e2a
 * and map it to the string or bool value on the config.
Packit ae9e2a
 */
Packit ae9e2a
int git_config_lookup_map_enum(git_cvar_t *type_out, const char **str_out,
Packit ae9e2a
			       const git_cvar_map *maps, size_t map_n, int enum_val);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Unlock the backend with the highest priority
Packit ae9e2a
 *
Packit ae9e2a
 * Unlocking will allow other writers to updat the configuration
Packit ae9e2a
 * file. Optionally, any changes performed since the lock will be
Packit ae9e2a
 * applied to the configuration.
Packit ae9e2a
 *
Packit ae9e2a
 * @param cfg the configuration
Packit ae9e2a
 * @param commit boolean which indicates whether to commit any changes
Packit ae9e2a
 * done since locking
Packit ae9e2a
 * @return 0 or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_config_unlock(git_config *cfg, int commit);
Packit ae9e2a
Packit ae9e2a
#endif