summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2022-07-31 17:29:50 -0300
committermrb0nk500 <b0nk@b0nk.xyz>2022-07-31 17:34:07 -0300
commitdb9647bc5b51859d83f1e3ab299ccc03536e6cae (patch)
tree1665a3d38f99239c7217bf7c4d91f2d8e32427e5 /git.c
parent7e27a353e5731584d3697d34668508960c28bc1b (diff)
pullreqd, git: Replace every current instance of `git_repository` with `git_repo`
This is done in order to make it easier to get the name of the repo.
Diffstat (limited to 'git.c')
-rw-r--r--git.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/git.c b/git.c
index f40f0fc..da9386d 100644
--- a/git.c
+++ b/git.c
@@ -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.");