diff options
-rw-r--r-- | git.c | 25 |
1 files changed, 23 insertions, 2 deletions
@@ -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; |