diff options
-rw-r--r-- | git.c | 68 | ||||
-rw-r--r-- | git.h | 1 |
2 files changed, 69 insertions, 0 deletions
@@ -72,6 +72,74 @@ void free_files(file **files) { free(files); } +static void free_git_branch(git_branch *branch) { + if (branch->name != NULL) { + free(branch->name); + branch->name = NULL; + } + if (branch->repo != NULL) { + free(branch->repo); + branch->repo = NULL; + } +} + +static void free_comment(comment *comment) { + if (comment->author != NULL) { + free(comment->author); + comment->author = NULL; + } + if (comment->desc != NULL) { + free(comment->desc); + comment->desc = NULL; + } + comment->reply = NULL; +} + +static void free_comments(comment **comments) { + for (int i = 0; comments[i] != NULL; ++i) { + free_comment(comments[i]); + comments[i] = NULL; + } + free(comments); +} + +void cleanup_pull_request(pull_request *pr) { + if (pr != NULL) { + if (pr->title != NULL) { + free(pr->title); + pr->title = NULL; + } + if (pr->desc != NULL) { + free(pr->desc); + pr->desc = NULL; + } + if (pr->author != NULL) { + free(pr->author); + pr->author = NULL; + } + if (pr->comments != NULL) { + free_comments(pr->comments); + pr->comments = NULL; + } + if (pr->merge_branch != NULL) { + free_git_branch(pr->merge_branch); + pr->merge_branch = NULL; + } + if (!pr->pr_type) { + if (pr->patches != NULL) { + free_files(pr->patches); + pr->patches = NULL; + } + } else { + if (pr->branch != NULL) { + free_git_branch(pr->branch); + pr->branch = NULL; + } + } + free(pr); + } +} + static linked_list *parse_dsv_str(const char *str, const char *delm) { linked_list *tail = NULL; for (; *str != '\0'; str += strspn(str, delm)) { @@ -45,6 +45,7 @@ struct pull_request { }; extern void cleanup_git(git_repository **repos); +extern void cleanup_pull_request(pull_request *pr); extern git_repository **init_git(config *cfg); extern pull_request *get_pull_request(index_t *idx, const char *root); extern int add_comment(comment *comment, const char *pr_root); |