diff options
-rw-r--r-- | git.c | 52 |
1 files changed, 52 insertions, 0 deletions
@@ -62,6 +62,58 @@ void cleanup_git(git_repository **repos) { git_libgit2_shutdown(); } +pull_request *get_pull_request(int id, const char *root) { + +} + +int create_pull_request_dir(pull_request *pr, const char *root) { + int id = 0; + int is_num = 0; + DIR *dir = opendir(root); + struct dirent entry, *result; + + while (readdir_r(dir, &entry, &result) == 0 && result != NULL) { + if (entry.d_type == DT_DIR) { + char *tmp = entry.d_name; + + /* Is this a blank directory name? */ + if (*tmp == '\0') { + continue; + } + + for (is_num = 1; *tmp && is_num; is_num = isdigit(*tmp++)); + + + /* Is this a numbered directory? */ + if (is_num) { + int val = strtol(entry.d_name, NULL, 0); + /* Set the current ID to the numbered directory, if it's larger than it. */ + id = (id < val) ? val : id; + } + } + } + + /* Did we find any numbered directories? */ + if (id > 0) { + struct stat st; + file **commits = (pr->pr_type) ? get_branch_commits(pr->branch) : pr->patches; + /* Get the length of the stringified ID path. */ + int len = snprintf(NULL, 0, "%s/%i", root, id); + /* Convert the ID to a string. */ + char *pr_dir = calloc(len+1, sizeof(char)); + sprintf(pr_dir, "%s/%i", root, id); + + /* Is there no existing directory? */ + if (stat(pr_dir, &st) < -1) { + /* Create a directory with a name of the stringified ID. */ + mkdir(pr_dir, 0755); + } + /* TODO: Implement rest of code. */ + } + + return id; +} + git_repository **init_git(config *cfg) { git_repository **repos = NULL; git_repository *repo = NULL; |