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

Re: [PATCHv7 4/6] worktree: have a function to check if worktrees are in use

From
Duy Nguyen <pclouds@gmail.com>
Date
Dec 10, 2016, 11:16 UTC
Message-ID
<CACsJy8CQD9QOhJzN7Dm8-=bjrZSEWM_03ETgroin-Lm6vKMuRw@mail.gmail.com>
In-Reply-To
<CAGZ79kaV4FYZEbRWQxKBHJg1jVzOkte1QxLZgu75=Jja_BMRGQ@mail.gmail.com>
On Sat, Dec 10, 2016 at 1:49 AM, Stefan Beller <sbeller@google.com> wrote:
Show 18 quoted lines
> On Fri, Dec 9, 2016 at 4:00 AM, Duy Nguyen <pclouds@gmail.com> wrote:
>
>> int submodule_uses_worktrees(const char *path)
>> {
>>         struct strbuf path = STRBUF_INIT;
>>         DIR *dir;
>>         struct dirent *d;
>>         int ret = 0;
>>
>>         strbuf_addf(&path, "%s/worktrees", path);
>>         dir = opendir(path.buf);
>>         strbuf_release(&path);
>>
>>         if (!dir)
>>                 return 0;
>
> The submodule may be one of the linked worktrees, which would be
> caught if we use the code as I sent it out?

I think I simplified it too much, there should still be a git_common_dir_noenv() to retrieve the correct common dir in the submodule from gitdir. Then, if the repo in question has any linked worktrees, you probably can't handle it. It does not matter if the submodule gitdir in question is a linked or main worktree.

> If this is one of the linked worktrees, we'd rather check if a file
> "commondir" or "gitdir" exists?

Well, in theory yes. But we're apparently not ready for that. If you check the files exist, but the files are not valid, then it's still not considered a worktree. Which is not much different from what we do here (if the directory exists, assuming it's a worktree). It should catch all the valid worktrees. But yes it could give some false positive. Since we're just using this function to stop the aborbing git dir operation, i think this is acceptable.

(It goes even trickier, even get_worktrees() won't detect if the linked worktree is already dead, .e.g. deleted manually, I believe. Those have to be cleaned up by 'git worktree prune' which does even more checks before it declare "this directory is garbage").

> I ask that because I would not know how to relocate such a linked
> worktree gitdir?
-- 
Duy
Previous: Stefan BellerNext: Stefan Beller
Message 9 of 10 in “[PATCHv7 0/6] submodule absorbgitdirs”
  1. Stefan BellerDec 8, 2016
  2. 1/6 submodule: use absolute path for computing relative path connectingStefan Beller, Dec 8, 2016
  3. 2/6 submodule helper: support super prefixStefan Beller, Dec 8, 2016
  4. 5/6 move connect_work_tree_and_git_dir to dir.hStefan Beller, Dec 8, 2016
  5. 3/6 test-lib-functions.sh: teach test_commit -C <dir>Stefan Beller, Dec 8, 2016
  6. 4/6 worktree: have a function to check if worktrees are in useStefan Beller, Dec 8, 2016
  7. Duy NguyenDec 9, 2016
  8. Stefan BellerDec 9, 2016
  9. Duy NguyenDec 10, 2016
  10. 6/6 submodule: add absorb-git-dir functionStefan Beller, Dec 8, 2016

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.