summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
Diffstat (limited to 'git.c')
-rw-r--r--git.c60
1 files changed, 32 insertions, 28 deletions
diff --git a/git.c b/git.c
index 191b800..e640f83 100644
--- a/git.c
+++ b/git.c
@@ -275,42 +275,46 @@ int create_pull_request_dir(pull_request *pr, int id, const char *root) {
/* 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;
- /* Does this patch file exists? */
- if (access(commits[i]->name, F_OK) == 0) {
- long size = 0;
- char *buf = read_file(commits[i]->name, &size);
- log(LOG_NOTICE, "Patch file %s already exists.", commits[i]->name);
- /* Did we read the file? */
- if (buf != NULL) {
- /* Are the contents of the patch file the same? */
- if (strcmp(commits[i]->buf, buf) == 0) {
- /* Skip creating this patch file. */
- log(LOG_NOTICE, "Patch file %s is the same as the new one.", commits[i]->name);
+ /* Is the patch file array non-NULL? */
+ if (commits != NULL) {
+ /* Make patch files for each commit of PR. */
+ for (int i = 0; commits[i] != NULL; i++) {
+ FILE *fp;
+ /* Does this patch file exists? */
+ if (access(commits[i]->name, F_OK) == 0) {
+ long size = 0;
+ char *buf = read_file(commits[i]->name, &size);
+ log(LOG_NOTICE, "Patch file %s already exists.", commits[i]->name);
+ /* Did we read the file? */
+ if (buf != NULL) {
+ /* Are the contents of the patch file the same? */
+ if (strcmp(commits[i]->buf, buf) == 0) {
+ /* Skip creating this patch file. */
+ log(LOG_NOTICE, "Patch file %s is the same as the new one.", commits[i]->name);
+ free(buf);
+ continue;
+ }
free(buf);
+ } else {
+ log(LOG_WARNING, "Couldn't open patch file %s.", commits[i]->name);
continue;
}
- free(buf);
- } else {
- log(LOG_WARNING, "Couldn't open patch file %s.", commits[i]->name);
- continue;
}
+
+ /* Create the format patch file for this commit. */
+ fp = fopen(commits[i]->name, "w");
+ fwrite(commits[i]->buf, sizeof(char), strlen(commits[i]->buf), fp);
+ fclose(fp);
}
- /* Create the format patch file for this commit. */
- fp = fopen(commits[i]->name, "w");
- fwrite(commits[i]->buf, sizeof(char), strlen(commits[i]->buf), fp);
- fclose(fp);
+ if (commits != NULL && pr->pr_type) {
+ free_files(commits);
+ }
+ } else {
+ log(LOG_ERR, "Patch file array is NULL.");
+ ret = -1;
}
-
free(pr_dir);
-
- if (pr->pr_type) {
- free_files(commits);
- }
-
return ret;
}