summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2022-08-05 13:40:55 -0300
committermrb0nk500 <b0nk@b0nk.xyz>2022-08-05 13:40:55 -0300
commit9f58d83f1d7116c824ff074184a6c90556410b5b (patch)
tree1802d61409ea3e7b4bd6718929b5ef17f691ccb9
parentb2a9cfafc577533b0a9923d93c0bd8039eaf9b50 (diff)
git: Add `get_repo()`
This function takes a null-terminated `git_repo` array, and the name of the repo to get, and will return said repo if found, and NULL if not.
-rw-r--r--git.c11
-rw-r--r--git.h1
2 files changed, 12 insertions, 0 deletions
diff --git a/git.c b/git.c
index b070b14..7e65323 100644
--- a/git.c
+++ b/git.c
@@ -576,6 +576,17 @@ file **get_branch_commits(git_branch *br) {
return NULL;
}
+git_repo *get_repo(git_repo **repos, const char *name) {
+ if (!is_empty(name)) {
+ for (int i = 0; repos[i] != NULL; ++i) {
+ if (!is_empty(repos[i]->name) && !strcmp(repos[i]->name, name)) {
+ return repos[i];
+ }
+ }
+ }
+ return NULL;
+}
+
int create_pull_request_dir(pull_request *pr, index_t *idx, const char *root, const char *repo) {
int ret = 0;
struct stat st;
diff --git a/git.h b/git.h
index b8bba77..595f7a5 100644
--- a/git.h
+++ b/git.h
@@ -55,6 +55,7 @@ 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, const char *repo);
extern int add_comment(comment *comment, const char *pr_root);
+extern git_repo *get_repo(git_repo **repos, const char *name);
extern int create_pull_request_dir(pull_request *pr, index_t *idx, const char *root, const char *repo);
int parse_remote_branch(void *ctx, void *ret, const keyword *key, keyword_val val);