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

Re: [PATCH] ls-files: fix overeager pathspec optimization

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Jan 8, 2010, 23:24 UTC
Message-ID
<alpine.LFD.2.00.1001081520240.7821@localhost.localdomain>
In-Reply-To
<7veim0w68q.fsf_-_@alter.siamese.dyndns.org>
On Fri, 8 Jan 2010, Junio C Hamano wrote:
Show 8 quoted lines
>
> Given pathspecs that share a common prefix, ls-files optimized its call
> into recursive directory reader by starting at the common prefix
> directory.
> 
> If you have a directory "t" with an untracked file "t/junk" in it, but the
> top-level .gitignore file told us to ignore "t/", this resulted in an
> unexpected behaviour:

Ok, I'm not sure how "unexpected" this is, since arguably you are overriding the ignore file by _being_ in that directory (the same way index contents override ignore files), but I could go either way on that.

Your patch looks fine, although I think you did this in a very odd way.
Show 11 quoted lines
> +	at = 0;
> +	memcpy(path, path_, len);
> +	while (1) {
> +		char *cp;
> +		path[at] = '\0';
> +		/*
> +		 * NOTE! NOTE! NOTE!: we might want to actually lstat(2)
> +		 * path[] to make sure it is a directory.
> +		 */
> +		if (excluded(dir, path, &dtype))
> +			return 1;

The above starts by testing the empty string, and then after that test it goes on to the next directory component. That is just _odd_.

Wouldn't it be more natural to write the loop the other way around, ie _first_ look up the next directory component, and _then_ do the exclude processing for thoose components?

Or is there some subtle reason I'm missing for actually checking the empty name?

				Linus
Previous: Junio C HamanoNext: Junio C Hamano
Message 13 of 28 in “Possible bug in git-completion.sh”
  1. Jon ScheweJan 8, 2010
  2. Michael J GruberJan 8, 2010
  3. Jeff KingJan 8, 2010
  4. Junio C HamanoJan 8, 2010
  5. Jeff KingJan 8, 2010
  6. Junio C HamanoJan 8, 2010
  7. Junio C HamanoJan 8, 2010
  8. Jeff KingJan 8, 2010
  9. Jeff KingJan 8, 2010
  10. Junio C HamanoJan 8, 2010
  11. Junio C HamanoJan 8, 2010
  12. ls-files: fix overeager pathspec optimizationJunio C Hamano, Jan 8, 2010
  13. Linus TorvaldsJan 8, 2010
  14. Junio C HamanoJan 8, 2010
  15. Junio C HamanoJan 9, 2010
  16. Linus TorvaldsJan 9, 2010
  17. Junio C HamanoJan 9, 2010
  18. Linus TorvaldsJan 9, 2010
  19. Jeff KingJan 9, 2010
  20. Junio C HamanoJan 9, 2010
  21. 1/4 t3001: test ls-files -o ignored/dirJunio C Hamano, Jan 9, 2010
  22. 2/4 read_directory_recursive(): refactor handling of a single path into a separate functionJunio C Hamano, Jan 9, 2010
  23. 3/4 read_directory(): further split treat_path()Junio C Hamano, Jan 9, 2010
  24. 4/4 ls-files: fix overeager pathspec optimizationJunio C Hamano, Jan 9, 2010
  25. Jeff KingJan 12, 2010
  26. Junio C HamanoJan 9, 2010
  27. Linus TorvaldsJan 9, 2010
  28. Junio C HamanoJan 10, 2010

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.