summaryrefslogtreecommitdiff
path: root/ls-files.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-01-07 14:32:09 -0800
committerJunio C Hamano <junkio@cox.net>2006-01-07 21:34:02 -0800
commit657907e76e298cac31845dadda2c71b431d9e712 (patch)
treec9d89aa5f8a4c8cec98ac90ef749b3249529cbd8 /ls-files.c
parent9518eb262980d5048ef71e4450ef2cf78d7df6b5 (diff)
downloadgit-657907e76e298cac31845dadda2c71b431d9e712.tar.gz
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>
Diffstat (limited to 'ls-files.c')
-rw-r--r--ls-files.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/ls-files.c b/ls-files.c
index 841c98a710..cc5b32e8ba 100644
--- a/ls-files.c
+++ b/ls-files.c
@@ -240,11 +240,9 @@ static int dir_exists(const char *dirname, int len)
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 *path, const char *base, int baselen)
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;