Skip to content

refactor: rename is_directory() to dir_exists() and use it in clone.c #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

johnlinp
Copy link

Fixes #230

@@ -5,7 +5,7 @@
* symlink to a directory, we do not want to say it is a directory when
* dealing with tracked content in the working tree.
*/
int is_directory(const char *path)
int dir_exists(const char *path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Maybe the commit message could talk about the value of reconciling functionality, about consistency in naming (definitely mention that there is a file_exists() already), and it should probably talk about the differences of the is_directory() and the dir_exists() function, and that the former is a superset of the latter, but the latter has the better name.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I'll work on it. Thank you.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already updated the commit message. Since I am not a native speaker, please feel free to correct me if you find the sentences weird.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Please note that I am also not a native speaker...)

@johnlinp johnlinp force-pushed the reconcile-dir-exists-and-is-directory branch from dd3c38d to a896c32 Compare June 19, 2019 03:36
@@ -5,7 +5,7 @@
* symlink to a directory, we do not want to say it is a directory when
* dealing with tracked content in the working tree.
*/
int is_directory(const char *path)
int dir_exists(const char *path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@dscho
Copy link
Member

dscho commented Oct 4, 2019

@johnlinp did you want to /submit?

The original is_directory() checks whether the given path exists as
a directory, which makes dir_exists() a more suitable name.
However, there is already an existing function called dir_exists(),
while it doesn't check if the path is a directory.

We decided to do the following:
- remove the original dir_exists()
- rename the original is_directory() to dir_exists()
- use the new dir_exists() where the original dir_exists() is called

Hope it can reduce some confusion.

Signed-off-by: John Lin <johnlinp@gmail.com>
@johnlinp johnlinp force-pushed the reconcile-dir-exists-and-is-directory branch from a896c32 to b36fdf6 Compare November 6, 2019 07:26
@johnlinp
Copy link
Author

johnlinp commented Nov 6, 2019

/submit

@gitgitgadget
Copy link

gitgitgadget bot commented Nov 6, 2019

@dscho
Copy link
Member

dscho commented Nov 6, 2019

@@ -5,7 +5,7 @@
* symlink to a directory, we do not want to say it is a directory when
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Junio C Hamano wrote (reply to this):

"John Lin via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: John Lin <johnlinp@gmail.com>
>
> The original is_directory() checks whether the given path exists as
> a directory, which makes dir_exists() a more suitable name.

Why?  For a function that takes a path and asked "is this a
directory" that returns "yes/no", "is_directory(path)" is just as a
natural name as, if not more than, "dir_exists(path)".

IOW, "a more suitable name" needs a lot stronger justification than
"it subjectively sounds better to me".

> However, there is already an existing function called dir_exists(),
> while it doesn't check if the path is a directory.

Have you considered the possibility that it is deliberate (iow,
making it check may break the existing callers)?

bultin/clone.c wants to use its dir_exists() to see if *anything*
exists at the path already, so that it can issue an error message
and die when there is a non directory (e.g. a regular file), or a
non-empty directory, when it is told to create a repository.

It is a misnomer, sure, but that does not mean it is OK to break the
existing callers by suddenly saying "no there is not" when a user
tries to say "git clone $URL ~/.bashrc" (which used to fail because
the given destination is a file and it's "dir_exists()" said "oh,
there is something there already so you cannot mkdir there", but
with this patch it would say "nah, that thing is a file, so there is
no directory tehre").

> We decided to do the following:
> - remove the original dir_exists()
> - rename the original is_directory() to dir_exists()
> - use the new dir_exists() where the original dir_exists() is called

For a patch that touches all over the code like this, a summary of
what was done, like the above, is useful in evaluating how sensible
it is that the author wanted to do.  But it should also need to come
with "WHY".  Why does this patch do these three things?  Or, why
"we" (who are they?) decided to do so?

"We decided to do the following" does not answer that question, and
we can see from the patch text that the author decided to do them;
otherwise this patch would not exist ;-).

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reconcile dir_exists() and is_directory()
2 participants