Anonymous avatar Anonymous committed 657907e

ls-files --others --directory: fix a bug with index entry ordering

When both 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, 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 <>;

Comments (0)

Files changed (1)

 	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);
 				/* 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);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.