Blame include/git2/config.h

Packit Service 20376f
/*
Packit Service 20376f
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit Service 20376f
 *
Packit Service 20376f
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit Service 20376f
 * a Linking Exception. For full terms see the included COPYING file.
Packit Service 20376f
 */
Packit Service 20376f
#ifndef INCLUDE_git_config_h__
Packit Service 20376f
#define INCLUDE_git_config_h__
Packit Service 20376f
Packit Service 20376f
#include "common.h"
Packit Service 20376f
#include "types.h"
Packit Service 20376f
#include "buffer.h"
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * @file git2/config.h
Packit Service 20376f
 * @brief Git config management routines
Packit Service 20376f
 * @defgroup git_config Git config management routines
Packit Service 20376f
 * @ingroup Git
Packit Service 20376f
 * @{
Packit Service 20376f
 */
Packit Service 20376f
GIT_BEGIN_DECL
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Priority level of a config file.
Packit Service 20376f
 * These priority levels correspond to the natural escalation logic
Packit Service 20376f
 * (from higher to lower) when searching for config entries in git.git.
Packit Service 20376f
 *
Packit Service 20376f
 * git_config_open_default() and git_repository_config() honor those
Packit Service 20376f
 * priority levels as well.
Packit Service 20376f
 */
Packit Service 20376f
typedef enum {
Packit Service 20376f
	/** System-wide on Windows, for compatibility with portable git */
Packit Service 20376f
	GIT_CONFIG_LEVEL_PROGRAMDATA = 1,
Packit Service 20376f
Packit Service 20376f
	/** System-wide configuration file; /etc/gitconfig on Linux systems */
Packit Service 20376f
	GIT_CONFIG_LEVEL_SYSTEM = 2,
Packit Service 20376f
Packit Service 20376f
	/** XDG compatible configuration file; typically ~/.config/git/config */
Packit Service 20376f
	GIT_CONFIG_LEVEL_XDG = 3,
Packit Service 20376f
Packit Service 20376f
	/** User-specific configuration file (also called Global configuration
Packit Service 20376f
	 * file); typically ~/.gitconfig
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_CONFIG_LEVEL_GLOBAL = 4,
Packit Service 20376f
Packit Service 20376f
	/** Repository specific configuration file; $WORK_DIR/.git/config on
Packit Service 20376f
	 * non-bare repos
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_CONFIG_LEVEL_LOCAL = 5,
Packit Service 20376f
Packit Service 20376f
	/** Application specific configuration file; freely defined by applications
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_CONFIG_LEVEL_APP = 6,
Packit Service 20376f
Packit Service 20376f
	/** Represents the highest level available config file (i.e. the most
Packit Service 20376f
	 * specific config file available that actually is loaded)
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_CONFIG_HIGHEST_LEVEL = -1,
Packit Service 20376f
} git_config_level_t;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * An entry in a configuration file
Packit Service 20376f
 */
Packit Service 20376f
typedef struct git_config_entry {
Packit Service 20376f
	const char *name; /**< Name of the entry (normalised) */
Packit Service 20376f
	const char *value; /**< String value of the entry */
Packit Service 20376f
	git_config_level_t level; /**< Which config file this was found in */
Packit Service 20376f
	void (*free)(struct git_config_entry *entry); /**< Free function for this entry */
Packit Service 20376f
	void *payload; /**< Opaque value for the free function. Do not read or write */
Packit Service 20376f
} git_config_entry;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Free a config entry
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(void) git_config_entry_free(git_config_entry *);
Packit Service 20376f
Packit Service 20376f
typedef int  (*git_config_foreach_cb)(const git_config_entry *, void *);
Packit Service 20376f
typedef struct git_config_iterator git_config_iterator;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Config var type
Packit Service 20376f
 */
Packit Service 20376f
typedef enum {
Packit Service 20376f
	GIT_CVAR_FALSE = 0,
Packit Service 20376f
	GIT_CVAR_TRUE = 1,
Packit Service 20376f
	GIT_CVAR_INT32,
Packit Service 20376f
	GIT_CVAR_STRING
Packit Service 20376f
} git_cvar_t;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Mapping from config variables to values.
Packit Service 20376f
 */
Packit Service 20376f
typedef struct {
Packit Service 20376f
	git_cvar_t cvar_type;
Packit Service 20376f
	const char *str_match;
Packit Service 20376f
	int map_value;
Packit Service 20376f
} git_cvar_map;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Locate the path to the global configuration file
Packit Service 20376f
 *
Packit Service 20376f
 * The user or global configuration file is usually
Packit Service 20376f
 * located in `$HOME/.gitconfig`.
Packit Service 20376f
 *
Packit Service 20376f
 * This method will try to guess the full path to that
Packit Service 20376f
 * file, if the file exists. The returned path
Packit Service 20376f
 * may be used on any `git_config` call to load the
Packit Service 20376f
 * global configuration file.
Packit Service 20376f
 *
Packit Service 20376f
 * This method will not guess the path to the xdg compatible
Packit Service 20376f
 * config file (.config/git/config).
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Pointer to a user-allocated git_buf in which to store the path
Packit Service 20376f
 * @return 0 if a global configuration file has been found. Its path will be stored in `out`.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_find_global(git_buf *out);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Locate the path to the global xdg compatible configuration file
Packit Service 20376f
 *
Packit Service 20376f
 * The xdg compatible configuration file is usually
Packit Service 20376f
 * located in `$HOME/.config/git/config`.
Packit Service 20376f
 *
Packit Service 20376f
 * This method will try to guess the full path to that
Packit Service 20376f
 * file, if the file exists. The returned path
Packit Service 20376f
 * may be used on any `git_config` call to load the
Packit Service 20376f
 * xdg compatible configuration file.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Pointer to a user-allocated git_buf in which to store the path
Packit Service 20376f
 * @return 0 if a xdg compatible configuration file has been
Packit Service 20376f
 *	found. Its path will be stored in `out`.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_find_xdg(git_buf *out);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Locate the path to the system configuration file
Packit Service 20376f
 *
Packit Service 20376f
 * If /etc/gitconfig doesn't exist, it will look for
Packit Service 20376f
 * %PROGRAMFILES%\Git\etc\gitconfig.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Pointer to a user-allocated git_buf in which to store the path
Packit Service 20376f
 * @return 0 if a system configuration file has been
Packit Service 20376f
 *	found. Its path will be stored in `out`.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_find_system(git_buf *out);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Locate the path to the configuration file in ProgramData
Packit Service 20376f
 *
Packit Service 20376f
 * Look for the file in %PROGRAMDATA%\Git\config used by portable git.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Pointer to a user-allocated git_buf in which to store the path
Packit Service 20376f
 * @return 0 if a ProgramData configuration file has been
Packit Service 20376f
 *	found. Its path will be stored in `out`.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_find_programdata(git_buf *out);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Open the global, XDG and system configuration files
Packit Service 20376f
 *
Packit Service 20376f
 * Utility wrapper that finds the global, XDG and system configuration files
Packit Service 20376f
 * and opens them into a single prioritized config object that can be
Packit Service 20376f
 * used when accessing default config data outside a repository.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Pointer to store the config instance
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_open_default(git_config **out);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Allocate a new configuration object
Packit Service 20376f
 *
Packit Service 20376f
 * This object is empty, so you have to add a file to it before you
Packit Service 20376f
 * can do anything with it.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out pointer to the new configuration
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_new(git_config **out);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Add an on-disk config file instance to an existing config
Packit Service 20376f
 *
Packit Service 20376f
 * The on-disk file pointed at by `path` will be opened and
Packit Service 20376f
 * parsed; it's expected to be a native Git config file following
Packit Service 20376f
 * the default Git config syntax (see man git-config).
Packit Service 20376f
 *
Packit Service 20376f
 * If the file does not exist, the file will still be added and it
Packit Service 20376f
 * will be created the first time we write to it.
Packit Service 20376f
 *
Packit Service 20376f
 * Note that the configuration object will free the file
Packit Service 20376f
 * automatically.
Packit Service 20376f
 *
Packit Service 20376f
 * Further queries on this config object will access each
Packit Service 20376f
 * of the config file instances in order (instances with
Packit Service 20376f
 * a higher priority level will be accessed first).
Packit Service 20376f
 *
Packit Service 20376f
 * @param cfg the configuration to add the file to
Packit Service 20376f
 * @param path path to the configuration file to add
Packit Service 20376f
 * @param level the priority level of the backend
Packit Service 20376f
 * @param force replace config file at the given priority level
Packit Service 20376f
 * @return 0 on success, GIT_EEXISTS when adding more than one file
Packit Service 20376f
 *  for a given priority level (and force_replace set to 0),
Packit Service 20376f
 *  GIT_ENOTFOUND when the file doesn't exist or error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_add_file_ondisk(
Packit Service 20376f
	git_config *cfg,
Packit Service 20376f
	const char *path,
Packit Service 20376f
	git_config_level_t level,
Packit Service 20376f
	int force);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Create a new config instance containing a single on-disk file
Packit Service 20376f
 *
Packit Service 20376f
 * This method is a simple utility wrapper for the following sequence
Packit Service 20376f
 * of calls:
Packit Service 20376f
 *	- git_config_new
Packit Service 20376f
 *	- git_config_add_file_ondisk
Packit Service 20376f
 *
Packit Service 20376f
 * @param out The configuration instance to create
Packit Service 20376f
 * @param path Path to the on-disk file to open
Packit Service 20376f
 * @return 0 on success, or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_open_ondisk(git_config **out, const char *path);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Build a single-level focused config object from a multi-level one.
Packit Service 20376f
 *
Packit Service 20376f
 * The returned config object can be used to perform get/set/delete operations
Packit Service 20376f
 * on a single specific level.
Packit Service 20376f
 *
Packit Service 20376f
 * Getting several times the same level from the same parent multi-level config
Packit Service 20376f
 * will return different config instances, but containing the same config_file
Packit Service 20376f
 * instance.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out The configuration instance to create
Packit Service 20376f
 * @param parent Multi-level config to search for the given level
Packit Service 20376f
 * @param level Configuration level to search for
Packit Service 20376f
 * @return 0, GIT_ENOTFOUND if the passed level cannot be found in the
Packit Service 20376f
 * multi-level parent config, or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_open_level(
Packit Service 20376f
	git_config **out,
Packit Service 20376f
	const git_config *parent,
Packit Service 20376f
	git_config_level_t level);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Open the global/XDG configuration file according to git's rules
Packit Service 20376f
 *
Packit Service 20376f
 * Git allows you to store your global configuration at
Packit Service 20376f
 * `$HOME/.config` or `$XDG_CONFIG_HOME/git/config`. For backwards
Packit Service 20376f
 * compatability, the XDG file shouldn't be used unless the use has
Packit Service 20376f
 * created it explicitly. With this function you'll open the correct
Packit Service 20376f
 * one to write to.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out pointer in which to store the config object
Packit Service 20376f
 * @param config the config object in which to look
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_open_global(git_config **out, git_config *config);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Create a snapshot of the configuration
Packit Service 20376f
 *
Packit Service 20376f
 * Create a snapshot of the current state of a configuration, which
Packit Service 20376f
 * allows you to look into a consistent view of the configuration for
Packit Service 20376f
 * looking up complex values (e.g. a remote, submodule).
Packit Service 20376f
 *
Packit Service 20376f
 * The string returned when querying such a config object is valid
Packit Service 20376f
 * until it is freed.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out pointer in which to store the snapshot config object
Packit Service 20376f
 * @param config configuration to snapshot
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_snapshot(git_config **out, git_config *config);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Free the configuration and its associated memory and files
Packit Service 20376f
 *
Packit Service 20376f
 * @param cfg the configuration to free
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(void) git_config_free(git_config *cfg);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the git_config_entry of a config variable.
Packit Service 20376f
 *
Packit Service 20376f
 * Free the git_config_entry after use with `git_config_entry_free()`.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out pointer to the variable git_config_entry
Packit Service 20376f
 * @param cfg where to look for the variable
Packit Service 20376f
 * @param name the variable's name
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_get_entry(
Packit Service 20376f
	git_config_entry **out,
Packit Service 20376f
	const git_config *cfg,
Packit Service 20376f
	const char *name);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the value of an integer config variable.
Packit Service 20376f
 *
Packit Service 20376f
 * All config files will be looked into, in the order of their
Packit Service 20376f
 * defined level. A higher level means a higher priority. The
Packit Service 20376f
 * first occurrence of the variable will be returned here.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out pointer to the variable where the value should be stored
Packit Service 20376f
 * @param cfg where to look for the variable
Packit Service 20376f
 * @param name the variable's name
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_get_int32(int32_t *out, const git_config *cfg, const char *name);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the value of a long integer config variable.
Packit Service 20376f
 *
Packit Service 20376f
 * All config files will be looked into, in the order of their
Packit Service 20376f
 * defined level. A higher level means a higher priority. The
Packit Service 20376f
 * first occurrence of the variable will be returned here.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out pointer to the variable where the value should be stored
Packit Service 20376f
 * @param cfg where to look for the variable
Packit Service 20376f
 * @param name the variable's name
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_get_int64(int64_t *out, const git_config *cfg, const char *name);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the value of a boolean config variable.
Packit Service 20376f
 *
Packit Service 20376f
 * This function uses the usual C convention of 0 being false and
Packit Service 20376f
 * anything else true.
Packit Service 20376f
 *
Packit Service 20376f
 * All config files will be looked into, in the order of their
Packit Service 20376f
 * defined level. A higher level means a higher priority. The
Packit Service 20376f
 * first occurrence of the variable will be returned here.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out pointer to the variable where the value should be stored
Packit Service 20376f
 * @param cfg where to look for the variable
Packit Service 20376f
 * @param name the variable's name
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_get_bool(int *out, const git_config *cfg, const char *name);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the value of a path config variable.
Packit Service 20376f
 *
Packit Service 20376f
 * A leading '~' will be expanded to the global search path (which
Packit Service 20376f
 * defaults to the user's home directory but can be overridden via
Packit Service 20376f
 * `git_libgit2_opts()`.
Packit Service 20376f
 *
Packit Service 20376f
 * All config files will be looked into, in the order of their
Packit Service 20376f
 * defined level. A higher level means a higher priority. The
Packit Service 20376f
 * first occurrence of the variable will be returned here.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out the buffer in which to store the result
Packit Service 20376f
 * @param cfg where to look for the variable
Packit Service 20376f
 * @param name the variable's name
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_get_path(git_buf *out, const git_config *cfg, const char *name);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the value of a string config variable.
Packit Service 20376f
 *
Packit Service 20376f
 * This function can only be used on snapshot config objects. The
Packit Service 20376f
 * string is owned by the config and should not be freed by the
Packit Service 20376f
 * user. The pointer will be valid until the config is freed.
Packit Service 20376f
 *
Packit Service 20376f
 * All config files will be looked into, in the order of their
Packit Service 20376f
 * defined level. A higher level means a higher priority. The
Packit Service 20376f
 * first occurrence of the variable will be returned here.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out pointer to the string
Packit Service 20376f
 * @param cfg where to look for the variable
Packit Service 20376f
 * @param name the variable's name
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_get_string(const char **out, const git_config *cfg, const char *name);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the value of a string config variable.
Packit Service 20376f
 *
Packit Service 20376f
 * The value of the config will be copied into the buffer.
Packit Service 20376f
 *
Packit Service 20376f
 * All config files will be looked into, in the order of their
Packit Service 20376f
 * defined level. A higher level means a higher priority. The
Packit Service 20376f
 * first occurrence of the variable will be returned here.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out buffer in which to store the string
Packit Service 20376f
 * @param cfg where to look for the variable
Packit Service 20376f
 * @param name the variable's name
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_get_string_buf(git_buf *out, const git_config *cfg, const char *name);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get each value of a multivar in a foreach callback
Packit Service 20376f
 *
Packit Service 20376f
 * The callback will be called on each variable found
Packit Service 20376f
 *
Packit Service 20376f
 * @param cfg where to look for the variable
Packit Service 20376f
 * @param name the variable's name
Packit Service 20376f
 * @param regexp regular expression to filter which variables we're
Packit Service 20376f
 * interested in. Use NULL to indicate all
Packit Service 20376f
 * @param callback the function to be called on each value of the variable
Packit Service 20376f
 * @param payload opaque pointer to pass to the callback
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_get_multivar_foreach(const git_config *cfg, const char *name, const char *regexp, git_config_foreach_cb callback, void *payload);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get each value of a multivar
Packit Service 20376f
 *
Packit Service 20376f
 * @param out pointer to store the iterator
Packit Service 20376f
 * @param cfg where to look for the variable
Packit Service 20376f
 * @param name the variable's name
Packit Service 20376f
 * @param regexp regular expression to filter which variables we're
Packit Service 20376f
 * interested in. Use NULL to indicate all
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_multivar_iterator_new(git_config_iterator **out, const git_config *cfg, const char *name, const char *regexp);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Return the current entry and advance the iterator
Packit Service 20376f
 *
Packit Service 20376f
 * The pointers returned by this function are valid until the iterator
Packit Service 20376f
 * is freed.
Packit Service 20376f
 *
Packit Service 20376f
 * @param entry pointer to store the entry
Packit Service 20376f
 * @param iter the iterator
Packit Service 20376f
 * @return 0 or an error code. GIT_ITEROVER if the iteration has completed
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_next(git_config_entry **entry, git_config_iterator *iter);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Free a config iterator
Packit Service 20376f
 *
Packit Service 20376f
 * @param iter the iterator to free
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(void) git_config_iterator_free(git_config_iterator *iter);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Set the value of an integer config variable in the config file
Packit Service 20376f
 * with the highest level (usually the local one).
Packit Service 20376f
 *
Packit Service 20376f
 * @param cfg where to look for the variable
Packit Service 20376f
 * @param name the variable's name
Packit Service 20376f
 * @param value Integer value for the variable
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_set_int32(git_config *cfg, const char *name, int32_t value);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Set the value of a long integer config variable in the config file
Packit Service 20376f
 * with the highest level (usually the local one).
Packit Service 20376f
 *
Packit Service 20376f
 * @param cfg where to look for the variable
Packit Service 20376f
 * @param name the variable's name
Packit Service 20376f
 * @param value Long integer value for the variable
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_set_int64(git_config *cfg, const char *name, int64_t value);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Set the value of a boolean config variable in the config file
Packit Service 20376f
 * with the highest level (usually the local one).
Packit Service 20376f
 *
Packit Service 20376f
 * @param cfg where to look for the variable
Packit Service 20376f
 * @param name the variable's name
Packit Service 20376f
 * @param value the value to store
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_set_bool(git_config *cfg, const char *name, int value);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Set the value of a string config variable in the config file
Packit Service 20376f
 * with the highest level (usually the local one).
Packit Service 20376f
 *
Packit Service 20376f
 * A copy of the string is made and the user is free to use it
Packit Service 20376f
 * afterwards.
Packit Service 20376f
 *
Packit Service 20376f
 * @param cfg where to look for the variable
Packit Service 20376f
 * @param name the variable's name
Packit Service 20376f
 * @param value the string to store.
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_set_string(git_config *cfg, const char *name, const char *value);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Set a multivar in the local config file.
Packit Service 20376f
 *
Packit Service 20376f
 * @param cfg where to look for the variable
Packit Service 20376f
 * @param name the variable's name
Packit Service 20376f
 * @param regexp a regular expression to indicate which values to replace
Packit Service 20376f
 * @param value the new value.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_set_multivar(git_config *cfg, const char *name, const char *regexp, const char *value);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Delete a config variable from the config file
Packit Service 20376f
 * with the highest level (usually the local one).
Packit Service 20376f
 *
Packit Service 20376f
 * @param cfg the configuration
Packit Service 20376f
 * @param name the variable to delete
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_delete_entry(git_config *cfg, const char *name);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Deletes one or several entries from a multivar in the local config file.
Packit Service 20376f
 *
Packit Service 20376f
 * @param cfg where to look for the variables
Packit Service 20376f
 * @param name the variable's name
Packit Service 20376f
 * @param regexp a regular expression to indicate which values to delete
Packit Service 20376f
 *
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_delete_multivar(git_config *cfg, const char *name, const char *regexp);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Perform an operation on each config variable.
Packit Service 20376f
 *
Packit Service 20376f
 * The callback receives the normalized name and value of each variable
Packit Service 20376f
 * in the config backend, and the data pointer passed to this function.
Packit Service 20376f
 * If the callback returns a non-zero value, the function stops iterating
Packit Service 20376f
 * and returns that value to the caller.
Packit Service 20376f
 *
Packit Service 20376f
 * The pointers passed to the callback are only valid as long as the
Packit Service 20376f
 * iteration is ongoing.
Packit Service 20376f
 *
Packit Service 20376f
 * @param cfg where to get the variables from
Packit Service 20376f
 * @param callback the function to call on each variable
Packit Service 20376f
 * @param payload the data to pass to the callback
Packit Service 20376f
 * @return 0 on success, non-zero callback return value, or error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_foreach(
Packit Service 20376f
	const git_config *cfg,
Packit Service 20376f
	git_config_foreach_cb callback,
Packit Service 20376f
	void *payload);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Iterate over all the config variables
Packit Service 20376f
 *
Packit Service 20376f
 * Use `git_config_next` to advance the iteration and
Packit Service 20376f
 * `git_config_iterator_free` when done.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out pointer to store the iterator
Packit Service 20376f
 * @param cfg where to ge the variables from
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_iterator_new(git_config_iterator **out, const git_config *cfg);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Iterate over all the config variables whose name matches a pattern
Packit Service 20376f
 *
Packit Service 20376f
 * Use `git_config_next` to advance the iteration and
Packit Service 20376f
 * `git_config_iterator_free` when done.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out pointer to store the iterator
Packit Service 20376f
 * @param cfg where to ge the variables from
Packit Service 20376f
 * @param regexp regular expression to match the names
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_iterator_glob_new(git_config_iterator **out, const git_config *cfg, const char *regexp);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Perform an operation on each config variable matching a regular expression.
Packit Service 20376f
 *
Packit Service 20376f
 * This behaviors like `git_config_foreach` with an additional filter of a
Packit Service 20376f
 * regular expression that filters which config keys are passed to the
Packit Service 20376f
 * callback.
Packit Service 20376f
 *
Packit Service 20376f
 * The pointers passed to the callback are only valid as long as the
Packit Service 20376f
 * iteration is ongoing.
Packit Service 20376f
 *
Packit Service 20376f
 * @param cfg where to get the variables from
Packit Service 20376f
 * @param regexp regular expression to match against config names
Packit Service 20376f
 * @param callback the function to call on each variable
Packit Service 20376f
 * @param payload the data to pass to the callback
Packit Service 20376f
 * @return 0 or the return value of the callback which didn't return 0
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_foreach_match(
Packit Service 20376f
	const git_config *cfg,
Packit Service 20376f
	const char *regexp,
Packit Service 20376f
	git_config_foreach_cb callback,
Packit Service 20376f
	void *payload);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Query the value of a config variable and return it mapped to
Packit Service 20376f
 * an integer constant.
Packit Service 20376f
 *
Packit Service 20376f
 * This is a helper method to easily map different possible values
Packit Service 20376f
 * to a variable to integer constants that easily identify them.
Packit Service 20376f
 *
Packit Service 20376f
 * A mapping array looks as follows:
Packit Service 20376f
 *
Packit Service 20376f
 *	git_cvar_map autocrlf_mapping[] = {
Packit Service 20376f
 *		{GIT_CVAR_FALSE, NULL, GIT_AUTO_CRLF_FALSE},
Packit Service 20376f
 *		{GIT_CVAR_TRUE, NULL, GIT_AUTO_CRLF_TRUE},
Packit Service 20376f
 *		{GIT_CVAR_STRING, "input", GIT_AUTO_CRLF_INPUT},
Packit Service 20376f
 *		{GIT_CVAR_STRING, "default", GIT_AUTO_CRLF_DEFAULT}};
Packit Service 20376f
 *
Packit Service 20376f
 * On any "false" value for the variable (e.g. "false", "FALSE", "no"), the
Packit Service 20376f
 * mapping will store `GIT_AUTO_CRLF_FALSE` in the `out` parameter.
Packit Service 20376f
 *
Packit Service 20376f
 * The same thing applies for any "true" value such as "true", "yes" or "1", storing
Packit Service 20376f
 * the `GIT_AUTO_CRLF_TRUE` variable.
Packit Service 20376f
 *
Packit Service 20376f
 * Otherwise, if the value matches the string "input" (with case insensitive comparison),
Packit Service 20376f
 * the given constant will be stored in `out`, and likewise for "default".
Packit Service 20376f
 *
Packit Service 20376f
 * If not a single match can be made to store in `out`, an error code will be
Packit Service 20376f
 * returned.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out place to store the result of the mapping
Packit Service 20376f
 * @param cfg config file to get the variables from
Packit Service 20376f
 * @param name name of the config variable to lookup
Packit Service 20376f
 * @param maps array of `git_cvar_map` objects specifying the possible mappings
Packit Service 20376f
 * @param map_n number of mapping objects in `maps`
Packit Service 20376f
 * @return 0 on success, error code otherwise
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_get_mapped(
Packit Service 20376f
	int *out,
Packit Service 20376f
	const git_config *cfg,
Packit Service 20376f
	const char *name,
Packit Service 20376f
	const git_cvar_map *maps,
Packit Service 20376f
	size_t map_n);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Maps a string value to an integer constant
Packit Service 20376f
 *
Packit Service 20376f
 * @param out place to store the result of the parsing
Packit Service 20376f
 * @param maps array of `git_cvar_map` objects specifying the possible mappings
Packit Service 20376f
 * @param map_n number of mapping objects in `maps`
Packit Service 20376f
 * @param value value to parse
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_lookup_map_value(
Packit Service 20376f
	int *out,
Packit Service 20376f
	const git_cvar_map *maps,
Packit Service 20376f
	size_t map_n,
Packit Service 20376f
	const char *value);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Parse a string value as a bool.
Packit Service 20376f
 *
Packit Service 20376f
 * Valid values for true are: 'true', 'yes', 'on', 1 or any
Packit Service 20376f
 *  number different from 0
Packit Service 20376f
 * Valid values for false are: 'false', 'no', 'off', 0
Packit Service 20376f
 *
Packit Service 20376f
 * @param out place to store the result of the parsing
Packit Service 20376f
 * @param value value to parse
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_parse_bool(int *out, const char *value);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Parse a string value as an int32.
Packit Service 20376f
 *
Packit Service 20376f
 * An optional value suffix of 'k', 'm', or 'g' will
Packit Service 20376f
 * cause the value to be multiplied by 1024, 1048576,
Packit Service 20376f
 * or 1073741824 prior to output.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out place to store the result of the parsing
Packit Service 20376f
 * @param value value to parse
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_parse_int32(int32_t *out, const char *value);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Parse a string value as an int64.
Packit Service 20376f
 *
Packit Service 20376f
 * An optional value suffix of 'k', 'm', or 'g' will
Packit Service 20376f
 * cause the value to be multiplied by 1024, 1048576,
Packit Service 20376f
 * or 1073741824 prior to output.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out place to store the result of the parsing
Packit Service 20376f
 * @param value value to parse
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_parse_int64(int64_t *out, const char *value);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Parse a string value as a path.
Packit Service 20376f
 *
Packit Service 20376f
 * A leading '~' will be expanded to the global search path (which
Packit Service 20376f
 * defaults to the user's home directory but can be overridden via
Packit Service 20376f
 * `git_libgit2_opts()`.
Packit Service 20376f
 *
Packit Service 20376f
 * If the value does not begin with a tilde, the input will be
Packit Service 20376f
 * returned.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out placae to store the result of parsing
Packit Service 20376f
 * @param value the path to evaluate
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_parse_path(git_buf *out, const char *value);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Perform an operation on each config variable in given config backend
Packit Service 20376f
 * matching a regular expression.
Packit Service 20376f
 *
Packit Service 20376f
 * This behaviors like `git_config_foreach_match` except instead of all config
Packit Service 20376f
 * entries it just enumerates through the given backend entry.
Packit Service 20376f
 *
Packit Service 20376f
 * @param backend where to get the variables from
Packit Service 20376f
 * @param regexp regular expression to match against config names (can be NULL)
Packit Service 20376f
 * @param callback the function to call on each variable
Packit Service 20376f
 * @param payload the data to pass to the callback
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_backend_foreach_match(
Packit Service 20376f
	git_config_backend *backend,
Packit Service 20376f
	const char *regexp,
Packit Service 20376f
	git_config_foreach_cb callback,
Packit Service 20376f
	void *payload);
Packit Service 20376f
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Lock the backend with the highest priority
Packit Service 20376f
 *
Packit Service 20376f
 * Locking disallows anybody else from writing to that backend. Any
Packit Service 20376f
 * updates made after locking will not be visible to a reader until
Packit Service 20376f
 * the file is unlocked.
Packit Service 20376f
 *
Packit Service 20376f
 * You can apply the changes by calling `git_transaction_commit()`
Packit Service 20376f
 * before freeing the transaction. Either of these actions will unlock
Packit Service 20376f
 * the config.
Packit Service 20376f
 *
Packit Service 20376f
 * @param tx the resulting transaction, use this to commit or undo the
Packit Service 20376f
 * changes
Packit Service 20376f
 * @param cfg the configuration in which to lock
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_lock(git_transaction **tx, git_config *cfg);
Packit Service 20376f
Packit Service 20376f
/** @} */
Packit Service 20376f
GIT_END_DECL
Packit Service 20376f
#endif