diff options
-rw-r--r-- | git.c | 26 | ||||
-rw-r--r-- | git.h | 4 | ||||
-rw-r--r-- | pullreqd.c | 6 |
3 files changed, 23 insertions, 13 deletions
@@ -31,15 +31,24 @@ int find_ignore_file(const char *path) { return 0; } -void cleanup_git_repos(git_repository **repos) { +void cleanup_git_repo(git_repo *repo) { + if (repo->name != NULL) { + free(repo->name); + } + if (repo->repo != NULL) { + git_repository_free(repo->repo); + } +} + +void cleanup_git_repos(git_repo **repos) { for (int i = 0; repos[i] != NULL; i++) { - git_repository_free(repos[i]); + cleanup_git_repo(repos[i]); repos[i] = NULL; } free(repos); } -void cleanup_git(git_repository **repos) { +void cleanup_git(git_repo **repos) { cleanup_git_repos(repos); git_libgit2_shutdown(); } @@ -692,8 +701,8 @@ int create_pull_request_dir(pull_request *pr, index_t *idx, const char *root) { return ret; } -git_repository **init_git(config *cfg) { - git_repository **repos = NULL; +git_repo **init_git(config *cfg) { + git_repo **repos = NULL; linked_list *repo_list = NULL; DIR *root = opendir(cfg->git_root); struct dirent entry, *result; @@ -719,9 +728,10 @@ git_repository **init_git(config *cfg) { sprintf(repo_dir, "%s/%s", cfg->git_root, entry.d_name); /* Was no ignore file found? */ if (!find_ignore_file(repo_dir)) { - git_repository *repo = NULL; + git_repo *repo = calloc(1, sizeof(git_repo)); + repo->name = make_str(entry.d_name); /* Did we fail to open the git repo? */ - if (git_repository_open(&repo, repo_dir)) { + if (git_repository_open(&repo->repo, repo_dir)) { log(LOG_ERR, "Failed to open git repository %s, ignoring.", entry.d_name); } else { log(LOG_INFO, "Successfully opened git repository %s", entry.d_name); @@ -737,7 +747,7 @@ git_repository **init_git(config *cfg) { if (repo_list != NULL) { log(LOG_INFO, "Found, and opened %i repositories.", linked_list_size(repo_list)); /* Create the git repo array from our linked list. */ - repos = (git_repository **)linked_list_to_array(repo_list); + repos = (git_repo **)linked_list_to_array(repo_list); cleanup_linked_list(repo_list); } else { log(LOG_ERR, "Couldn't find, and/or open any repositories."); @@ -50,9 +50,9 @@ struct pull_request { git_branch *merge_branch; /* Branch to merge pull request with. */ }; -extern void cleanup_git(git_repository **repos); +extern void cleanup_git(git_repo **repos); extern void cleanup_pull_request(pull_request *pr); -extern git_repository **init_git(config *cfg); +extern git_repo **init_git(config *cfg); extern pull_request *get_pull_request(index_t *idx, const char *root); extern int add_comment(comment *comment, const char *pr_root); extern int create_pull_request_dir(pull_request *pr, index_t *idx, const char *root); @@ -160,7 +160,7 @@ int init_socket(config *cfg) { return fd; } -int main_loop(config *cfg, int listen_socket, git_repository **repos) { +int main_loop(config *cfg, int listen_socket, git_repo **repos) { int done = 0; struct stat st; @@ -177,7 +177,7 @@ int main_loop(config *cfg, int listen_socket, git_repository **repos) { return 0; } -void cleanup(config *cfg, int listen_socket, git_repository **repos) { +void cleanup(config *cfg, int listen_socket, git_repo **repos) { if (listen_socket > 0) { close(listen_socket); /* Is this a unix domain socket? */ @@ -197,7 +197,7 @@ void cleanup(config *cfg, int listen_socket, git_repository **repos) { int main(int argc, char **argv) { config *cfg = NULL; - git_repository **repos = NULL; + git_repo **repos = NULL; char *config_file = "test.conf"; int config_read = 0; int listen_socket = -1; |