From fb6bcf3f91b0297f218a91cedabfbed875c1b432 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Sun, 31 Jul 2022 17:49:19 -0300 Subject: git: Add support for specifying the name of a repo when getting, and creating PRs This allows for repos to have their own set of PRs, rather than only having a global set of PRs. Although, if you leave the repo name empty, then it will treat it as a global PR, rather than a repo specific PR. --- git.c | 23 +++++++++++++++++++---- git.h | 4 ++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/git.c b/git.c index d173471..0f0c802 100644 --- a/git.c +++ b/git.c @@ -367,15 +367,19 @@ static int parse_info_file_path(pull_request *pr, const char *root) { return ret; } -pull_request *get_pull_request(index_t *idx, const char *root) { +pull_request *get_pull_request(index_t *idx, const char *root, const char *repo) { /* Do we have a valid index? */ if (is_valid_index(idx)) { char *pr_dir; char *idx_str = index_to_str(idx); + char *pr_root = (!is_empty(repo)) ? dir_path_name(root, (char *)repo) : (char *)root; /* Does the converted path of our index exist? */ - if (index_path_exists(idx, root, &pr_dir) >= 0) { + if (index_path_exists(idx, (const char *)pr_root, &pr_dir) >= 0) { pull_request *pr = calloc(1, sizeof(pull_request)); + if (!is_empty(repo)) { + free(pr_root); + } log(LOG_NOTICE, "Found PR #%s with path \"%s\".", idx_str, pr_dir); @@ -390,14 +394,19 @@ pull_request *get_pull_request(index_t *idx, const char *root) { log(LOG_WARNING, "Failed to parse comments file of PR #%s.", idx_str); } + free(pr_dir); return pr; } else { log(LOG_ERR, "Failed to parse info file of PR #%s.", idx_str); free(pr); + free(pr_dir); return NULL; } } else { log(LOG_ERR, "No PR #%s found.", idx_str); + if (!is_empty(repo)) { + free(pr_root); + } free(idx_str); return NULL; } @@ -605,11 +614,12 @@ file **get_branch_commits(git_branch *br) { return NULL; } -int create_pull_request_dir(pull_request *pr, index_t *idx, const char *root) { +int create_pull_request_dir(pull_request *pr, index_t *idx, const char *root, const char *repo) { int ret = 0; struct stat st; file **commits; char *pr_dir; + char *pr_root = (!is_empty(repo)) ? dir_path_name(root, (char *)repo) : (char *)root; char *reason; /* Is this a NULL PR? */ @@ -619,7 +629,12 @@ int create_pull_request_dir(pull_request *pr, index_t *idx, const char *root) { } /* Use the index as the directory path. */ - pr_dir = make_index_path(root, idx, 0); + pr_dir = make_index_path((const char *)pr_root, idx, 0); + + /* Free the PR root, if the supplied repo isn't empty. */ + if (!is_empty(repo)) { + free(pr_root); + } /* Did we fail to make an indexed path? */ if (pr_dir == NULL) { diff --git a/git.h b/git.h index 222dc28..b8a709d 100644 --- a/git.h +++ b/git.h @@ -53,9 +53,9 @@ struct pull_request { extern void cleanup_git(git_repo **repos); extern void cleanup_pull_request(pull_request *pr); extern git_repo **init_git(config *cfg); -extern pull_request *get_pull_request(index_t *idx, const char *root); +extern pull_request *get_pull_request(index_t *idx, const char *root, const char *repo); 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); +extern int create_pull_request_dir(pull_request *pr, index_t *idx, const char *root, const char *repo); int parse_patch_list(void *ctx, void *ret, const keyword *key, keyword_val val); int parse_comment_reply(void *ctx, void *ret, const keyword *key, keyword_val val); -- cgit v1.2.3-13-gbd6f