git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Linus Torvalds <torvalds@osdl.org>
To: Junio C Hamano <junkio@cox.net>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH] ls-tree: handle trailing slashes in the pathspec properly.
Date: Tue, 31 May 2005 16:48:42 -0700 (PDT)	[thread overview]
Message-ID: <Pine.LNX.4.58.0505311636260.1876@ppc970.osdl.org> (raw)
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

  reply	other threads:[~2005-05-31 23:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-31 15:32 [PATCH] allow pathspec to end with a slash Linus Torvalds
2005-05-31 20:08 ` Junio C Hamano
2005-05-31 21:47 ` [PATCH 1/2] diff: consolidate test helper script pieces Junio C Hamano
2005-05-31 21:48 ` [PATCH 2/2] diff: Fix trailing slash handling Junio C Hamano
2005-05-31 21:49 ` [PATCH] ls-tree: remove trailing slashes properly Junio C Hamano
2005-05-31 22:19   ` Linus Torvalds
2005-05-31 22:35     ` Junio C Hamano
2005-05-31 23:18     ` [PATCH] ls-tree: handle trailing slashes in the pathspec properly Junio C Hamano
2005-05-31 23:48       ` Linus Torvalds [this message]
2005-06-01  1:46         ` Junio C Hamano
2005-06-01  3:51           ` Linus Torvalds
2005-05-31 23:22     ` [PATCH] ls-tree: remove trailing slashes properly Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.58.0505311636260.1876@ppc970.osdl.org \
    --to=torvalds@osdl.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).