Skip to content

Commit 1016ad4

Browse files
committed
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).
1 parent 717df1a commit 1016ad4

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/attr.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,14 @@ static int collect_attr_files(
523523
return error;
524524

525525
/* Resolve path in a non-bare repo */
526-
if (workdir != NULL)
527-
error = git_path_find_dir(&dir, path, workdir);
528-
else
526+
if (workdir != NULL) {
527+
if (!(error = git_repository_workdir_path(&dir, repo, path)))
528+
error = git_path_find_dir(&dir);
529+
}
530+
else {
529531
error = git_path_dirname_r(&dir, path);
532+
}
533+
530534
if (error < 0)
531535
goto cleanup;
532536

src/path.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -754,15 +754,13 @@ bool git_path_contains_file(git_buf *base, const char *file)
754754
return _check_dir_contents(base, file, &git_path_isfile);
755755
}
756756

757-
int git_path_find_dir(git_buf *dir, const char *path, const char *base)
757+
int git_path_find_dir(git_buf *dir)
758758
{
759-
int error = git_path_join_unrooted(dir, path, base, NULL);
759+
int error = 0;
760+
char buf[GIT_PATH_MAX];
760761

761-
if (!error) {
762-
char buf[GIT_PATH_MAX];
763-
if (p_realpath(dir->ptr, buf) != NULL)
764-
error = git_buf_sets(dir, buf);
765-
}
762+
if (p_realpath(dir->ptr, buf) != NULL)
763+
error = git_buf_sets(dir, buf);
766764

767765
/* call dirname if this is not a directory */
768766
if (!error) /* && git_path_isdir(dir->ptr) == false) */

src/path.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ extern int git_path_prettify_dir(git_buf *path_out, const char *path, const char
283283
* appends the trailing '/'. If the path does not exist, it is
284284
* treated like a regular filename.
285285
*/
286-
extern int git_path_find_dir(git_buf *dir, const char *path, const char *base);
286+
extern int git_path_find_dir(git_buf *dir);
287287

288288
/**
289289
* Resolve relative references within a path.

0 commit comments

Comments
 (0)