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

Re: [PATCH 2/2 v2] ls-files: add pathspec matching for submodules

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 23, 2016, 18:48 UTC
Message-ID
<xmqqfuoq1mh9.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1474500486-101640-1-git-send-email-bmwill@google.com>
Brandon Williams <bmwill@google.com> writes:
Show 12 quoted lines
> -	/* Find common prefix for all pathspec's */
> -	max_prefix = common_prefix(&pathspec);
> +	/*
> +	 * Find common prefix for all pathspec's
> +	 * This is used as a performance optimization which unfortunately cannot
> +	 * be done when recursing into submodules
> +	 */
> +	if (recurse_submodules)
> +		max_prefix = NULL;
> +	else
> +		max_prefix = common_prefix(&pathspec);
>  	max_prefix_len = max_prefix ? strlen(max_prefix) : 0;

This is OK for now, but for a future enhancement, I think we could do better than this. In a superproject with a submodule at "sub/", the current implementation of the common_prefix() helper would yield "sub/a/" when given "sub/a/x" and "sub/a/y" (a pathspec with two elements), which we want to avoid.

But somebody should be able to notice, before "sub/a/" is given to max_prefix here, that "sub/" is the leaf level in our repository and reduce the max_prefix to it. dir.c::common_prefix_len() might be a place we could do so, but I didn't think about the ramifications of doing so for other callers of common_prefix() or when we are not recursing into submodules. Doing it in the caller here, i.e.

	max_prefix = common_prefix(&pathspec);
        if (recurse_submodules)
        	max_prefix = chomp_at_submodule_boundary(max_prefix);
is certainly safer.

If the superproject has submodules at "a/b/{sub1,sub2,...}", this matters more. We do want to notice that we won't have to scan outside "a/b/" of the index given "a/b/sub1" and "a/b/sub2" as a pathspec.

The common_prefix_len() function also looks beyond symbolic links, which is another thing that we may want to think about. In a repository with a symbolic link "link" pointing somewhere else, when you give "link/a/x" and "link/a/y" (a pathspec with two elements), we would get "link/a/" as a common prefix, but we won't find anything underneath "link" in our index. In such a case, leaving the common prefix to "link/a/" _might_ allow us to notice that no pathspec elements can ever match, so not noticing that the common prefix points beyond a symbolic link might be a feature. I dunno.

Previous: Brandon WilliamsNext: Junio C Hamano
Message 6 of 29 in “ls-files: adding support for submodules”
  1. 1/2 ls-files: adding support for submodulesBrandon Williams, Sep 21, 2016
  2. 2/2 ls-files: add pathspec matching for submodulesBrandon Williams, Sep 21, 2016
  3. Junio C HamanoSep 21, 2016
  4. Brandon WilliamsSep 21, 2016
  5. 2/2 ls-files: add pathspec matching for submodulesBrandon Williams, Sep 21, 2016
  6. Junio C HamanoSep 23, 2016
  7. Junio C HamanoSep 23, 2016
  8. Brandon WilliamsSep 23, 2016
  9. Brandon WilliamsSep 21, 2016
  10. Junio C HamanoSep 21, 2016
  11. Brandon WilliamsSep 21, 2016
  12. 1/2 ls-files: optionally recurse into submodulesBrandon Williams, Sep 21, 2016
  13. Jeff KingSep 22, 2016
  14. Brandon WilliamsSep 23, 2016
  15. Junio C HamanoSep 21, 2016
  16. Jeff KingSep 22, 2016
  17. Stefan BellerSep 22, 2016
  18. Junio C HamanoSep 22, 2016
  19. Jeff KingSep 23, 2016
  20. Stefan BellerSep 23, 2016
  21. Jeff KingSep 23, 2016
  22. Brandon WilliamsSep 23, 2016
  23. Stefan BellerSep 23, 2016
  24. Nazri RamliySep 25, 2016
  25. Junio C HamanoSep 27, 2016
  26. Brandon WilliamsSep 27, 2016
  27. Junio C HamanoSep 27, 2016
  28. Brandon WilliamsSep 27, 2016
  29. Junio C HamanoSep 27, 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.