mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-29 17:05:49 +00:00
Add git_repository_config API
This function puts the global and repository configurations in one git_config object and gives it to the user. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
This commit is contained in:
parent
b76934de6c
commit
b22d147986
@ -265,6 +265,16 @@ GIT_EXTERN(const char *) git_repository_path(git_repository *repo, git_repositor
|
|||||||
*/
|
*/
|
||||||
GIT_EXTERN(int) git_repository_is_bare(git_repository *repo);
|
GIT_EXTERN(int) git_repository_is_bare(git_repository *repo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the relevant configuration for a repository
|
||||||
|
*
|
||||||
|
* Puts together the configuration from the global and local files.
|
||||||
|
*
|
||||||
|
* @param out the repository's configuration
|
||||||
|
* @param repo the repository for which to get the config
|
||||||
|
*/
|
||||||
|
GIT_EXTERN(int) git_repository_config(git_config **out, git_repository *repo);
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
GIT_END_DECL
|
GIT_END_DECL
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
|
|
||||||
#define GIT_CONFIG_FILENAME ".gitconfig"
|
#define GIT_CONFIG_FILENAME ".gitconfig"
|
||||||
|
#define GIT_CONFIG_FILENAME_INREPO "config"
|
||||||
|
|
||||||
struct git_config {
|
struct git_config {
|
||||||
git_vector files;
|
git_vector files;
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
#include "blob.h"
|
#include "blob.h"
|
||||||
#include "fileops.h"
|
#include "fileops.h"
|
||||||
|
#include "config.h"
|
||||||
#include "refs.h"
|
#include "refs.h"
|
||||||
|
|
||||||
#define GIT_OBJECTS_INFO_DIR GIT_OBJECTS_DIR "info/"
|
#define GIT_OBJECTS_INFO_DIR GIT_OBJECTS_DIR "info/"
|
||||||
@ -271,6 +271,42 @@ cleanup:
|
|||||||
return git__rethrow(error, "Failed to open repository");
|
return git__rethrow(error, "Failed to open repository");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int git_repository_config(git_config **out, git_repository *repo)
|
||||||
|
{
|
||||||
|
git_config *cfg = NULL;
|
||||||
|
git_config_file *local = NULL;
|
||||||
|
char gitconfig[GIT_PATH_MAX];
|
||||||
|
int error = GIT_SUCCESS;
|
||||||
|
|
||||||
|
error = git_config_open_global(&cfg);
|
||||||
|
if (error < GIT_SUCCESS)
|
||||||
|
return git__rethrow(error, "Failed to open global config");
|
||||||
|
|
||||||
|
git__joinpath(gitconfig, repo->path_repository, GIT_CONFIG_FILENAME_INREPO);
|
||||||
|
error = git_config_file__ondisk(&local, gitconfig);
|
||||||
|
if (error < GIT_SUCCESS) {
|
||||||
|
error = git__rethrow(error, "Failed to open local config");
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
error = git_config_add_file(cfg, local, 2);
|
||||||
|
if (error < GIT_SUCCESS) {
|
||||||
|
error = git__rethrow(error, "Failed to add the local config");
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out = cfg;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if (error < GIT_SUCCESS) {
|
||||||
|
git_config_free(cfg);
|
||||||
|
if (local)
|
||||||
|
local->free(local);
|
||||||
|
}
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
static int discover_repository_dirs(git_repository *repo, const char *path)
|
static int discover_repository_dirs(git_repository *repo, const char *path)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
|
Loading…
Reference in New Issue
Block a user