diff options
author | Ben Straub <bs@github.com> | 2012-11-20 16:02:25 -0800 |
---|---|---|
committer | Ben Straub <bs@github.com> | 2012-11-27 13:18:28 -0800 |
commit | 54b2a37ac7715c74e5b06b76eb2b631987d7b6f8 (patch) | |
tree | e2f7441735a506de16b411a3c181a76f264c2bab /include/git2/config.h | |
parent | eecc80502975df5ef3aa9027d1b8b929cd6181bd (diff) | |
download | libgit2-54b2a37ac7715c74e5b06b76eb2b631987d7b6f8.tar.gz |
Clean up config.h
Diffstat (limited to 'include/git2/config.h')
-rw-r--r-- | include/git2/config.h | 94 |
1 files changed, 55 insertions, 39 deletions
diff --git a/include/git2/config.h b/include/git2/config.h index 8ec78e35c..af4d54044 100644 --- a/include/git2/config.h +++ b/include/git2/config.h @@ -41,23 +41,26 @@ typedef struct { unsigned int level; } git_config_entry; +typedef int (*git_config_foreach_cb)(const git_config_entry *, void *); + + /** * Generic backend that implements the interface to * access a configuration file */ -struct git_config_file { +struct git_config_backend { struct git_config *cfg; /* Open means open the file/database and parse if necessary */ - int (*open)(struct git_config_file *, unsigned int level); - int (*get)(struct git_config_file *, const char *key, const git_config_entry **entry); - int (*get_multivar)(struct git_config_file *, const char *key, const char *regexp, int (*fn)(const git_config_entry *, void *), void *data); - int (*set)(struct git_config_file *, const char *key, const char *value); - int (*set_multivar)(git_config_file *cfg, const char *name, const char *regexp, const char *value); - int (*del)(struct git_config_file *, const char *key); - int (*foreach)(struct git_config_file *, const char *, int (*fn)(const git_config_entry *, void *), void *data); - int (*refresh)(struct git_config_file *); - void (*free)(struct git_config_file *); + int (*open)(struct git_config_backend *, unsigned int level); + int (*get)(const struct git_config_backend *, const char *key, const git_config_entry **entry); + int (*get_multivar)(struct git_config_backend *, const char *key, const char *regexp, git_config_foreach_cb callback, void *payload); + int (*set)(struct git_config_backend *, const char *key, const char *value); + int (*set_multivar)(git_config_backend *cfg, const char *name, const char *regexp, const char *value); + int (*del)(struct git_config_backend *, const char *key); + int (*foreach)(struct git_config_backend *, const char *, git_config_foreach_cb callback, void *payload); + int (*refresh)(struct git_config_backend *); + void (*free)(struct git_config_backend *); }; typedef enum { @@ -87,11 +90,11 @@ typedef struct { * This method will not guess the path to the xdg compatible * config file (.config/git/config). * - * @param global_config_path Buffer of GIT_PATH_MAX length to store the path - * @return 0 if a global configuration file has been - * found. Its path will be stored in `buffer`. + * @param out Buffer to store the path in + * @param length size of the buffer in bytes + * @return 0 if a global configuration file has been found. Its path will be stored in `buffer`. */ -GIT_EXTERN(int) git_config_find_global(char *global_config_path, size_t length); +GIT_EXTERN(int) git_config_find_global(char *out, size_t length); /** * Locate the path to the global xdg compatible configuration file @@ -104,11 +107,12 @@ GIT_EXTERN(int) git_config_find_global(char *global_config_path, size_t length); * may be used on any `git_config` call to load the * xdg compatible configuration file. * - * @param xdg_config_path Buffer of GIT_PATH_MAX length to store the path + * @param out Buffer to store the path in + * @param length size of the buffer in bytes * @return 0 if a xdg compatible configuration file has been * found. Its path will be stored in `buffer`. */ -GIT_EXTERN(int) git_config_find_xdg(char *xdg_config_path, size_t length); +GIT_EXTERN(int) git_config_find_xdg(char *out, size_t length); /** * Locate the path to the system configuration file @@ -116,11 +120,12 @@ GIT_EXTERN(int) git_config_find_xdg(char *xdg_config_path, size_t length); * If /etc/gitconfig doesn't exist, it will look for * %PROGRAMFILES%\Git\etc\gitconfig. - * @param system_config_path Buffer of GIT_PATH_MAX length to store the path + * @param global_config_path Buffer to store the path in + * @param length size of the buffer in bytes * @return 0 if a system configuration file has been * found. Its path will be stored in `buffer`. */ -GIT_EXTERN(int) git_config_find_system(char *system_config_path, size_t length); +GIT_EXTERN(int) git_config_find_system(char *out, size_t length); /** * Open the global, XDG and system configuration files @@ -163,9 +168,9 @@ GIT_EXTERN(int) git_config_new(git_config **out); * @return 0 on success, GIT_EEXISTS when adding more than one file * for a given priority level (and force_replace set to 0), or error code */ -GIT_EXTERN(int) git_config_add_file( +GIT_EXTERN(int) git_config_add_backend( git_config *cfg, - git_config_file *file, + git_config_backend *file, unsigned int level, int force); @@ -223,12 +228,15 @@ GIT_EXTERN(int) git_config_open_ondisk(git_config **out, const char *path); * will return different config instances, but containing the same config_file * instance. * + * @param out The configuration instance to create + * @param parent Multi-level config to search for the given level + * @param level Configuration level to search for * @return 0, GIT_ENOTFOUND if the passed level cannot be found in the * multi-level parent config, or an error code */ GIT_EXTERN(int) git_config_open_level( - git_config **cfg_out, - git_config *cfg_parent, + git_config **out, + const git_config *parent, unsigned int level); /** @@ -262,7 +270,10 @@ GIT_EXTERN(void) git_config_free(git_config *cfg); * @param name the variable's name * @return 0 or an error code */ -GIT_EXTERN(int) git_config_get_entry(const git_config_entry **out, git_config *cfg, const char *name); +GIT_EXTERN(int) git_config_get_entry( + const git_config_entry **out, + const git_config *cfg, + const char *name); /** * Get the value of an integer config variable. @@ -276,7 +287,7 @@ GIT_EXTERN(int) git_config_get_entry(const git_config_entry **out, git_config *c * @param name the variable's name * @return 0 or an error code */ -GIT_EXTERN(int) git_config_get_int32(int32_t *out, git_config *cfg, const char *name); +GIT_EXTERN(int) git_config_get_int32(int32_t *out, const git_config *cfg, const char *name); /** * Get the value of a long integer config variable. @@ -290,7 +301,7 @@ GIT_EXTERN(int) git_config_get_int32(int32_t *out, git_config *cfg, const char * * @param name the variable's name * @return 0 or an error code */ -GIT_EXTERN(int) git_config_get_int64(int64_t *out, git_config *cfg, const char *name); +GIT_EXTERN(int) git_config_get_int64(int64_t *out, const git_config *cfg, const char *name); /** * Get the value of a boolean config variable. @@ -307,7 +318,7 @@ GIT_EXTERN(int) git_config_get_int64(int64_t *out, git_config *cfg, const char * * @param name the variable's name * @return 0 or an error code */ -GIT_EXTERN(int) git_config_get_bool(int *out, git_config *cfg, const char *name); +GIT_EXTERN(int) git_config_get_bool(int *out, const git_config *cfg, const char *name); /** * Get the value of a string config variable. @@ -324,7 +335,7 @@ GIT_EXTERN(int) git_config_get_bool(int *out, git_config *cfg, const char *name) * @param name the variable's name * @return 0 or an error code */ -GIT_EXTERN(int) git_config_get_string(const char **out, git_config *cfg, const char *name); +GIT_EXTERN(int) git_config_get_string(const char **out, const git_config *cfg, const char *name); /** * Get each value of a multivar. @@ -338,7 +349,7 @@ GIT_EXTERN(int) git_config_get_string(const char **out, git_config *cfg, const c * @param fn the function to be called on each value of the variable * @param data opaque pointer to pass to the callback */ -GIT_EXTERN(int) git_config_get_multivar(git_config *cfg, const char *name, const char *regexp, int (*fn)(const git_config_entry *, void *), void *data); +GIT_EXTERN(int) git_config_get_multivar(const git_config *cfg, const char *name, const char *regexp, git_config_foreach_cb callback, void *payload); /** * Set the value of an integer config variable in the config file @@ -404,7 +415,7 @@ GIT_EXTERN(int) git_config_set_multivar(git_config *cfg, const char *name, const * @param cfg the configuration * @param name the variable to delete */ -GIT_EXTERN(int) git_config_delete(git_config *cfg, const char *name); +GIT_EXTERN(int) git_config_delete_entry(git_config *cfg, const char *name); /** * Perform an operation on each config variable. @@ -420,8 +431,8 @@ GIT_EXTERN(int) git_config_delete(git_config *cfg, const char *name); * @return 0 on success, GIT_EUSER on non-zero callback, or error code */ GIT_EXTERN(int) git_config_foreach( - git_config *cfg, - int (*callback)(const git_config_entry *, void *payload), + const git_config *cfg, + git_config_foreach_cb callback, void *payload); /** @@ -438,9 +449,9 @@ GIT_EXTERN(int) git_config_foreach( * @return 0 or the return value of the callback which didn't return 0 */ GIT_EXTERN(int) git_config_foreach_match( - git_config *cfg, + const git_config *cfg, const char *regexp, - int (*callback)(const git_config_entry *entry, void *payload), + git_config_foreach_cb callback, void *payload); /** @@ -477,7 +488,12 @@ GIT_EXTERN(int) git_config_foreach_match( * @param map_n number of mapping objects in `maps` * @return 0 on success, error code otherwise */ -GIT_EXTERN(int) git_config_get_mapped(int *out, git_config *cfg, const char *name, git_cvar_map *maps, size_t map_n); +GIT_EXTERN(int) git_config_get_mapped( + int *out, + const git_config *cfg, + const char *name, + const git_cvar_map *maps, + size_t map_n); /** * Maps a string value to an integer constant @@ -489,7 +505,7 @@ GIT_EXTERN(int) git_config_get_mapped(int *out, git_config *cfg, const char *nam */ GIT_EXTERN(int) git_config_lookup_map_value( int *out, - git_cvar_map *maps, + const git_cvar_map *maps, size_t map_n, const char *value); @@ -506,7 +522,7 @@ GIT_EXTERN(int) git_config_lookup_map_value( GIT_EXTERN(int) git_config_parse_bool(int *out, const char *value); /** - * Parse a string value as an int64. + * Parse a string value as an int32. * * An optional value suffix of 'k', 'm', or 'g' will * cause the value to be multiplied by 1024, 1048576, @@ -515,10 +531,10 @@ GIT_EXTERN(int) git_config_parse_bool(int *out, const char *value); * @param out place to store the result of the parsing * @param value value to parse */ -GIT_EXTERN(int) git_config_parse_int64(int64_t *out, const char *value); +GIT_EXTERN(int) git_config_parse_int32(int32_t *out, const char *value); /** - * Parse a string value as an int32. + * Parse a string value as an int64. * * An optional value suffix of 'k', 'm', or 'g' will * cause the value to be multiplied by 1024, 1048576, @@ -527,7 +543,7 @@ GIT_EXTERN(int) git_config_parse_int64(int64_t *out, const char *value); * @param out place to store the result of the parsing * @param value value to parse */ -GIT_EXTERN(int) git_config_parse_int32(int32_t *out, const char *value); +GIT_EXTERN(int) git_config_parse_int64(int64_t *out, const char *value); /** @} */ |