From: Miriam Rubio <mirucam@gmail.com>
To: git@vger.kernel.org
Cc: Miriam Rubio <mirucam@gmail.com>
Subject: [Outreachy] [PATCH] dir: add new function `path_exists()`
Date: Sun, 27 Oct 2019 17:30:38 +0100 [thread overview]
Message-ID: <20191027163038.47409-1-mirucam@gmail.com> (raw)
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@gmail.com>
---
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)
next reply other threads:[~2019-10-27 16:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-27 16:30 Miriam Rubio [this message]
2019-10-28 2:22 ` [Outreachy] [PATCH] dir: add new function `path_exists()` Junio C Hamano
2019-10-28 9:45 ` Carlo Arenas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191027163038.47409-1-mirucam@gmail.com \
--to=mirucam@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).