summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2021-06-17 18:07:34 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2021-06-17 18:07:34 -0400
commit6f853c7ba14b5f4da8f1cb2da2ad63ad6753986f (patch)
tree6b50c44bd29794b7bc1bda62be23b38013cef090 /git.c
parenta0e2fef0f164ac3da9f6fac7aea96b91ceb64fa1 (diff)
Start work on some of the pull request handling code.
Diffstat (limited to 'git.c')
-rw-r--r--git.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/git.c b/git.c
index ab59ac4..8be1be5 100644
--- a/git.c
+++ b/git.c
@@ -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;