git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [GSoC] [PATCH 1/1] t0001: replace "test [-d|-f]" with test_path_is_* functions

From
Shaoxuan Yuan <shaoxuan.yuan02@gmail.com>
Date
Jan 24, 2022, 05:56 UTC
Message-ID
<CAJyCBORyjNaPXshQrGjbrUCUv832MJsNew6ez-EOWJo2od9a8g@mail.gmail.com>
In-Reply-To
<xmqqr190g6gd.fsf@gitster.g>
On Sat, Jan 22, 2022 at 4:49 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 31 quoted lines
>
> Taylor Blau <me@ttaylorr.com> writes:
>
> >> -    if test -d "$1" && test -f "$1/config" && test -d "$1/refs"
> >> +    if test_path_is_dir "$1" && test_path_is_file "$1/config" && test_path_is_dir "$1/refs"
> >>      then
> >>              : happy
> >>      else
> >
> > Looks very reasonable to me. Indeed, this line comes from 6adcca3fe8
> > (Fix initialization of a bare repository, 2007-08-27) which predates
> > 2caf20c52b (test-lib: user-friendly alternatives to test [-d|-f|-e],
> > 2010-08-10) when these helpers were originally introduced.
> >
> > I thought that we could probably just shorten this to calling
> > "test_path_is_file" twice: once for "$1/config" and a second time for
> > "$1/refs", but that assumes "$1" is non-empty. And to ensure that you'd
> > need another check, which amounts to the same amount of code overall.
>
> I had the same thought.
>
> Since the first "$GIT_DIR must be a directory" matters only when the
> caller is crazy enough to have a bare repository at the root of the
> filesystem and to think that it is a good idea to say "" is the
> "$GIT_DIR" (in which case, "test -d ''" would fail, even though the
> tests for /config and /refs are checking the right thing), I do not
> see much downside from omitting the first one, but I think that is
> something we need to do _outside_ the topic of this change, which is
> purely "modernize, using the helpers we already have, without
> changing what we do"
>
Yes I feel the same way, one patch for one thing :)
Previous: Junio C HamanoNext: Shaoxuan Yuan
Message 5 of 13 in “t0001: replace "test [-d|-f]" with test_path_is_* functions”
  1. Shaoxuan YuanJan 21, 2022
  2. [GSoC] [PATCH 1/1] t0001: replace "test [-d|-f]" with test_path_is_* functionsShaoxuan Yuan, Jan 21, 2022
  3. Taylor BlauJan 21, 2022
  4. Junio C HamanoJan 21, 2022
  5. Shaoxuan YuanJan 24, 2022
  6. Shaoxuan YuanFeb 10, 2022
  7. Junio C HamanoFeb 10, 2022
  8. Shaoxuan YuanFeb 10, 2022
  9. Junio C HamanoFeb 10, 2022
  10. Shaoxuan YuanFeb 11, 2022
  11. Junio C HamanoFeb 11, 2022
  12. Christian CouderFeb 14, 2022
  13. Shaoxuan YuanFeb 14, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.