summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2022-08-01 11:11:49 -0300
committermrb0nk500 <b0nk@b0nk.xyz>2022-08-01 11:11:49 -0300
commit705cd82152b3228cb5162c8e5680b77074bdac91 (patch)
treee6cc38b36a9c5774b959d6a5b686ac61de87e46a
parentfb6bcf3f91b0297f218a91cedabfbed875c1b432 (diff)
git: Add `parse_remote_branch()` callback
This needs to be done in order to properly allocate the remote branch before setting it's members.
-rw-r--r--git.c15
-rw-r--r--git.h5
2 files changed, 18 insertions, 2 deletions
diff --git a/git.c b/git.c
index 0f0c802..003d9b6 100644
--- a/git.c
+++ b/git.c
@@ -166,6 +166,21 @@ static linked_list *parse_dsv_str(const char *str, const char *delm) {
return tail;
}
+int parse_remote_branch(void *ctx, void *ret, const keyword *key, keyword_val val) {
+ if (key->type != TYPE_STRING) {
+ if (key->offsets[0] == offsetof(pull_request, branch)) {
+ if (key->offsets[1] == offsetof(git_branch, name) || key->offsets[1] == offsetof(git_branch, repo)) {
+ pull_request *pr = (pull_request *)ret;
+ if (pr->branch == NULL) {
+ pr->branch = calloc(1, sizeof(git_branch));
+ }
+ return 0;
+ }
+ }
+ }
+ return -1;
+}
+
int parse_patch_list(void *ctx, void *ret, const keyword *key, keyword_val val) {
/* Do we actually have a "patches" keyword? */
if (key->type == TYPE_STRING) {
diff --git a/git.h b/git.h
index b8a709d..71cecd0 100644
--- a/git.h
+++ b/git.h
@@ -57,6 +57,7 @@ extern pull_request *get_pull_request(index_t *idx, const char *root, const char
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, const char *repo);
+int parse_remote_branch(void *ctx, void *ret, const keyword *key, keyword_val val);
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);
@@ -67,8 +68,8 @@ static const keyword *info_keywords[] = {
&(const keyword){"date", "Date of Pull Request's creation.", "%a %b %e %H:%M:%S %Y %z", TYPE_TIME, offset_list(offsetof(pull_request, date)), NULL},
&(const keyword){"description", "Description of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, desc)), NULL},
&(const keyword){"type", "Type of Pull Request (0 = patch files, 1 = remote repo).", NULL, TYPE_INT, offset_list(offsetof(pull_request, pr_type)), NULL},
- &(const keyword){"branch", "Branch of remote repo.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, branch), offsetof(git_branch, name)), NULL},
- &(const keyword){"repo", "URL of remote repo.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, branch), offsetof(git_branch, repo)), NULL},
+ &(const keyword){"branch", "Branch of remote repo.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, branch), offsetof(git_branch, name)), parse_remote_branch},
+ &(const keyword){"repo", "URL of remote repo.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, branch), offsetof(git_branch, repo)), parse_remote_branch},
&(const keyword){"patches", "Patch file(s) of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, patches), offsetof(file, name)), parse_patch_list},
NULL,
};