diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2022-07-30 14:21:31 -0300 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2022-07-30 14:21:31 -0300 |
commit | 31bb4276c730c70fcdaa89d270d32ab15c4975d2 (patch) | |
tree | 31db42dd70cf90e8a090d4aa9e42abd50982ba82 /git.c | |
parent | 5524b1730736c01d7b6172d2cc250b85cbf748d2 (diff) |
git: Add `cleanup_pull_request()`
Diffstat (limited to 'git.c')
-rw-r--r-- | git.c | 68 |
1 files changed, 68 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)) { |