summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2022-08-06 12:13:28 -0300
committermrb0nk500 <b0nk@b0nk.xyz>2022-08-06 12:13:28 -0300
commitfbe98f57dc779069bd283ac1773866ce73727ea0 (patch)
treef5091e55374f4bf91ae011cf856519bc829327de
parenta185caea7fbc0969829b96af3f43e8ae980df000 (diff)
git: Add `get_pr_type()` keyword getter callback
This callback is needed because `pr_type` is a `uint8_t`, but the keyword type is `TYPE_INT` which assumes that the type is an `int`.
-rw-r--r--git.c10
-rw-r--r--git.h3
2 files changed, 12 insertions, 1 deletions
diff --git a/git.c b/git.c
index e20cfd6..e56035b 100644
--- a/git.c
+++ b/git.c
@@ -377,6 +377,16 @@ pull_request *get_pull_request(index_t *idx, const char *root, const char *repo)
}
}
+int get_pr_type(void *ctx, void *data, const keyword *key, keyword_val *val) {
+ pull_request *pr = (pull_request *)data;
+ if (key->type == TYPE_INT && pr != NULL) {
+ val->i = pr->pr_type;
+ return 1;
+ } else {
+ return -1;
+ }
+}
+
int has_remote_branch(void *ctx, void *data, const keyword *key, keyword_val *val) {
pull_request *pr = (pull_request *)data;
return (pr->pr_type) ? 0 : -1;
diff --git a/git.h b/git.h
index 80cdc92..76be91e 100644
--- a/git.h
+++ b/git.h
@@ -64,6 +64,7 @@ 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);
+int get_pr_type(void *ctx, void *data, const keyword *key, keyword_val *val);
int has_remote_branch(void *ctx, void *ret, const keyword *key, keyword_val *val);
int get_patch_list(void *ctx, void *data, const keyword *key, keyword_val *val);
int get_comment_reply(void *ctx, void *data, const keyword *key, keyword_val *val);
@@ -74,7 +75,7 @@ static const keyword *info_keywords[] = {
&(const keyword){"author", "Author of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, author)), NULL, NULL},
&(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, NULL},
&(const keyword){"description", "Description of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, desc)), NULL, 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, 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, get_pr_type},
&(const keyword){"branch", "Branch of remote repo.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, branch), offsetof(git_branch, name)), parse_remote_branch, has_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, has_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, get_patch_list},