summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2022-07-30 14:21:31 -0300
committermrb0nk500 <b0nk@b0nk.xyz>2022-07-30 14:21:31 -0300
commit31bb4276c730c70fcdaa89d270d32ab15c4975d2 (patch)
tree31db42dd70cf90e8a090d4aa9e42abd50982ba82 /git.c
parent5524b1730736c01d7b6172d2cc250b85cbf748d2 (diff)
git: Add `cleanup_pull_request()`
Diffstat (limited to 'git.c')
-rw-r--r--git.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/git.c b/git.c
index befdaa3..ea1b59a 100644
--- a/git.c
+++ b/git.c
@@ -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)) {