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 9, 2016, 12:00 UTC
Message-ID
<20161209120006.GA6609@ash>
In-Reply-To
<20161208210329.12919-5-sbeller@google.com>
On Thu, Dec 08, 2016 at 01:03:27PM -0800, Stefan Beller wrote:
Show 5 quoted lines
> +/*
> + * NEEDSWORK: The values in the returned worktrees are broken, e.g.
> + * the refs or path resolution is influenced by the current repository.
> + */
> +static struct worktree **get_submodule_worktrees(const char *path, unsigned flags)

I'm ok with this (at least we know the function is half-broken). But I wonder if we could go simpler, with something like this. It's more efficient as well. And we can replace its implementation with get_worktrees() or something when we are able to.

As long as this function stays in worktree.c I think it's ok for it to peek into "worktrees" directory directly. That's what all other functions in this file do after all.

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;
	while ((d = readdir(dir)) != NULL) {
		if (is_dot_or_dotdot(d->d_name))
			continue;
		ret = 1;
		break;
	}
	closedir(dir);
	return ret;
}
--
Duy
Previous: Stefan BellerNext: Stefan Beller
Message 7 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.