threads / patch / 52141

patchclone: rename static function `dir_exists()`.

Subject: [Outreachy] [PATCH] clone: rename static function `dir_exists()`.

## tl;dr

3 messages between Oct 28, 2019 and Oct 29, 2019. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Miriam Rubio· Oct 28, 2019, 16:55 UTC · lore

builtin/clone.c has a static function dir_exists() that checks if a given path exists on the filesystem. It returns true (and it is correct for it to return true) when the given path exists as a non-directory (e.g. a regular file).

This is confusing. What the caller wants to check, and what this function wants to return, is if the path exists, so rename it to path_exists().

Signed-off-by: Miriam Rubio <mirucam@gmail.com>
---
 builtin/clone.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Show changes to builtin/clone.c +4 −4
diff --git a/builtin/clone.c b/builtin/clone.c
index c46ee29f0a..b24f04cf33 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -899,7 +899,7 @@ static void dissociate_from_references(void)
 	free(alternates);
 }
 
-static int dir_exists(const char *path)
+static int path_exists(const char *path)
 {
 	struct stat sb;
 	return !stat(path, &sb);
@@ -981,7 +981,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 +992,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 +1020,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 {
-- 
2.21.0 (Apple Git-122)
Junio C Hamano· Oct 29, 2019, 03:03 UTC · re: Miriam Rubio · lore

Re: [Outreachy] [PATCH] clone: rename static function `dir_exists()`.

Miriam Rubio <mirucam@gmail.com> writes:
Show 13 quoted lines
> builtin/clone.c has a static function dir_exists() that
> checks if a given path exists on the filesystem.  It returns
> true (and it is correct for it to return true) when the
> given path exists as a non-directory (e.g. a regular file).
>
> This is confusing.  What the caller wants to check, and what
> this function wants to return, is if the path exists, so
> rename it to path_exists().
>
> Signed-off-by: Miriam Rubio <mirucam@gmail.com>
> ---
>  builtin/clone.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)

With a narrowed scope, the patch and its explanation are both perfect ;-)

Now, with this localized change behind us, we may want to consider what to do with file_exists(path) that does not ensure the path is a file. It would be a separate topic, and it is OK for the result after such consideration to be "let's not go further for now". It also is OK for it to be "I am interested in digging further", too.

Thanks.  Will queue.
Miriam R.· Oct 29, 2019, 20:14 UTC · re: Junio C Hamano · lore

Re: [Outreachy] [PATCH] clone: rename static function `dir_exists()`.

Great! Thank you, Junio!
El mar., 29 oct. 2019 a las 4:03, Junio C Hamano (<gitster@pobox.com>) escribió:
Show 27 quoted lines
>
> Miriam Rubio <mirucam@gmail.com> writes:
>
> > builtin/clone.c has a static function dir_exists() that
> > checks if a given path exists on the filesystem.  It returns
> > true (and it is correct for it to return true) when the
> > given path exists as a non-directory (e.g. a regular file).
> >
> > This is confusing.  What the caller wants to check, and what
> > this function wants to return, is if the path exists, so
> > rename it to path_exists().
> >
> > Signed-off-by: Miriam Rubio <mirucam@gmail.com>
> > ---
> >  builtin/clone.c | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
>
> With a narrowed scope, the patch and its explanation are both
> perfect ;-)
>
> Now, with this localized change behind us, we may want to consider
> what to do with file_exists(path) that does not ensure the path is a
> file.  It would be a separate topic, and it is OK for the result
> after such consideration to be "let's not go further for now".  It
> also is OK for it to be "I am interested in digging further", too.
>
> Thanks.  Will queue.

← back to recent threads