diff options
Diffstat (limited to 'git.c')
-rw-r--r-- | git.c | 26 |
1 files changed, 18 insertions, 8 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."); |