summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2021-06-25 20:44:31 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2021-06-25 20:54:10 -0400
commite33f48a1797691ae0432e2b90bf0755c1493d8a4 (patch)
tree4deb6e7505f66dee1cccf0b4e3dc00e39fcf2bf7 /git.c
parent0d74accf6fca824570fdb05b9a7644bf52fdb172 (diff)
Add error checking, and move the code for getting the
PR path, and getting the patch files to after the error checks.
Diffstat (limited to 'git.c')
-rw-r--r--git.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/git.c b/git.c
index 4a35165..52ef13a 100644
--- a/git.c
+++ b/git.c
@@ -71,9 +71,27 @@ pull_request *get_pull_request(int id, const char *root) {
int create_pull_request_dir(pull_request *pr, int id, const char *root) {
int ret = id;
struct stat st;
- file **commits = (pr->pr_type) ? get_branch_commits(pr->branch) : pr->patches;
+ file **commits;
+ char *pr_dir;
+
+ /* Is this a NULL PR? */
+ if (pr == NULL) {
+ log(LOG_ERR, "Pull Request is NULL.");
+ return -1;
+ }
+ /* Is the ID negative, and the PR title blank, or NULL? */
+ if (id < 0 && (pr->title == NULL || pr->title[0] == '\0')) {
+ log(LOG_ERR, "Negative ID, and either blank, or NULL Pull Request title.");
+ return -1;
+ }
+ /* Did we fail to create the info file? */
+ if (!create_info(pr, pr_dir)) {
+ log(LOG_ERR, "Failed to create info file.");
+ return -1;
+ }
+
/* Get the path of the PR's directory. */
- char *pr_dir = (id >= 0) ? dir_path_num(root, id) : dir_path_name(root, sanitize_str(pr->title));
+ pr_dir = (pr->title != NULL && pr->title[0] != '\0') ? dir_path_name(root, sanitize_str(pr->title)) : dir_path_num(root, id);
/* Is there no existing directory? */
if (stat(pr_dir, &st) < -1) {
@@ -81,6 +99,9 @@ int create_pull_request_dir(pull_request *pr, int id, const char *root) {
mkdir(pr_dir, 0755);
}
+ /* Get the patch files. */
+ commits = (pr->pr_type) ? get_branch_commits(pr->branch) : pr->patches;
+
/* Make patch files for each commit of PR. */
for (int i = 0; commits[i] != NULL; i++) {
FILE *fp;