#ifndef GIT_H #define GIT_H #include #include #include #include "index.h" #include "keyword.h" typedef struct pull_request pull_request; typedef struct file file; typedef struct comment comment; typedef struct git_branch git_branch; typedef struct git_repo git_repo; struct file { char *name; /* Name of file. */ char *buf; /* Buffer containing contents of file. */ }; struct comment { char *author; /* Author of comment. */ char *desc; /* Description/Contents of comment. */ time_t date; /* Date of creation. */ int id; /* Comment ID. */ comment *reply; /* Comment that is being replied to. */ }; struct git_branch { char *name; /* Name of branch. */ char *repo; /* Path, or URL to local, or remote repository. */ }; struct git_repo { char *name; /* Name of git repository. */ git_repository *repo; /* Git repository. */ }; struct pull_request { char *title; /* Title of the pull request. */ char *desc; /* Description of the pull request. */ char *author; /* Author of the pull request. */ comment **comments; /* Comments of this pull reuqest. */ time_t date; /* Date of creation. */ uint8_t pr_type; /* Type of pull request. (0 = individual commit patches, 1 = remote branch) */ union { file **patches; /* Patch files of pull request. */ git_branch *branch; /* Branch of pull request. */ }; char *merge_branch; /* Branch to merge pull request with. */ }; 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, 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_branch(pull_request *pr, index_t *idx, git_repo *repo); 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); 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); #define offset_list(...) (size_t []){__VA_ARGS__, -1} static const keyword *info_keywords[] = { &(const keyword){"title", "Title of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, title)), NULL, NULL}, &(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, 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}, &(const keyword){"merge-branch", "Branch to merge Pull Request with.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, merge_branch)), NULL}, NULL, }; static const keyword *comment_keywords[] = { &(const keyword){"id", "ID of Comment.", NULL, TYPE_INT, offset_list(offsetof(comment, id)), NULL}, &(const keyword){"author", "Author of Comment.", NULL, TYPE_STRING, offset_list(offsetof(comment, author)), NULL}, &(const keyword){"date", "Date of Comment's creation.", "%a %b %e %H:%M:%S %Y %z", TYPE_TIME, offset_list(offsetof(comment, date)), NULL}, &(const keyword){"reply-to", "ID of replied Comment.", NULL, TYPE_INT, offset_list(offsetof(comment, reply), offsetof(comment, id)), parse_comment_reply, get_comment_reply}, &(const keyword){"reply-author", "Author of replied Comment.", NULL, TYPE_STRING, offset_list(offsetof(comment, reply), offsetof(comment, author)), parse_comment_reply, get_comment_reply}, &(const keyword){"reply-date", "Date of replied Comment's creation", "%a %b %e %H:%M:%S %Y %z", TYPE_TIME, offset_list(offsetof(comment, reply), offsetof(comment, date)), parse_comment_reply, get_comment_reply}, &(const keyword){"description", "Message of Comment.", NULL, TYPE_STRING, offset_list(offsetof(comment, desc)), NULL, NULL}, NULL, }; #undef offset_list #endif