char *git__dirname(const char *path) { char *dname = NULL; int len; len = (path ? strlen(path) : 0) + 2; dname = (char *)git__malloc(len); if (dname == NULL) return NULL; if (git__dirname_r(dname, len, path) < GIT_SUCCESS) { free(dname); return NULL; } return dname; }
static int guess_repository_dirs(git_repository *repo, const char *repository_path) { char buffer[GIT_PATH_MAX]; const char *path_work_tree = NULL; /* Git directory name */ if (git__basename_r(buffer, sizeof(buffer), repository_path) < 0) return GIT_EINVALIDPATH; if (strcmp(buffer, DOT_GIT) == 0) { /* Path to working dir */ if (git__dirname_r(buffer, sizeof(buffer), repository_path) < 0) return GIT_EINVALIDPATH; path_work_tree = buffer; } return assign_repository_dirs(repo, repository_path, NULL, NULL, path_work_tree); }
int gitfo_mv_force(const char *from, const char *to) { const int mode = 0755; /* or 0777 ? */ int error = GIT_SUCCESS; char target_folder_path[GIT_PATH_MAX]; error = git__dirname_r(target_folder_path, sizeof(target_folder_path), to); if (error < GIT_SUCCESS) return error; /* Does the containing folder exist? */ if (gitfo_isdir(target_folder_path)) { git__joinpath(target_folder_path, target_folder_path, ""); /* Ensure there's a trailing slash */ /* Let's create the tree structure */ error = gitfo_mkdir_recurs(target_folder_path, mode); if (error < GIT_SUCCESS) return error; } return gitfo_mv(from, to); }