From 45b91d6057fc67db1491d301cf44f4f93764c783 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Tue, 26 Jul 2022 17:46:54 -0300 Subject: git, index: Move index related functions to `index.{c,h}` --- git.c | 65 ----------------------------------------------------------------- 1 file changed, 65 deletions(-) (limited to 'git.c') diff --git a/git.c b/git.c index ff3a574..5408de9 100644 --- a/git.c +++ b/git.c @@ -284,71 +284,6 @@ file **get_branch_commits(git_branch *br) { return NULL; } -int is_valid_index(index *idx) { - int did_alloc = 0; - char *err_str = NULL; - - /* Is the index NULL? */ - if (idx == NULL) { - err_str = "Index is NULL."; - /* Is the index type invalid? */ - } else if (idx->type > 1) { - did_alloc = 1; - err_str = calloc(format_len("Invalid index type: %u.", idx->type)+1, sizeof(char)); - sprintf(err_str, "Invalid index type: %u.", idx->type); - /* Is this named index empty? */ - } else if (idx->type == 0 && is_empty(idx->name)) { - err_str = "Named index is empty."; - } - - /* Did we get an error? */ - if (err_str != NULL) { - log_reason(LOG_ERR, "Invalid index.", reason); - if (did_alloc) { - free(err_str); - } - /* Invalid index, return false. */ - return 0; - /* Is there another index after this one? */ - } else if (idx->next != NULL) { - /* Return the validity of the next index. */ - return is_valid_index(idx->next); - } - /* Valid index, return true. */ - return 1; -} - -char *make_index_path(const char *root, index *idx, int path_type) { - char *path; - char *tmp; - int path_len = strlen(root) + 1; - /* Is the index invalid? */ - if (!is_valid_index(idx)) { - return NULL; - } - - /* Get the length of the path. */ - for (index *i = idx; i != NULL; i = i->next) { - const int is_last = (i->next == NULL); - const char *fmt = (i->type) "%llu" : "%s"; - path_len += format_len(fmt, (i->type) ? i->num : i->name) + !is_last; - } - - path = calloc(path_len+1, sizeof(char)); - tmp = path; - - /* Create the path. */ - tmp += sprintf(tmp, "%s/", root); - for (index *i = idx; i != NULL; i = i->next) { - const int is_last = (i->next == NULL); - const char *delm = (path_type) ? "-" : "/"; - const char *fmt = (i->type) "%llu%s" : "%s%s"; - tmp += sprintf(tmp, fmt, (i->type) ? i->num : i->name, (!is_last) ? delm : ""); - } - - return path; -} - int create_pull_request_dir(pull_request *pr, index *idx, const char *root) { int ret = 0; struct stat st; -- cgit v1.2.3-13-gbd6f