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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Tue, 16 May 2006, Linus Torvalds wrote:
> 
> 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;
}

-
: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]