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

Re: [PATCH] ls-tree: handle trailing slashes in the pathspec properly.

From
Linus Torvalds <torvalds@osdl.org>
Date
May 31, 2005, 23:48 UTC
Message-ID
<Pine.LNX.4.58.0505311636260.1876@ppc970.osdl.org>
In-Reply-To
<7v8y1vvvaa.fsf_-_@assigned-by-dhcp.cox.net>
On Tue, 31 May 2005, Junio C Hamano wrote:
> 
> I take it to mean that you took my other patch for diffcore-pathspec.

No, I did my own. Rather than add more code to handle '/' as a special case, I just removed it all, and fixed the compare logic.

> Here is a fixed ls-tree, with a couple of new tests in an
> existing test script, to catch this bug.

You seem to think that '/' at the end is a special case, and it really shouldn't be. It should just fall out as a natural special case of a zero-sized name (which is, btw, the same natural special case that the path of "" should have in &root_dir).

For some reason your ls-tree.c logic seems to think that zero-sized names means "root entry", when the _natural_ thing to do is to pass in the "base directory", and then a zero-sized name is that base.

IOW, it would make much more sense to have
	list_one(struct tree_entry_list *tree, const char *name)
	{
		const char *slash = strchr(name, '/');
		const char *next;
		int len;
		for (;;) {
			if (!slash) {
				len = strlen(name);
				next = NULL;
			} else {
				len = slash - name;
				next = slash+1;
			}
			newtree = tree;
			if (len)
				newtree = lookup(tree, name, len);
			if (!next)
				break;
			tree = newtree;
			name = next;
		}
		/* Ok, "newtree" is the last component */
		show_entry(newtree);
	}
and then call it with
	list_one(&root_entry, full_path)

and notice how the cases of an empty path "" and "xxx//yy" and "xx/" just fall out from the exact same logic - a zero-sized name is the same as the directory it is in. No special cases for slashes or empty names.

		Linus
Previous: Junio C HamanoNext: Junio C Hamano
Message 9 of 12 in “Re: [PATCH] allow pathspec to end with a slash”
  1. Linus TorvaldsMay 31, 2005
  2. Junio C HamanoMay 31, 2005
  3. 1/2 diff: consolidate test helper script pieces.Junio C Hamano, May 31, 2005
  4. 2/2 diff: Fix trailing slash handling.Junio C Hamano, May 31, 2005
  5. ls-tree: remove trailing slashes properly.Junio C Hamano, May 31, 2005
  6. Linus TorvaldsMay 31, 2005
  7. Junio C HamanoMay 31, 2005
  8. ls-tree: handle trailing slashes in the pathspec properly.Junio C Hamano, May 31, 2005
  9. Linus TorvaldsMay 31, 2005
  10. ls-tree: handle trailing slashes in the pathspec properly.Junio C Hamano, Jun 1, 2005
  11. Linus TorvaldsJun 1, 2005
  12. Junio C HamanoMay 31, 2005

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.