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

Re: [PATCH v2 2/4] worktree: link worktrees with relative paths

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Oct 7, 2024, 04:02 UTC
Message-ID
<CAPig+cQjHCZChToM_nEhmQsXedK4nEObs7YV2Q2PzrZqcHB4fQ@mail.gmail.com>
In-Reply-To
<ZwNZRX1LHlxawJJc@ArchLinux>
On Sun, Oct 6, 2024 at 11:45 PM shejialuo <shejialuo@gmail.com> wrote:
Show 9 quoted lines
> Actually, I somehow understand why in the original code, it will use
> "xstrdup_or_null" to initialize the "backlink". Because in
> "read_gitfile_gently", we will use a static "struct strbuf" as the
> buffer.
>
> I guess the intention of the original code is that if we call again
> "read_gitfile_gently" in this function or we have another thread which
> calls this function, the content of the buffer will be changed. So we
> explicitly use "xstrdup_or_null" to create a copy here to avoid this.

That's correct. The code is being defensive in case the static strbuf inside read_gitfile_gently() gets overwritten.

> But I wonder whether we really need to consider above problem?

It's easier to reason about the code in this function if we don't have to worry about the underlying static strbuf. Also, this is not a hot path so the extra allocation and string copy is not a concern. As such, it makes sense for the code to remain robust (by creating the copy) rather than becoming potentially more fragile by eliminating the string copy.

Previous: shejialuoNext: Caleb White
Message 25 of 38 in “Link worktrees with relative paths”
  1. 0/4 Link worktrees with relative pathsCaleb White, Oct 6, 2024
  2. 1/4 worktree: refactor infer_backlink() to use *strbufCaleb White, Oct 6, 2024
  3. shejialuoOct 6, 2024
  4. Kristoffer HaugsbakkOct 6, 2024
  5. Eric SunshineOct 6, 2024
  6. Caleb WhiteOct 7, 2024
  7. shejialuoOct 7, 2024
  8. Caleb WhiteOct 7, 2024
  9. shejialuoOct 7, 2024
  10. Caleb WhiteOct 7, 2024
  11. shejialuoOct 7, 2024
  12. Caleb WhiteOct 7, 2024
  13. shejialuoOct 7, 2024
  14. Caleb WhiteOct 6, 2024
  15. Eric SunshineOct 6, 2024
  16. Caleb WhiteOct 7, 2024
  17. Eric SunshineOct 7, 2024
  18. Caleb WhiteOct 7, 2024
  19. 2/4 worktree: link worktrees with relative pathsCaleb White, Oct 6, 2024
  20. Eric SunshineOct 6, 2024
  21. Caleb WhiteOct 6, 2024
  22. shejialuoOct 6, 2024
  23. Caleb WhiteOct 6, 2024
  24. shejialuoOct 7, 2024
  25. Eric SunshineOct 7, 2024
  26. Caleb WhiteOct 7, 2024
  27. 3/4 worktree: sync worktree paths after gitdir moveCaleb White, Oct 6, 2024
  28. Eric SunshineOct 6, 2024
  29. Caleb WhiteOct 6, 2024
  30. Eric SunshineOct 6, 2024
  31. Caleb WhiteOct 6, 2024
  32. Eric SunshineOct 6, 2024
  33. 4/4 worktree: prevent null pointer dereferenceCaleb White, Oct 6, 2024
  34. Eric SunshineOct 6, 2024
  35. Caleb WhiteOct 6, 2024
  36. Eric SunshineOct 6, 2024
  37. Caleb WhiteOct 7, 2024
  38. Eric SunshineOct 6, 2024

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.