int git_path_prettify(git_buf *path_out, const char *path, const char *base) { char buf[GIT_PATH_MAX]; assert(path && path_out); /* construct path if needed */ if (base != NULL && git_path_root(path) < 0) { if (git_buf_joinpath(path_out, base, path) < 0) return -1; path = path_out->ptr; } if (p_realpath(path, buf) == NULL) { /* giterr_set resets the errno when dealing with a GITERR_OS kind of error */ int error = (errno == ENOENT || errno == ENOTDIR) ? GIT_ENOTFOUND : -1; giterr_set(GITERR_OS, "Failed to resolve path '%s'", path); git_buf_clear(path_out); return error; } return git_buf_sets(path_out, buf); }
int git_path_find_dir(git_buf *dir, const char *path, const char *base) { int error = GIT_SUCCESS; if (base != NULL && git_path_root(path) < 0) error = git_buf_joinpath(dir, base, path); else error = git_buf_sets(dir, path); if (error == GIT_SUCCESS) { char buf[GIT_PATH_MAX]; if (p_realpath(dir->ptr, buf) != NULL) error = git_buf_sets(dir, buf); } /* call dirname if this is not a directory */ if (error == GIT_SUCCESS && git_path_isdir(dir->ptr) != GIT_SUCCESS) if (git_path_dirname_r(dir, dir->ptr) < GIT_SUCCESS) error = git_buf_lasterror(dir); if (error == GIT_SUCCESS) error = git_path_to_dir(dir); return error; }
static int create_and_configure_origin( git_remote **out, git_repository *repo, const char *url, const git_clone_options *options) { int error; git_remote *origin = NULL; char buf[GIT_PATH_MAX]; git_remote_create_cb remote_create = options->remote_cb; void *payload = options->remote_cb_payload; /* If the path exists and is a dir, the url should be the absolute path */ if (git_path_root(url) < 0 && git_path_exists(url) && git_path_isdir(url)) { if (p_realpath(url, buf) == NULL) return -1; url = buf; } if (!remote_create) { remote_create = default_remote_create; payload = NULL; } if ((error = remote_create(&origin, repo, "origin", url, payload)) < 0) goto on_error; *out = origin; return 0; on_error: git_remote_free(origin); return error; }
int git_path_prettify(git_buf *path_out, const char *path, const char *base) { char *result = NULL; int error = GIT_SUCCESS; git_buf_clear(path_out); /* construct path if needed */ if (base != NULL && git_path_root(path) < 0) { if ((error = git_buf_joinpath(path_out, base, path)) < GIT_SUCCESS) return error; path = path_out->ptr; } /* allow realpath to allocate the buffer */ if (path != NULL) result = p_realpath(path, NULL); if (result) { error = git_buf_sets(path_out, result); git__free(result); } else { error = GIT_EOSERR; } return error; }
int git_path_find_dir(git_buf *dir, const char *path, const char *base) { int error = git_path_join_unrooted(dir, path, base, NULL); if (!error) { char buf[GIT_PATH_MAX]; if (p_realpath(dir->ptr, buf) != NULL) error = git_buf_sets(dir, buf); } /* call dirname if this is not a directory */ if (!error) /* && git_path_isdir(dir->ptr) == false) */ error = (git_path_dirname_r(dir, dir->ptr) < 0) ? -1 : 0; if (!error) error = git_path_to_dir(dir); return error; }
/* * This function returns furthest offset into path where a ceiling dir * is found, so we can stop processing the path at that point. * * Note: converting this to use git_bufs instead of GIT_PATH_MAX buffers on * the stack could remove directories name limits, but at the cost of doing * repeated malloc/frees inside the loop below, so let's not do it now. */ static int find_ceiling_dir_offset( const char *path, const char *ceiling_directories) { char buf[GIT_PATH_MAX + 1]; char buf2[GIT_PATH_MAX + 1]; const char *ceil, *sep; size_t len, max_len = 0, min_len; assert(path); min_len = (size_t)(git_path_root(path) + 1); if (ceiling_directories == NULL || min_len == 0) return (int)min_len; for (sep = ceil = ceiling_directories; *sep; ceil = sep + 1) { for (sep = ceil; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++); len = sep - ceil; if (len == 0 || len >= sizeof(buf) || git_path_root(ceil) == -1) continue; strncpy(buf, ceil, len); buf[len] = '\0'; if (p_realpath(buf, buf2) == NULL) continue; len = strlen(buf2); if (len > 0 && buf2[len-1] == '/') buf[--len] = '\0'; if (!strncmp(path, buf2, len) && (path[len] == '/' || !path[len]) && len > max_len) { max_len = len; } } return (int)(max_len <= min_len ? min_len : max_len); }
int git_path_prettify(git_buf *path_out, const char *path, const char *base) { int error = GIT_SUCCESS; char buf[GIT_PATH_MAX]; git_buf_clear(path_out); /* construct path if needed */ if (base != NULL && git_path_root(path) < 0) { if ((error = git_buf_joinpath(path_out, base, path)) < GIT_SUCCESS) return error; path = path_out->ptr; } if (path == NULL || p_realpath(path, buf) == NULL) error = GIT_EOSERR; else error = git_buf_sets(path_out, buf); return error; }