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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Dec 10, 2016 at 1:49 AM, Stefan Beller <sbeller@xxxxxxxxxx> wrote:
> On Fri, Dec 9, 2016 at 4:00 AM, Duy Nguyen <pclouds@xxxxxxxxx> 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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]