Added a new function path_exists() that works the same as file_exists() but with better descriptive name. New calls should use path_exists() instead of file_exists(). The dir_exists() function in builtin/clone.c is marked as static, so nobody can use it outside builtin/clone.c and can be replaced by new function path_exists(). The static function path_exists() in archive.c have been renamed as archive_path_exists() to avoid name collision. Signed-off-by: Miriam Rubio <mirucam@xxxxxxxxx> --- archive.c | 6 +++--- builtin/clone.c | 12 +++--------- dir.c | 6 ++++++ dir.h | 3 +++ 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/archive.c b/archive.c index a8da0fcc4f..8110a50f17 100644 --- a/archive.c +++ b/archive.c @@ -338,7 +338,7 @@ static int reject_entry(const struct object_id *oid, struct strbuf *base, return ret; } -static int path_exists(struct archiver_args *args, const char *path) +static int archive_path_exists(struct archiver_args *args, const char *path) { const char *paths[] = { path, NULL }; struct path_exists_context ctx; @@ -358,7 +358,7 @@ static void parse_pathspec_arg(const char **pathspec, struct archiver_args *ar_args) { /* - * must be consistent with parse_pathspec in path_exists() + * must be consistent with parse_pathspec in archive_path_exists() * Also if pathspec patterns are dependent, we're in big * trouble as we test each one separately */ @@ -368,7 +368,7 @@ static void parse_pathspec_arg(const char **pathspec, ar_args->pathspec.recursive = 1; if (pathspec) { while (*pathspec) { - if (**pathspec && !path_exists(ar_args, *pathspec)) + if (**pathspec && !archive_path_exists(ar_args, *pathspec)) die(_("pathspec '%s' did not match any files"), *pathspec); pathspec++; } diff --git a/builtin/clone.c b/builtin/clone.c index c46ee29f0a..20ab535784 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -899,12 +899,6 @@ static void dissociate_from_references(void) free(alternates); } -static int dir_exists(const char *path) -{ - struct stat sb; - return !stat(path, &sb); -} - int cmd_clone(int argc, const char **argv, const char *prefix) { int is_bundle = 0, is_local; @@ -981,7 +975,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) dir = guess_dir_name(repo_name, is_bundle, option_bare); strip_trailing_slashes(dir); - dest_exists = dir_exists(dir); + dest_exists = path_exists(dir); if (dest_exists && !is_empty_dir(dir)) die(_("destination path '%s' already exists and is not " "an empty directory."), dir); @@ -992,7 +986,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) work_tree = NULL; else { work_tree = getenv("GIT_WORK_TREE"); - if (work_tree && dir_exists(work_tree)) + if (work_tree && path_exists(work_tree)) die(_("working tree '%s' already exists."), work_tree); } @@ -1020,7 +1014,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) } if (real_git_dir) { - if (dir_exists(real_git_dir)) + if (path_exists(real_git_dir)) junk_git_dir_flags |= REMOVE_DIR_KEEP_TOPLEVEL; junk_git_dir = real_git_dir; } else { diff --git a/dir.c b/dir.c index 61f559f980..638a783b65 100644 --- a/dir.c +++ b/dir.c @@ -2353,6 +2353,12 @@ int read_directory(struct dir_struct *dir, struct index_state *istate, return dir->nr; } +int path_exists(const char *path) +{ + struct stat sb; + return !stat(path, &sb); +} + int file_exists(const char *f) { struct stat sb; diff --git a/dir.h b/dir.h index 2fbdef014f..376fa93321 100644 --- a/dir.h +++ b/dir.h @@ -286,6 +286,9 @@ void clear_pattern_list(struct pattern_list *pl); void clear_directory(struct dir_struct *dir); int repo_file_exists(struct repository *repo, const char *path); +int path_exists(const char *); + +/* New calls should use path_exists(). */ int file_exists(const char *); int is_inside_dir(const char *dir); -- 2.21.0 (Apple Git-122)