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

Re: [PATCH] setup: do not create $X/gitdir unnecessarily when accessing git file $X

From
Jeff King <peff@peff.net>
Date
Nov 2, 2015, 20:35 UTC
Message-ID
<20151102203507.GB10722@sigill.intra.peff.net>
In-Reply-To
<1446491306-13493-1-git-send-email-pclouds@gmail.com>
On Mon, Nov 02, 2015 at 08:08:26PM +0100, Nguyễn Thái Ngọc Duy wrote:
Show 7 quoted lines
> $X/gitdir is created, or refreshed, in order to keep a linked worktree
> from being pruned. But while git file is used as the foundation for
> linked worktrees, it's used for other purposes as well and we should
> not create $X/gitdir in those cases.
> 
> Tighten the check. Only update an existing file, which is an
> indication this is a linked worktree.

Hrm. I think this fixes the immediate problem, but it seems odd for us to rely on "does the file exist"[1].

We trigger this code unconditionally from read_gitfile_gently(). But .git files are a general-purpose mechanism. Shouldn't we be doing this only if we suspect we are working with a linked working tree directory in the first place?

Or we do not know at all, because we are operating in the linked dir, and seeing the presence of the "gitdir" file is the only way we say "ah, it turns out we are linked, so we should take the opportunity to do some maintenance"?

If the latter, then I guess this is the only way to do it. It does seem a bit strange to me that an otherwise read-only operation (reading the file) might involve writing[2].

-Peff
[1] You check only !stat(), so it is not really "does it exist", but
    "can we stat it". I think that is OK, because this is an
    opportunistic update, and failing the stat should just mean we don't
    do the update.
[2] I suspect this code should use write_file_gently(). What happens if
    I have a read-only linked checkout?
Previous: Eric SunshineNext: Junio C Hamano
Message 10 of 18 in “What's the ".git/gitdir" file?”
  1. Kyle MeyerOct 27, 2015
  2. Stefan BellerOct 27, 2015
  3. Randall S. BeckerOct 27, 2015
  4. Stefan BellerOct 27, 2015
  5. Junio C HamanoOct 27, 2015
  6. Mike RappazzoOct 27, 2015
  7. Junio C HamanoOct 28, 2015
  8. setup: do not create $X/gitdir unnecessarily when accessing git file $XNguyễn Thái Ngọc Duy, Nov 2, 2015
  9. Eric SunshineNov 2, 2015
  10. Jeff KingNov 2, 2015
  11. Junio C HamanoNov 2, 2015
  12. Jeff KingNov 2, 2015
  13. Duy NguyenNov 3, 2015
  14. Junio C HamanoNov 3, 2015
  15. worktree: stop supporting moving worktrees manuallyNguyễn Thái Ngọc Duy, Dec 27, 2015
  16. Eric SunshineDec 28, 2015
  17. Duy NguyenDec 29, 2015
  18. Eric SunshineDec 31, 2015

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.