summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2021-06-26 14:17:51 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2021-06-26 14:17:51 -0400
commit0be4dd7fdae48923df2d2f1c3525269bc948a16d (patch)
treeca2ef95e7a906b950718d631ba7d574f9f5eb288 /git.c
parent30afc5de57b24a7fab895e0b421b2ca754cfb82c (diff)
Added `get_info_len()`.
This function gets the length of the contents of the info file to make.
Diffstat (limited to 'git.c')
-rw-r--r--git.c25
1 files changed, 25 insertions, 0 deletions
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;