From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: "Robert P. J. Day" <rpjday@crashcourse.ca>,
Stephan Janssen <sjanssen@you-get.com>,
"git\@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: [PATCH 3/4] clone: factor out dir_exists() helper
Date: Fri, 05 Jan 2018 11:19:19 -0800 [thread overview]
Message-ID: <xmqqo9m8cdvs.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20180105002206.GB3474@sigill.intra.peff.net> (Jeff King's message of "Thu, 4 Jan 2018 19:22:06 -0500")
Jeff King <peff@peff.net> writes:
> On Thu, Jan 04, 2018 at 06:54:12PM -0500, Jeff King wrote:
>
>> > If we really want to be anal, perhaps a new helper path_exists()
>> > that cares only about existence of paths (i.e. the implementation of
>> > these two helpers they currently have), together with update to
>> > check the st.st_mode for file_exists() and dir_exists(), may help
>> > making the API set more rational, but I do not think it is worth it.
>>
>> Yep, I also considered that file_exists() probably wants to be
>> path_exists() with its current implementation. We'd probably want to
>> review all of the callers.
>>
>> Anyway, I tried to do the minimal refactoring here, with no change in
>> behavior. I'm not opposed to calling this dir_exists() as path_exists()
>> and making it globally available (as you note, I don't think we'd want
>> to use a true dir_exists() here).
>
> So I actually started down this road just now, but I'm not sure if it's
> worth it.
Yeah, although I said it already without starting down this road,
you actually thought about it more and your insight is more valuable
;-)
> If we were to transition to an endgame with path_exists(),
> dir_exists(), and file_exists(), we'd probably want to do something
> like:
>
> 1. introduce path_exists(), but leave existing file_exists() callers
> in place
>
> 2. introduce file_exists_as_file(), which checks S_IFREG
>
> 3. audit each file_exists() call to see if it ought to be
> path_exists() or file_exists_as_file() and convert as needed
>
> 4. When there are no more file_exists() calls left, all
> file_exists_as_file() instances can be renamed to file_exists().
>
> But as with any "audit each..." plan, that leaves topics in flight out
> of luck. If we want to be kind to those, we'd have to wait a long while
> to shake out any file_exists() callers.
>
> At which point is there much value in having path_exists() as a wrapper?
> It's a better name, perhaps, but I think my future-proofing against
> "file_exists() may become file-specific" was probably overly paranoid. I
> don't think we could sanely do that conversion without risking breakage.
If we want to, the endgame can be to have a single path_exists_as()
helper that could be used like so:
#define PATH_TYPE_IFREG (1<<0)
#define PATH_TYPE_IFLNK (1<<1)
#define PATH_TYPE_IFDIR (1<<2)
#define PATY_TYPE_IFANY ((1<<3)-1)
#define path_exists(path) path_exists_as(path, PATH_TYPE_ANY)
#define path_exists_as_file(path) path_exists_as(path, PATH_TYPE_IFREG)
/* backward compatibility */
#define file_exists(path) path_exists_as(path, PATH_TYPE_ANY)
We can avoid "file-exists used to mean this thing but in a distant
future it means completely different thing" that way.
> Maybe we should just document its behavior and use it here, rather than
> introducing this new dir_exists().
Sounds good enough to me ;-)
next prev parent reply other threads:[~2018-01-05 19:19 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-02 11:10 Git removes existing folder when cancelling clone Stephan Janssen
2018-01-02 11:12 ` Robert P. J. Day
2018-01-02 20:04 ` Jeff King
2018-01-02 21:07 ` [PATCH 0/4] " Jeff King
2018-01-02 21:08 ` [PATCH 1/4] t5600: fix outdated comment about unborn HEAD Jeff King
2018-01-02 21:09 ` [PATCH 2/4] t5600: modernize style Jeff King
2018-01-02 21:10 ` [PATCH 3/4] clone: factor out dir_exists() helper Jeff King
2018-01-04 23:47 ` Junio C Hamano
2018-01-04 23:54 ` Jeff King
2018-01-05 0:22 ` Jeff King
2018-01-05 19:19 ` Junio C Hamano [this message]
2018-01-02 21:11 ` [PATCH 4/4] clone: do not clean up directories we didn't create Jeff King
2018-01-02 22:49 ` Eric Sunshine
2018-01-02 23:39 ` Jeff King
2018-01-05 18:50 ` Junio C Hamano
2018-01-04 23:48 ` Junio C Hamano
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=xmqqo9m8cdvs.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=rpjday@crashcourse.ca \
--cc=sjanssen@you-get.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.