From 0be4dd7fdae48923df2d2f1c3525269bc948a16d Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Sat, 26 Jun 2021 14:17:51 -0400 Subject: Added `get_info_len()`. This function gets the length of the contents of the info file to make. --- git.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/git.c b/git.c index 3c84378..51e52e1 100644 --- a/git.c +++ b/git.c @@ -68,6 +68,31 @@ pull_request *get_pull_request(int id, const char *root) { } +int get_info_len(pull_request *pr) { + struct tm tm; + int len = format_len("title: %s\n", pr->title); + + localtime_r(&pr->date, &tm); + + len += format_len("author: %s\n", pr->author); + len += format_len("date: ") + strftime(NULL, -1, "%c %z\n", &tm); + len += format_len("description: %s\n", pr->desc); + len += format_len("type: %i\n", pr->pr_type); + + /* Is this PR using a remote branch? */ + if (pr->pr_type) { + len += format_len("branch: %s\n", pr->branch->name); + len += format_len("repo: %s", pr->branch->repo); + } else { + len += format_len("patches:"); + for (int i = 0; pr->patches[i] != NULL; i++) { + len += format_len(" %s", pr->patches[i]->name); + } + } + return len; + +} + int create_info(pull_request *pr, const char *pr_dir) { int len; int buf_len; -- cgit v1.2.3-13-gbd6f