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

Re: [PATCH v2] contrib/subtree: fix split with squashed subtrees

From
CSColin Stagner <ask+git@howdoi.land>
Date
Sep 10, 2025, 03:00 UTC
Message-ID
<641aaa9b-2b23-4faf-a13e-f6205e9ef5a2@howdoi.land>
In-Reply-To
<xmqqbjnjt67y.fsf@gitster.g>
On 9/9/25 21:02, Junio C Hamano wrote:
Show 7 quoted lines
> Besides, "if test -n ${subtree_dir-}" without colon would be the
> more proper way for those who care about "set -u", wouldn't it?  It
> is not that you want to substitute with an empty string that comes
> between that "-" and "}" when subtree_dir is unset or set to empty.
> You are preparing for the case where the variable is truly not set,
> and the variable being set to an empty string is not something you
> are worried about.
Yes, "test -n ${subtree_dir-}" is definitely the more correct expression.

At the very real risk of embarrassing myself in public today... in the particular case of a "test -n," is there actually an appreciable difference? Either way, the output of the substitution is empty if the input is empty or undefined. Here, "test -n ${subtree_dir:-}" is merely less efficient. Right?

The difference between "${x:-}" vs "${x-}" really starts to matter if you want to permit the empty string (or not). It also matters if you call a command that has side effects.

(And in the context of this patch, neither are necessary.)
Previous: Junio C HamanoNext: Junio C Hamano
Message 11 of 15 in “contrib/subtree: fix split with squashed subtrees”
  1. contrib/subtree: fix split with squashed subtreesColin Stagner, Aug 24, 2025
  2. Phillip WoodSep 1, 2025
  3. Colin StagnerSep 1, 2025
  4. Phillip WoodSep 2, 2025
  5. Phillip WoodSep 2, 2025
  6. Colin StagnerSep 4, 2025
  7. contrib/subtree: fix split with squashed subtreesColin Stagner, Sep 5, 2025
  8. Phillip WoodSep 8, 2025
  9. Colin StagnerSep 10, 2025
  10. Junio C HamanoSep 10, 2025
  11. Colin StagnerSep 10, 2025
  12. Junio C HamanoSep 10, 2025
  13. contrib/subtree: fix split with squashed subtreesColin Stagner, Sep 10, 2025
  14. Phillip WoodSep 10, 2025
  15. Junio C HamanoSep 11, 2025

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.