diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2021-06-18 09:52:40 -0400 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2021-06-18 09:52:40 -0400 |
commit | c70cf68a59dd94789b700d48c2389468ed6d4383 (patch) | |
tree | f7b64101515501fa3d668b2cc461a6dd889a941e /git.c | |
parent | 8c7006c3ce636e7ba4127e5567350c334c3ea5e1 (diff) |
Added code for creating format patch files of each
commit of a pull request.
Diffstat (limited to 'git.c')
-rw-r--r-- | git.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -12,6 +12,7 @@ #include "config.h" #include "git.h" #include "macros.h" +#include "misc.h" git_repo *add_repo(git_repository *repo, git_repo **first, git_repo **last) { @@ -108,6 +109,33 @@ int create_pull_request_dir(pull_request *pr, const char *root) { /* Create a directory with a name of the stringified ID. */ mkdir(pr_dir, 0755); } + + /* 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); + /* 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. */ + free(buf); + continue; + } + free(buf); + } else { + 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); + } /* TODO: Implement rest of code. */ } |