From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>,
Duy Nguyen <pclouds@gmail.com>,
Brandon Williams <bmwill@google.com>
Subject: Re: [PATCH v5 10/11] setup_git_directory_gently_1(): avoid die()ing
Date: Mon, 13 Mar 2017 20:38:41 +0100 (CET) [thread overview]
Message-ID: <alpine.DEB.2.20.1703131826330.3767@virtualbox> (raw)
In-Reply-To: <xmqqefy5yn4k.fsf@gitster.mtv.corp.google.com>
Hi Junio,
PLEASE NOTE: the purpose of this patch series is to allow the same
function (setup_git_directory_gently_1()) to be the work horse for
setup_git_directory() as before, but also for the new
discover_git_directory() function that is introduced to fix
read_early_config() to avoid hardconfig .git/config.
The purpose is *not* to change any current behavior. Please do not ask me
to do that in this patch series.
Now to your comments:
On Fri, 10 Mar 2017, Junio C Hamano wrote:
> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
>
> > @@ -890,14 +892,22 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
> > if (one_filesystem)
> > current_device = get_device_or_die(dir->buf, NULL, 0);
> > for (;;) {
> > - int offset = dir->len;
> > + int offset = dir->len, error_code = 0;
> >
> > if (offset > min_offset)
> > strbuf_addch(dir, '/');
> > strbuf_addstr(dir, DEFAULT_GIT_DIR_ENVIRONMENT);
> > - gitdirenv = read_gitfile(dir->buf);
> > - if (!gitdirenv && is_git_directory(dir->buf))
> > - gitdirenv = DEFAULT_GIT_DIR_ENVIRONMENT;
> > + gitdirenv = read_gitfile_gently(dir->buf, die_on_error ?
> > + NULL : &error_code);
> > + if (!gitdirenv) {
>
> We tried to read ".git" as a regular file, but couldn't. There are
> some cases but I am having trouble to convince myself all cases are
> covered correctly here, so let me follow the code aloud.
It is subtle and finicky, I agree.
> > + if (die_on_error ||
> > + error_code == READ_GITFILE_ERR_NOT_A_FILE) {
> > + if (is_git_directory(dir->buf))
> > + gitdirenv = DEFAULT_GIT_DIR_ENVIRONMENT;
>
> If we are told to die on error, but if it is a Git directory, then
> we do not have to (and want to) die and instead report that
> directory as discovered.
>
> If we are to report the failure status instead of dying, we also do
> want to recover when the read_gitfile_gentrly() failed only because
> it was a real Git directory. READ_GITFILE_ERR_NOT_A_FILE could be a
> signal for that, and we recover after making sure it is a Git
> directory.
>
> Among the READ_GITFILE_ERR_* codes, ERR_NOT_A_FILE is the only one
> we attempt this recovery. All others just take the "else if" thing
> below.
>
> What happens when is_git_directory() test here does not pass,
> though? Let's say stat() in read_gitfile_gently() found a FIFO
> there, it gives us ERR_NOT_A_FILE, is_git_directory() would say
> "Nah", and then ...? Don't we want the other side for this if()
> statement that returns failure?
The current code as per `master` detects the NOT_A_FILE condition, and as
the parameter return_error_code was passed as NULL (because read_gitfile is
actually #define'd in cache.h to call read_gitfile_gently with NULL as
second parameter), it calls read_gitfile_error_die(). That function
*ignores* the NOT_A_FILE error condition, and as a consequence returns to
read_gitfile_gently() which then returns NULL because there *was* an
error_code.
That means that setup_git_directory_gently_1() will retrieve a NULL from
the read_gitfile() call, which means it then goes on to test whether it
is looking at a .git/ directory via is_git_directory() and if that returns
false, the loop will continue to look at the *parent* directory.
That, in turn, means that what you are asking for is a change in behavior,
and as I am unwilling to introduce a change in behavior with this patch
series, my patch does the exact right thing.
> > + } else if (error_code &&
> > + error_code != READ_GITFILE_ERR_STAT_FAILED)
> > + return GIT_DIR_INVALID_GITFILE;
> > + }
>
> On the other hand, if read_gitfile_gently() didn't say "we found
> something that is not a regular file" we come here. If the error
> came because there wasn't ".git" in the directory we are looking at,
> i.e. stat(2) in read_gitfile_gently() gave ENOENT, it is perfectly
> normal and we just want to go one level up.
>
> But shouldn't read_gitfile_gently() be inspecting errno when it sees
> a stat() failure? If there _is_ ".git" but we failed to stat it for
> whatever reason (EACCES, ELOOP,...), we do not want to go up but
> give the INVALID_GITFILE from here, just like other cases, no?
> For that I imagine that ERR_STAT_FAILED needs to be split into two,
> one for true ERR_STAT_FAILED (from which we cannot recover) and the
> other for ERR_ENOENT to signal us that there is nothing there (which
> allows us to go up).
True. But again, you are asking for a *change in behavior*, which is not
the purpose of this patch series.
> By the way, is the "error_code &&" needed?
It is not! I had the order of the if/else blocks completely differently
originally [*1*] and just overlooked that the error_code could no longer
be 0 in that condition.
Ciao,
Dscho
Footnote *1*: Yes, I wanted to construct an English sentence with three
-ly words in a row.
next prev parent reply other threads:[~2017-03-13 19:39 UTC|newest]
Thread overview: 123+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-08 15:35 [PATCH/RFC 0/7] Pie-in-the-sky attempt to fix the early config Johannes Schindelin
2016-12-08 15:36 ` [PATCH/RFC 1/7] Make read_early_config() reusable Johannes Schindelin
2016-12-08 15:36 ` [PATCH/RFC 2/7] read_early_config(): avoid .git/config hack when unneeded Johannes Schindelin
2016-12-08 15:36 ` [PATCH/RFC 3/7] Mark builtins that create .git/ directories Johannes Schindelin
2016-12-08 15:36 ` [PATCH/RFC 4/7] read_early_config(): special-case `init` and `clone` Johannes Schindelin
2016-12-08 15:36 ` [PATCH/RFC 5/7] read_early_config(): really discover .git/ Johannes Schindelin
2016-12-08 15:36 ` [PATCH/RFC 6/7] WIP read_config_early(): respect ceiling directories Johannes Schindelin
2016-12-08 15:36 ` [PATCH/RFC 7/7] WIP: read_early_config(): add tests Johannes Schindelin
2016-12-08 17:26 ` [PATCH/RFC 0/7] Pie-in-the-sky attempt to fix the early config Jeff King
2016-12-09 17:28 ` Johannes Schindelin
2016-12-09 17:55 ` Jeff King
2016-12-09 12:42 ` Duy Nguyen
2016-12-09 16:52 ` Johannes Schindelin
2017-03-03 2:03 ` [PATCH v2 0/9] Fix " Johannes Schindelin
2017-03-03 2:04 ` [PATCH v2 1/9] t7006: replace dubious test Johannes Schindelin
2017-03-03 3:36 ` Jeff King
2017-03-03 11:10 ` Johannes Schindelin
2017-03-03 2:04 ` [PATCH v2 2/9] setup_git_directory(): use is_dir_sep() helper Johannes Schindelin
2017-03-03 3:37 ` Jeff King
2017-03-03 11:16 ` Johannes Schindelin
2017-03-03 11:26 ` Jeff King
2017-03-03 15:35 ` Johannes Schindelin
2017-03-03 2:04 ` [PATCH v2 3/9] setup_git_directory(): avoid changing global state during discovery Johannes Schindelin
2017-03-03 4:24 ` Jeff King
2017-03-03 13:54 ` Johannes Schindelin
2017-03-03 2:04 ` [PATCH v2 4/9] Export the discover_git_directory() function Johannes Schindelin
2017-03-03 4:45 ` Jeff King
2017-03-03 14:49 ` Johannes Schindelin
2017-03-03 2:04 ` [PATCH v2 5/9] Make read_early_config() reusable Johannes Schindelin
2017-03-03 4:46 ` Jeff King
2017-03-03 14:11 ` Johannes Schindelin
2017-03-03 2:04 ` [PATCH v2 6/9] read_early_config(): special-case builtins that create a repository Johannes Schindelin
2017-03-03 4:51 ` Jeff King
2017-03-03 15:11 ` Johannes Schindelin
2017-03-03 2:04 ` [PATCH v2 7/9] read_early_config(): avoid .git/config hack when unneeded Johannes Schindelin
2017-03-03 4:51 ` Jeff King
2017-03-03 2:04 ` [PATCH v2 8/9] read_early_config(): really discover .git/ Johannes Schindelin
2017-03-03 5:06 ` Jeff King
2017-03-03 15:26 ` Johannes Schindelin
2017-03-03 2:04 ` [PATCH v2 9/9] Test read_early_config() Johannes Schindelin
2017-03-03 5:07 ` Jeff King
2017-03-03 15:04 ` Johannes Schindelin
2017-03-03 5:14 ` [PATCH v2 0/9] Fix the early config Jeff King
2017-03-03 15:31 ` Johannes Schindelin
2017-03-03 17:31 ` [PATCH v3 " Johannes Schindelin
2017-03-03 17:32 ` [PATCH v3 1/9] t7006: replace dubious test Johannes Schindelin
2017-03-03 17:32 ` [PATCH v3 2/9] setup_git_directory(): use is_dir_sep() helper Johannes Schindelin
2017-03-03 17:32 ` [PATCH v3 3/9] Prepare setup_discovered_git_directory() the root directory Johannes Schindelin
2017-03-03 17:32 ` [PATCH v3 4/9] setup_git_directory_1(): avoid changing global state Johannes Schindelin
2017-03-03 17:33 ` [PATCH v3 5/9] Export the discover_git_directory() function Johannes Schindelin
2017-03-03 17:33 ` [PATCH v3 6/9] Make read_early_config() reusable Johannes Schindelin
2017-03-03 17:33 ` [PATCH v3 7/9] read_early_config(): avoid .git/config hack when unneeded Johannes Schindelin
2017-03-03 17:33 ` [PATCH v3 8/9] read_early_config(): really discover .git/ Johannes Schindelin
2017-03-03 17:33 ` [PATCH v3 9/9] Test read_early_config() Johannes Schindelin
2017-03-03 21:35 ` [PATCH v3 0/9] Fix the early config Junio C Hamano
2017-03-07 11:55 ` Johannes Schindelin
2017-03-07 15:18 ` Johannes Schindelin
2017-03-04 7:39 ` Jeff King
2017-03-05 3:36 ` Junio C Hamano
2017-03-07 14:31 ` Johannes Schindelin
2017-03-08 7:30 ` Jeff King
2017-03-08 16:18 ` Johannes Schindelin
2017-03-08 16:29 ` Jeff King
2017-03-08 17:09 ` Junio C Hamano
2017-03-08 17:42 ` Jeff King
2017-03-08 22:43 ` Junio C Hamano
2017-03-09 11:51 ` Johannes Schindelin
2017-03-09 12:16 ` Jeff King
2017-03-10 16:39 ` Junio C Hamano
2017-03-07 14:32 ` [PATCH v4 00/10] " Johannes Schindelin
2017-03-07 14:32 ` [PATCH v4 01/10] t7006: replace dubious test Johannes Schindelin
2017-03-07 14:32 ` [PATCH v4 02/10] setup_git_directory(): use is_dir_sep() helper Johannes Schindelin
2017-03-07 14:32 ` [PATCH v4 03/10] Prepare setup_discovered_git_directory() the root directory Johannes Schindelin
2017-03-07 14:32 ` [PATCH v4 04/10] setup_git_directory_1(): avoid changing global state Johannes Schindelin
2017-03-07 23:24 ` Junio C Hamano
2017-03-07 23:35 ` Brandon Williams
2017-03-08 0:57 ` Johannes Schindelin
2017-03-08 2:10 ` Brandon Williams
2017-03-07 14:33 ` [PATCH v4 05/10] Introduce the discover_git_directory() function Johannes Schindelin
2017-03-07 14:33 ` [PATCH v4 06/10] Make read_early_config() reusable Johannes Schindelin
2017-03-07 14:33 ` [PATCH v4 07/10] read_early_config(): avoid .git/config hack when unneeded Johannes Schindelin
2017-03-07 14:33 ` [PATCH v4 08/10] read_early_config(): really discover .git/ Johannes Schindelin
2017-03-07 14:33 ` [PATCH v4 09/10] Test read_early_config() Johannes Schindelin
2017-03-07 14:33 ` [PATCH v4 10/10] setup_git_directory_gently_1(): avoid die()ing Johannes Schindelin
2017-03-09 22:23 ` [PATCH v5 00/11] Fix the early config Johannes Schindelin
2017-03-09 22:23 ` [PATCH v5 01/11] t7006: replace dubious test Johannes Schindelin
2017-03-09 22:23 ` [PATCH v5 02/11] setup_git_directory(): use is_dir_sep() helper Johannes Schindelin
2017-03-09 22:23 ` [PATCH v5 03/11] Prepare setup_discovered_git_directory() the root directory Johannes Schindelin
2017-03-09 22:24 ` [PATCH v5 04/11] setup_git_directory_1(): avoid changing global state Johannes Schindelin
2017-03-10 19:34 ` Junio C Hamano
2017-03-09 22:24 ` [PATCH v5 05/11] Introduce the discover_git_directory() function Johannes Schindelin
2017-03-09 22:24 ` [PATCH v5 06/11] Make read_early_config() reusable Johannes Schindelin
2017-03-09 22:24 ` [PATCH v5 07/11] read_early_config(): avoid .git/config hack when unneeded Johannes Schindelin
2017-03-09 22:25 ` [PATCH v5 08/11] read_early_config(): really discover .git/ Johannes Schindelin
2017-03-09 22:25 ` [PATCH v5 09/11] Test read_early_config() Johannes Schindelin
2017-03-10 19:02 ` Junio C Hamano
2017-03-13 17:19 ` Johannes Schindelin
2017-03-13 17:32 ` Junio C Hamano
2017-03-09 22:25 ` [PATCH v5 10/11] setup_git_directory_gently_1(): avoid die()ing Johannes Schindelin
2017-03-10 18:58 ` Junio C Hamano
2017-03-13 19:38 ` Johannes Schindelin [this message]
2017-03-13 19:47 ` Junio C Hamano
2017-03-13 20:20 ` Junio C Hamano
2017-03-13 21:46 ` Johannes Schindelin
2017-03-13 23:31 ` Junio C Hamano
2017-03-09 22:25 ` [PATCH v5 11/11] t1309: document cases where we would want early config not to die() Johannes Schindelin
2017-03-13 20:09 ` [PATCH v6 00/12] Fix the early config Johannes Schindelin
2017-03-13 20:09 ` [PATCH v6 01/12] t7006: replace dubious test Johannes Schindelin
2017-03-13 20:09 ` [PATCH v6 02/12] setup_git_directory(): use is_dir_sep() helper Johannes Schindelin
2017-03-13 20:09 ` [PATCH v6 03/12] Prepare setup_discovered_git_directory() the root directory Johannes Schindelin
2017-03-13 20:34 ` Junio C Hamano
2017-03-13 21:44 ` Johannes Schindelin
2017-03-13 20:10 ` [PATCH v6 04/12] setup_git_directory_1(): avoid changing global state Johannes Schindelin
2017-03-13 20:10 ` [PATCH v6 05/12] Introduce the discover_git_directory() function Johannes Schindelin
2017-03-13 20:11 ` [PATCH v6 06/12] Make read_early_config() reusable Johannes Schindelin
2017-03-13 20:11 ` [PATCH v6 07/12] read_early_config(): avoid .git/config hack when unneeded Johannes Schindelin
2017-03-13 20:11 ` [PATCH v6 08/12] read_early_config(): really discover .git/ Johannes Schindelin
2017-03-13 20:11 ` [PATCH v6 09/12] Add t1309 to test read_early_config() Johannes Schindelin
2017-03-13 20:11 ` [PATCH v6 10/12] setup_git_directory_gently_1(): avoid die()ing Johannes Schindelin
2017-03-13 20:11 ` [PATCH v6 11/12] t1309: document cases where we would want early config not to die() Johannes Schindelin
2017-03-13 20:12 ` [PATCH v6 12/12] setup.c: mention unresolved problems Johannes Schindelin
2017-03-13 22:31 ` [PATCH v6 00/12] Fix the early config Junio C Hamano
2017-03-14 18:01 ` Jeff King
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.20.1703131826330.3767@virtualbox \
--to=johannes.schindelin@gmx.de \
--cc=bmwill@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).