diff options
author | Carlos Martín Nieto <cmn@elego.de> | 2011-03-29 17:44:10 +0200 |
---|---|---|
committer | Carlos Martín Nieto <cmn@elego.de> | 2011-03-29 18:13:47 +0200 |
commit | 9a3c5e55fd7894b8732a8010c94d034d674adbf7 (patch) | |
tree | 8fb90a8a97327b8c127e21ef730cfb537996c5cd /include/git2/config.h | |
parent | 26faa3668fedf1ffc95ef747b28f08b7131870f4 (diff) | |
download | libgit2-9a3c5e55fd7894b8732a8010c94d034d674adbf7.tar.gz |
Expose config API for setters, getters and foreach
These functions can be used to query or modify the variables in a
given configuration. No sanity checking is done on the variable names.
This is mostly meant as an API preview.
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Diffstat (limited to 'include/git2/config.h')
-rw-r--r-- | include/git2/config.h | 128 |
1 files changed, 126 insertions, 2 deletions
diff --git a/include/git2/config.h b/include/git2/config.h index c43d27fa..c9148263 100644 --- a/include/git2/config.h +++ b/include/git2/config.h @@ -26,11 +26,12 @@ #define INCLUDE_git_config_h__ #include "common.h" +#include "types.h" /** - * @file git2/refs.h + * @file git2/config.h * @brief Git config management routines - * @defgroup git_reference Git config management routines + * @defgroup git_config Git config management routines * @ingroup Git * @{ */ @@ -40,14 +41,137 @@ GIT_BEGIN_DECL * Open a configuration file * * @param cfg_out pointer to the configuration data + * @param path where to load the confiration from */ GIT_EXTERN(int) git_config_open(git_config **cfg_out, const char *path); /** * Free the configuration and its associated memory + * + * @param cfg the configuration to free */ GIT_EXTERN(void) git_config_free(git_config *cfg); +/** + * Get the value of an integer or boolean config variable. + * + * This is a more general function to retrieve the value of a integer + * or boolean variable. + * + * @param cfg where to look for the variable + * @param name the variable's name + * @param out pointer to the variable where the value should be stored + * @param type either GIT_VAR_INT or GIT_VAR_BOOL + * @return GIT_SUCCESS on success; error code otherwise + */ +GIT_EXTERN(int) git_config_get(git_config *cfg, const char *name, int *out, git_cvar_type type); + +/** + * Get the value of an integer config variable. + * + * @param cfg where to look for the variable + * @param name the variable's name + * @param out pointer to the variable where the value should be stored + * @return GIT_SUCCESS on success; error code otherwise + */ +GIT_INLINE(int) git_config_get_int(git_config *cfg, const char *name, int *out) +{ + return git_config_get(cfg, name, out, GIT_VAR_INT); +} + +/** + * Get the value of a boolean config variable. + * + * @param cfg where to look for the variable + * @param name the variable's name + * @param out pointer to the variable where the value should be stored + * @return GIT_SUCCESS on success; error code otherwise + */ +GIT_INLINE(int) git_config_get_bool(git_config *cfg, const char *name, int *out) +{ + return git_config_get(cfg, name, out, GIT_VAR_BOOL); +} + +/** + * Get the value of a string config variable. + * + * The string is owned by the variable and should not be freed by the + * user. + * + * @param cfg where to look for the variable + * @param name the variable's name + * @param out pointer to the variable's value + * @return GIT_SUCCESS on success; error code otherwise + */ +GIT_EXTERN(int) git_config_get_string(git_config *cfg, const char *name, const char **out); +/** + * Set the value of an integer or boolean config variable. + * + * This is a more general function to set the value of a integer or + * boolean variable. + * + * @param cfg where to look for the variable + * @param name the variable's name + * @param value the value to store + * @param type either GIT_VAR_INT or GIT_VAR_BOOL + * @return GIT_SUCCESS on success; error code otherwise + */ +GIT_EXTERN(int) git_config_set(git_config *cfg, const char *name, int value, git_cvar_type type); + +/** + * Set the value of an integer config variable. + * + * @param cfg where to look for the variable + * @param name the variable's name + * @param out pointer to the variable where the value should be stored + * @return GIT_SUCCESS on success; error code otherwise + */ +GIT_INLINE(int) git_config_set_int(git_config *cfg, const char *name, int value) +{ + return git_config_set(cfg, name, value, GIT_VAR_INT); +} + +/** + * Set the value of a boolean config variable. + * + * @param cfg where to look for the variable + * @param name the variable's name + * @param value the value to store + * @return GIT_SUCCESS on success; error code otherwise + */ +GIT_INLINE(int) git_config_set_bool(git_config *cfg, const char *name, int value) +{ + return git_config_set(cfg, name, value, GIT_VAR_BOOL); +} + +/** + * Set the value of a string config variable. + * + * A copy of the string is made and the user is free to use it + * afterwards. + * + * @param cfg where to look for the variable + * @param name the variable's name + * @param value the string to store. + * @return GIT_SUCCESS on success; error code otherwise + */ +GIT_EXTERN(int) git_config_set_string(git_config *cfg, const char *name, const char *value); + +/** + * Perform an operation on each config variable. + * + * The callback is passed a pointer to a config variable and the data + * pointer passed to this function. As soon as one of the callback + * functions returns something other than 0, this function returns + * that value. + * + * @param cfg where to get the variables from + * @param callback the function to call on each variable + * @param data the data to pass to the callback + * @return GIT_SUCCESS or the return value of the callback which didn't return 0 + */ +GIT_EXTERN(int) git_config_foreach(git_config *cfg, int (*callback)(git_cvar *, void *data), void *data); + /** @} */ GIT_END_DECL #endif |