summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2021-06-26 14:58:17 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2021-06-26 14:58:17 -0400
commite0724b5286f8bb7a264cea3f923ee88f0a406a6e (patch)
tree740e9143085dbf82250122ba81191ce332920084 /git.c
parentb950d12b216f7a7b6b3b63e307a434f010305324 (diff)
Added the code for printing the info file contents to
the buffer.
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 51e52e1..c169baa 100644
--- a/git.c
+++ b/git.c
@@ -96,9 +96,11 @@ int get_info_len(pull_request *pr) {
int create_info(pull_request *pr, const char *pr_dir) {
int len;
int buf_len;
+ int j = 0;
char *info;
char *info_buf;
FILE *fp;
+ struct tm tm;
/* Is the PR NULL? */
if (pr == NULL) {
@@ -111,15 +113,34 @@ int create_info(pull_request *pr, const char *pr_dir) {
return 0;
}
+ localtime_r(&pr->date, &tm);
+
len = strlen(pr_dir) + strlen("/info");
buf_len = get_info_len(pr);
info = calloc(len+1, sizeof(char));
+ info_buf = calloc(buf_len+1, sizeof(char));
+
+ j = sprintf(info_buf, "title: %s\n", pr->title);
+ j += sprintf(info_buf+j, "author: %s\n", pr->author);
+ j += sprintf(info_buf+j, "date: ");
+ j += strftime(info_buf+j, -1, "%c %z\n", &tm);
+ j += sprintf(info_buf+j, "description: %s\n", pr->desc);
+ j += sprintf(info_buf+j, "type: %i\n", pr->pr_type);
+
+ /* Is this PR using a remote branch? */
+ if (pr->pr_type) {
+ j += sprintf(info_buf+j, "branch: %s\n", pr->branch->name);
+ j += sprintf(info_buf+j, "repo: %s", pr->branch->repo);
+ } else {
+ j += sprintf(info_buf+j, "patches:");
+ for (int i = 0; pr->patches[i] != NULL; i++) {
+ j += sprintf(info_buf+j, " %s", pr->patches[i]->name);
+ }
+ }
/* Append /info to the PR directory. */
sprintf(info, "%s/info", pr_dir);
- /* TODO: Write the rest of the code. */
-
/* Is there already an info file? */
if (access(info, F_OK) == 0) {
long size = 0;