From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, Tian Yuchen <cat@malon.dev>
Subject: Re: [PATCH] read_gitfile_gently(): return non-repo path on error
Date: Tue, 02 Jun 2026 16:42:15 +0900 [thread overview]
Message-ID: <xmqq4ijlz8vc.fsf@gitster.g> (raw)
In-Reply-To: <20260602061159.GA693928@coredump.intra.peff.net> (Jeff King's message of "Tue, 2 Jun 2026 02:11:59 -0400")
Jeff King <peff@peff.net> writes:
> I've tried to make the minimally-invasive fix here:
>
> 1. We only copy the string when we hit READ_GITFILE_ERR_NOT_A_REPO,
> so other error codes don't have to worry about freeing it.
>
> 2. We'll turn read_gitfile_gently() into a wrapper which passes NULL
> by default, leaving other callers unaffected.
Nice, probably. I do not know what to feel about the first point,
though, as it burdens those who add new callers in the future more.
> The result is kind of gross. There's an extra layer of macro
> indirection, and the validity of the string is subtly tied to the
> NOT_A_REPO error. A cleaner solution might be an error struct that
> couples the code and the output string together, along with a function
> to free the error struct. But then all callers would have to be modified
> to call the free function. Alternatively, we could perhaps put a
> large-ish fixed-size buffer in the struct, though that means potential
> truncation and a larger stack footprint in each caller (even when they
> don't have see an error).
None of thoese are particularly appetizing ;-).
> So I've left that as possible work for the future, or maybe never. Some
> of this gross-ness was already there. For example, the only other caller
> of read_gitfile_error_die() is in submodule.c, and it also passes NULL
> for the "dir" parameter. But it does so only when the code is not
> NOT_A_REPO! So it is depending on the same subtle connection to avoid
> triggering the bug.
Yup. I can agree with this.
> ---
> Two other points of interest.
>
> One, I'm not sure how useful printing the pointed-to directory is. We
> _could_ just say:
>
> fatal: gitfile does not point to a valid repository: /path/to/.git
>
> which is enough for somebody to investigate themselves. That would
> certainly make the patch smaller.
Thanks. While reading the main explanation, it was the first thing
that came to me.
The implementation and the test are as expected in patches from you
and matches the intent explained in the log message exactly.
Thanks, will queue.
next prev parent reply other threads:[~2026-06-02 7:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-02 6:11 [PATCH] read_gitfile_gently(): return non-repo path on error Jeff King
2026-06-02 7:42 ` Junio C Hamano [this message]
2026-06-02 8:02 ` Jeff King
2026-06-02 8:36 ` Patrick Steinhardt
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=xmqq4ijlz8vc.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=cat@malon.dev \
--cc=git@vger.kernel.org \
--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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox