diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2021-04-15 01:31:12 +0100 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2021-04-28 13:03:34 +0100 |
commit | 1016ad4f98f1db7f5912c36b7922375d4c387ca0 (patch) | |
tree | d0f26e0a7da70d6e3aadc8bcafbfae84834c7b67 | |
parent | 717df1a4d201e713d8e16aae1d258d9cc27a86dc (diff) | |
download | libgit2-1016ad4f98f1db7f5912c36b7922375d4c387ca0.tar.gz |
path: don't join paths in git_path_find_dir
Let `git_path_find_dir` simply take a `git_buf` that contains a
directory or a file, instead of trying to both join a path AND then deal
with prettifying it or its basename. This allows consumers to join
paths themselves (and apply any necessary rules - like fitting within
MAX_PATH).
-rw-r--r-- | src/attr.c | 10 | ||||
-rw-r--r-- | src/path.c | 12 | ||||
-rw-r--r-- | src/path.h | 2 |
3 files changed, 13 insertions, 11 deletions
diff --git a/src/attr.c b/src/attr.c index f9cd93074..cab5e8b97 100644 --- a/src/attr.c +++ b/src/attr.c @@ -523,10 +523,14 @@ static int collect_attr_files( return error; /* Resolve path in a non-bare repo */ - if (workdir != NULL) - error = git_path_find_dir(&dir, path, workdir); - else + if (workdir != NULL) { + if (!(error = git_repository_workdir_path(&dir, repo, path))) + error = git_path_find_dir(&dir); + } + else { error = git_path_dirname_r(&dir, path); + } + if (error < 0) goto cleanup; diff --git a/src/path.c b/src/path.c index 50a0b468c..8928e49b8 100644 --- a/src/path.c +++ b/src/path.c @@ -754,15 +754,13 @@ bool git_path_contains_file(git_buf *base, const char *file) return _check_dir_contents(base, file, &git_path_isfile); } -int git_path_find_dir(git_buf *dir, const char *path, const char *base) +int git_path_find_dir(git_buf *dir) { - int error = git_path_join_unrooted(dir, path, base, NULL); + int error = 0; + char buf[GIT_PATH_MAX]; - if (!error) { - char buf[GIT_PATH_MAX]; - if (p_realpath(dir->ptr, buf) != NULL) - error = git_buf_sets(dir, buf); - } + 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) */ diff --git a/src/path.h b/src/path.h index 0cf2dbcdf..dcf5652df 100644 --- a/src/path.h +++ b/src/path.h @@ -283,7 +283,7 @@ extern int git_path_prettify_dir(git_buf *path_out, const char *path, const char * appends the trailing '/'. If the path does not exist, it is * treated like a regular filename. */ -extern int git_path_find_dir(git_buf *dir, const char *path, const char *base); +extern int git_path_find_dir(git_buf *dir); /** * Resolve relative references within a path. |