{"thread":{"id":"2994","subject":"[PATCH 1/3] ls-files --others --directory: fix a bug with index entry ordering","startedAt":"2006-01-07T22:32:09Z","lastAt":"2006-01-07T22:32:09Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"14270","messageId":"7vmzi7acuu.fsf@assigned-by-dhcp.cox.net","threadId":"2994","inReplyTo":null,"subject":"[PATCH 1/3] ls-files --others --directory: fix a bug with index entry ordering","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-01-07T22:32:09Z","receivedAt":"2006-01-07T22:32:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When both howto-index.sh and howto/make-dist.txt exist under\nDocumentation/ directory, dir_exists() mistakenly checked it\nwithout the trailing slash to see if there was something under\nDocumentation/howto directory, and did not realize there was,\nbecause '-' sorts earlier than '/' and cache_name_pos() finds\nhowto-index.sh, which is not under howto/ directory.  This\ncaused --others --directory to show it which was incorrect.\n\nCheck the directory name with the trailing slash, because having\nan entry that has such as a prefix is what we are looking for.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n\n ls-files.c |   13 +++++--------\n 1 files changed, 5 insertions(+), 8 deletions(-)\n\n598164857b48f251c627b6b7ce7bf91cad21a779\ndiff --git a/ls-files.c b/ls-files.c\nindex 841c98a..cc5b32e 100644\n--- a/ls-files.c\n+++ b/ls-files.c\n@@ -240,11 +240,9 @@ static int dir_exists(const char *dirnam\n \tif (pos >= 0)\n \t\treturn 1;\n \tpos = -pos-1;\n-\tif (pos >= active_nr)\n+\tif (pos >= active_nr) /* can't */\n \t\treturn 0;\n-\tif (strncmp(active_cache[pos]->name, dirname, len))\n-\t\treturn 0;\n-\treturn active_cache[pos]->name[len] == '/';\n+\treturn !strncmp(active_cache[pos]->name, dirname, len);\n }\n \n /*\n@@ -294,11 +292,10 @@ static void read_directory(const char *p\n \t\t\t\t\tcontinue;\n \t\t\t\t/* fallthrough */\n \t\t\tcase DT_DIR:\n-\t\t\t\tif (show_other_directories) {\n-\t\t\t\t\tif (!dir_exists(fullname, baselen + len))\n-\t\t\t\t\t\tbreak;\n-\t\t\t\t}\n \t\t\t\tmemcpy(fullname + baselen + len, \"/\", 2);\n+\t\t\t\tif (show_other_directories &&\n+\t\t\t\t    !dir_exists(fullname, baselen + len + 1))\n+\t\t\t\t\tbreak;\n \t\t\t\tread_directory(fullname, fullname,\n \t\t\t\t\t       baselen + len + 1);\n \t\t\t\tcontinue;\n-- \n1.0.7-g0263\n"}]}