aboutsummaryrefslogtreecommitdiffstats
path: root/src/blogc-git-receiver/post-receive.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/blogc-git-receiver/post-receive.c')
-rw-r--r--src/blogc-git-receiver/post-receive.c75
1 files changed, 8 insertions, 67 deletions
diff --git a/src/blogc-git-receiver/post-receive.c b/src/blogc-git-receiver/post-receive.c
index 93cae25..23d4dae 100644
--- a/src/blogc-git-receiver/post-receive.c
+++ b/src/blogc-git-receiver/post-receive.c
@@ -16,32 +16,8 @@
#include "../common/config-parser.h"
#include "../common/error.h"
#include "../common/file.h"
-
-
-char*
-bgr_post_receive_get_config_section(bc_config_t *config, const char *repo_path,
- const char *home)
-{
- char *rv = NULL;
- char** sections = bc_config_list_sections(config);
- for (size_t i = 0; sections[i] != NULL; i++) {
- if (bc_str_starts_with(sections[i], "repo:")) {
- char *tmp_repo = bc_strdup_printf("%s/repos/%s", home, sections[i] + 5);
- char *real_tmp_repo = realpath(tmp_repo, NULL); // maybe not needed
- free(tmp_repo);
- if (real_tmp_repo == NULL)
- continue;
- if (0 == strcmp(real_tmp_repo, repo_path)) {
- rv = bc_strdup(sections[i]);
- free(real_tmp_repo);
- break;
- }
- free(real_tmp_repo);
- }
- }
- bc_strv_free(sections);
- return rv;
-}
+#include "settings.h"
+#include "post-receive.h"
int
@@ -76,56 +52,21 @@ bgr_post_receive_hook(int argc, char *argv[])
goto push;
}
- char *home = getenv("BLOGC_GIT_RECEIVER_BASEDIR");
- if (home == NULL) {
- home = getenv("HOME");
- }
- if (home == NULL) {
- fprintf(stderr, "warning: failed to find user home path, "
- "mirroring disabled\n");
- goto cleanup;
- }
-
- char *config_file = bc_strdup_printf("%s/blogc-git-receiver.ini", home);
- if ((0 != access(config_file, F_OK))) {
+ bc_config_t *config = bgr_settings_parse();
+ if (config == NULL) {
fprintf(stderr, "warning: repository mirroring disabled\n");
- free(config_file);
- goto cleanup;
- }
-
- size_t len;
- bc_error_t *err = NULL;
- char* config_content = bc_file_get_contents(config_file, true, &len, &err);
- if (err != NULL) {
- fprintf(stderr, "warning: failed to read configuration file (%s), "
- "mirroring disabled: %s\n", config_file, err->msg);
- bc_error_free(err);
- free(config_file);
- free(config_content);
- goto cleanup;
- }
-
- bc_config_t *config = bc_config_parse(config_content, len, NULL, &err);
- free(config_content);
- if (err != NULL) {
- fprintf(stderr, "warning: failed to parse configuration file (%s), "
- "mirroring disabled: %s\n", config_file, err->msg);
- bc_error_free(err);
- free(config_file);
goto cleanup;
}
- free(config_file);
- char *config_section = bgr_post_receive_get_config_section(config, repo_path,
- home);
- if (config_section == NULL) {
+ char *section = bgr_settings_get_section(config, repo_path);
+ if (section == NULL) {
fprintf(stderr, "warning: repository mirroring disabled\n");
bc_config_free(config);
goto cleanup;
}
- mirror = bc_strdup(bc_config_get(config, config_section, "mirror"));
- free(config_section);
+ mirror = bc_strdup(bc_config_get(config, section, "mirror"));
+ free(section);
bc_config_free(config);
if (mirror == NULL) {