@matheusbsbs / matheus-bagliano / commits / 657907e76e
Fork 0

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

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>

Junio C Hamano committed Jan 7, 2006 at 14:32 UTC 657907e76e298cac31845dadda2c71b431d9e712
1 file changed +5 -8
ls-files.c
+5 -8
@@ -240,11 +240,9 @@ static int dir_exists(const char *dirname, int len)
240 if (pos >= 0)
241 return 1;
242 pos = -pos-1;
243 - if (pos >= active_nr)
243 + if (pos >= active_nr) /* can't */
244 return 0;
245 - if (strncmp(active_cache[pos]->name, dirname, len))
246 - return 0;
247 - return active_cache[pos]->name[len] == '/';
245 + return !strncmp(active_cache[pos]->name, dirname, len);
246 }
247
248 /*
@@ -294,11 +292,10 @@ static void read_directory(const char *path, const char *base, int baselen)
292 continue;
293 /* fallthrough */
294 case DT_DIR:
297 - if (show_other_directories) {
298 - if (!dir_exists(fullname, baselen + len))
299 - break;
300 - }
295 memcpy(fullname + baselen + len, "/", 2);
296 + if (show_other_directories &&
297 + !dir_exists(fullname, baselen + len + 1))
298 + break;
299 read_directory(fullname, fullname,
300 baselen + len + 1);
301 continue;