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

Re: [PATCH 1/2] Reimplement read_tree_recursive() using tree_entry_interesting()

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 24, 2011, 19:55 UTC
Message-ID
<7vlj048f97.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1300977675-6243-1-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
> +static int read_tree_1(struct tree *tree, struct strbuf *base,
> +		       int stage, struct pathspec *pathspecs,
> +		       read_tree_fn_t fn, void *context)
Micronit: call the variable pathspec, not pathspecs.

An instance of the structure contains a specification to limit the set of paths to operate on as a set of pathspec elements, and this single set is collectively called a "struct pathspec"; you are not passing an array that has one or more pathspecs in it here (i.e. pathspecs[2] in this function does not make sense).

It looks like the result is easier to follow, perhaps mostly thanks to the (re)use of strbuf instead of allocating a new path when going deeper.

Show 18 quoted lines
> @@ -108,10 +60,22 @@ int read_tree_recursive(struct tree *tree,
>  	init_tree_desc(&desc, tree->buffer, tree->size);
>  
>  	while (tree_entry(&desc, &entry)) {
> -		if (!match_tree_entry(base, baselen, entry.path, entry.mode, match))
> +		if (all_interesting)
> +			retval = all_interesting > 0;
> +		else {
> +			retval = tree_entry_interesting(&entry, base, 0, pathspecs);
> +			if (retval == 2)
> +				all_interesting = 1;
> +			else if (retval == -1) {
> +				all_interesting = -1;
> +				retval = 0;
> +			}
> +		}
> +		if (!retval)
>  			continue;

This "if all-interesting then avoid calling into an expensive matcher" logic looks familiar but is not something that came from the parts deleted by this patch. Where did I see it? Is that something we can share in a common helper function? Is such a sharing worth pursuing, considering that the above is a reasonably trivial logic in a tight loop?

"That's how the return value of tree-entry-interesting is designed to be used, and it is unsurprising that all the callers will fall into that pattern" is a perfectly acceptable answer, I guess.

Thanks.
Previous: Junio C HamanoNext: Nguyễn Thái Ngọc Duy
Message 18 of 28 in “Relative ls-files”
  1. John TapsellMar 23, 2011
  2. Michael J GruberMar 23, 2011
  3. John TapsellMar 23, 2011
  4. demerphqMar 23, 2011
  5. Michael J GruberMar 23, 2011
  6. Martin LanghoffMar 23, 2011
  7. Junio C HamanoMar 23, 2011
  8. Nguyen Thai Ngoc DuyMar 23, 2011
  9. Junio C HamanoMar 23, 2011
  10. Nguyen Thai Ngoc DuyMar 23, 2011
  11. Junio C HamanoMar 23, 2011
  12. Nguyen Thai Ngoc DuyMar 24, 2011
  13. 1/2 Reimplement read_tree_recursive() using tree_entry_interesting()Nguyễn Thái Ngọc Duy, Mar 24, 2011
  14. 2/2 Convert read_tree{,_recursive} to support struct pathspecNguyễn Thái Ngọc Duy, Mar 24, 2011
  15. Nguyen Thai Ngoc DuyMar 24, 2011
  16. Junio C HamanoMar 24, 2011
  17. Junio C HamanoMar 24, 2011
  18. Junio C HamanoMar 24, 2011
  19. 1/3 Reimplement read_tree_recursive() using tree_entry_interesting()Nguyễn Thái Ngọc Duy, Mar 25, 2011
  20. 2/3 Convert read_tree{,_recursive} to support struct pathspecNguyễn Thái Ngọc Duy, Mar 25, 2011
  21. 3/3 Improve tree_entry_interesting() handling codeNguyễn Thái Ngọc Duy, Mar 25, 2011
  22. Junio C HamanoMar 24, 2011
  23. Martin LanghoffMar 23, 2011
  24. Junio C HamanoMar 23, 2011
  25. Junio C HamanoMar 23, 2011
  26. Junio C HamanoMar 23, 2011
  27. Michael J GruberMar 23, 2011
  28. Nguyen Thai Ngoc DuyMar 23, 2011

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.