summaryrefslogtreecommitdiff
path: root/src/repository.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <carlos@cmartin.tk>2011-06-16 17:46:06 +0200
committerVicent Marti <tanoku@gmail.com>2011-06-17 22:30:29 +0200
commitb22d147986504434188218ec74f9a6531497ffe9 (patch)
tree3b1b15f85654cf26e3f34b09745a08b28658f874 /src/repository.c
parentb76934de6cfb920bc52c03730667fad3e0434aa4 (diff)
downloadlibgit2-b22d147986504434188218ec74f9a6531497ffe9.tar.gz
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>
Diffstat (limited to 'src/repository.c')
-rw-r--r--src/repository.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/repository.c b/src/repository.c
index c9678f185..be089b54b 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -32,7 +32,7 @@
#include "tag.h"
#include "blob.h"
#include "fileops.h"
-
+#include "config.h"
#include "refs.h"
#define GIT_OBJECTS_INFO_DIR GIT_OBJECTS_DIR "info/"
@@ -271,6 +271,42 @@ cleanup:
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)
{
int error;