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

Re: [PATCH] Clean up git-ls-file directory walking library interface

From
Linus Torvalds <torvalds@osdl.org>
Date
May 17, 2006, 04:06 UTC
Message-ID
<Pine.LNX.4.64.0605162100570.10823@g5.osdl.org>
In-Reply-To
<Pine.LNX.4.64.0605161944480.10823@g5.osdl.org>
On Tue, 16 May 2006, Linus Torvalds wrote:
Show 5 quoted lines
> 
> That not only allows us to turn the function push_exclude_per_directory() 
> static again, it also simplifies the library interface a lot (the caller 
> no longer needs to worry about any of the per-directory exclude files at 
> all).
Just as an example, here's all you need to basically do
	git-ls-files --others --directory
		--exclude-from="$GIT_DIR/info/exclude"
		--exclude-per-directory=.gitignore

like "git status" does (where the "--exclude-from" is conditional on whether the file exists or not).

		Linus
---
#include "cache.h"
#include "dir.h"
int main(int argc, char **argv)
{
	struct dir_struct dir;
	const char *prefix = setup_git_directory();
	const char *base, *path;
	int baselen, i;
	/* Read the index */
	read_cache();
	/* Set up the "struct dir_struct */
	memset(&dir, 0, sizeof(dir));
	dir.show_other_directories = 1;
	/* normal git porcelain exclude patterns */
	dir.exclude_per_dir = ".gitignore";
	path = git_path("info/exclude");
	if (!access(path, R_OK))
		add_excludes_from_file(&dir, path);
	/* Set up read_directory() arguments and go go go! */
	path = ".";
	base = "";
	baselen = 0;
	if (prefix) {
		path = base = prefix;
		baselen = strlen(prefix);
	}
	read_directory(&dir, path, base, baselen);
	/* And print it all out */
	if (dir.nr)
		printf("#\n# Untracked files:\n#\n");
	for (i = 0; i < dir.nr; i++)
		printf("# %s\n", dir.entries[i]->name);
	return 0;
}
Previous: Linus Torvalds
Message 4 of 4 in “libify git-ls-files directory traversal”
  1. libify git-ls-files directory traversalLinus Torvalds, May 17, 2006
  2. Linus TorvaldsMay 17, 2006
  3. Clean up git-ls-file directory walking library interfaceLinus Torvalds, May 17, 2006
  4. Linus TorvaldsMay 17, 2006

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.