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

Re: [PATCHv6 5/7] worktree: add function to check if worktrees are in use

From
Stefan Beller <sbeller@google.com>
Date
Dec 8, 2016, 19:32 UTC
Message-ID
<CAGZ79kbNAZ81JqO+UEmKJC06oDRKWjxaF3Cb6jpZ3Xxo=des8g@mail.gmail.com>
In-Reply-To
<CACsJy8DMhC7Umnqf+-ViOBKn46Emtan4647=MDdLoYXVNB0=6A@mail.gmail.com>
On Thu, Dec 8, 2016 at 2:51 AM, Duy Nguyen <pclouds@gmail.com> wrote:
Show 17 quoted lines
> On Thu, Dec 8, 2016 at 5:40 PM, Duy Nguyen <pclouds@gmail.com> wrote:
>> Alternatively, we could add a new flag to get_worktrees() to tell it
>> to return all worktrees if there is a least one linked worktree, or
>> return NULL if there's only main worktree. I'm not sure if this is
>> clever or very stupid.
>
> No, this may be better. Add a flag to say "returns linked worktrees
> _only_". Which means when you're in a "normal" repo, get_worktrees()
> with this flag returns NULL. When you're in a multiple-worktree repo,
> it returns all linked worktrees (no main worktree). I think I might
> have a use for this flag in addition to this uses_worktrees() here.
> uses_worktrees() look quite simple with that flag
>
> int uses_worktrees(void)
> {
>     struct worktree **worktrees = get_worktrees(WT_LINKED_ONLY);
>     int retval = worktrees != NULL;

I am interested in the submodule case however, where we already return NULL e.g. when the submodule git dir cannot be found. Actually that would work out fine as well:

    /* NOTE on accuracy of result, hence not exposed. */
    static worktree **submodule_get_worktrees(const char *path, unsigned flags)
    ..
    int submodule_uses_worktrees(const char *path)
    {
        struct worktree **worktrees = submodule_get_worktrees(path,
WT_LINKED_ONLY);
        int retval = worktrees != NULL;
        free_worktrees(worktrees);
        return retval;
    }
Thanks for that inspiration!
Previous: Duy NguyenNext: Stefan Beller
Message 18 of 20 in “[PATCHv6 0/7] submodule embedgitdirs”
  1. Stefan BellerDec 8, 2016
  2. 1/7 submodule: use absolute path for computing relative path connectingStefan Beller, Dec 8, 2016
  3. Duy NguyenDec 8, 2016
  4. 2/7 submodule helper: support super prefixStefan Beller, Dec 8, 2016
  5. Duy NguyenDec 8, 2016
  6. Stefan BellerDec 8, 2016
  7. 4/7 worktree: get worktrees from submodulesStefan Beller, Dec 8, 2016
  8. Duy NguyenDec 8, 2016
  9. Stefan BellerDec 8, 2016
  10. Duy NguyenDec 9, 2016
  11. Brandon WilliamsDec 9, 2016
  12. Stefan BellerDec 9, 2016
  13. 7/7 submodule: add absorb-git-dir functionStefan Beller, Dec 8, 2016
  14. Duy NguyenDec 8, 2016
  15. 5/7 worktree: add function to check if worktrees are in useStefan Beller, Dec 8, 2016
  16. Duy NguyenDec 8, 2016
  17. Duy NguyenDec 8, 2016
  18. Stefan BellerDec 8, 2016
  19. 3/7 test-lib-functions.sh: teach test_commit -C <dir>Stefan Beller, Dec 8, 2016
  20. 6/7 move connect_work_tree_and_git_dir to dir.hStefan 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.