Commit 1016ad4f by Edward Thomson

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).
parent 717df1a4
...@@ -523,10 +523,14 @@ static int collect_attr_files( ...@@ -523,10 +523,14 @@ static int collect_attr_files(
return error; return error;
/* Resolve path in a non-bare repo */ /* Resolve path in a non-bare repo */
if (workdir != NULL) if (workdir != NULL) {
error = git_path_find_dir(&dir, path, workdir); if (!(error = git_repository_workdir_path(&dir, repo, path)))
else error = git_path_find_dir(&dir);
}
else {
error = git_path_dirname_r(&dir, path); error = git_path_dirname_r(&dir, path);
}
if (error < 0) if (error < 0)
goto cleanup; goto cleanup;
......
...@@ -754,15 +754,13 @@ bool git_path_contains_file(git_buf *base, const char *file) ...@@ -754,15 +754,13 @@ bool git_path_contains_file(git_buf *base, const char *file)
return _check_dir_contents(base, file, &git_path_isfile); 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;
if (!error) {
char buf[GIT_PATH_MAX]; char buf[GIT_PATH_MAX];
if (p_realpath(dir->ptr, buf) != NULL) if (p_realpath(dir->ptr, buf) != NULL)
error = git_buf_sets(dir, buf); error = git_buf_sets(dir, buf);
}
/* call dirname if this is not a directory */ /* call dirname if this is not a directory */
if (!error) /* && git_path_isdir(dir->ptr) == false) */ if (!error) /* && git_path_isdir(dir->ptr) == false) */
......
...@@ -283,7 +283,7 @@ extern int git_path_prettify_dir(git_buf *path_out, const char *path, const char ...@@ -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 * appends the trailing '/'. If the path does not exist, it is
* treated like a regular filename. * 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. * Resolve relative references within a path.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment