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

[PATCH 1/3] ls-files --others --directory: fix a bug with index entry ordering

From
Junio C Hamano <junkio@cox.net>
Date
Jan 7, 2006, 22:32 UTC
Message-ID
<7vmzi7acuu.fsf@assigned-by-dhcp.cox.net>

When both howto-index.sh and howto/make-dist.txt exist under Documentation/ directory, dir_exists() mistakenly checked it without the trailing slash to see if there was something under Documentation/howto directory, and did not realize there was, because '-' sorts earlier than '/' and cache_name_pos() finds howto-index.sh, which is not under howto/ directory. This caused --others --directory to show it which was incorrect.

Check the directory name with the trailing slash, because having an entry that has such as a prefix is what we are looking for.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 ls-files.c |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)
598164857b48f251c627b6b7ce7bf91cad21a779
diff --git a/ls-files.c b/ls-files.c
index 841c98a..cc5b32e 100644
--- a/ls-files.c
+++ b/ls-files.c
@@ -240,11 +240,9 @@ static int dir_exists(const char *dirnam
 	if (pos >= 0)
 		return 1;
 	pos = -pos-1;
-	if (pos >= active_nr)
+	if (pos >= active_nr) /* can't */
 		return 0;
-	if (strncmp(active_cache[pos]->name, dirname, len))
-		return 0;
-	return active_cache[pos]->name[len] == '/';
+	return !strncmp(active_cache[pos]->name, dirname, len);
 }
 
 /*
@@ -294,11 +292,10 @@ static void read_directory(const char *p
 					continue;
 				/* fallthrough */
 			case DT_DIR:
-				if (show_other_directories) {
-					if (!dir_exists(fullname, baselen + len))
-						break;
-				}
 				memcpy(fullname + baselen + len, "/", 2);
+				if (show_other_directories &&
+				    !dir_exists(fullname, baselen + len + 1))
+					break;
 				read_directory(fullname, fullname,
 					       baselen + len + 1);
 				continue;
-- 
1.0.7-g0263
Message 1 of 1 in “ls-files --others --directory: fix a bug with index entry ordering”
  1. 1/3 ls-files --others --directory: fix a bug with index entry orderingJunio C Hamano, Jan 7, 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.