X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=ls-files.c;h=7024cf18e1b739ed4944b89ddddaeff15d59f9ee;hb=feffaddce0cec7fd3f749d23e95579b683961002;hp=841c98a710d6fbe58f21e8ab2e9b613fb592d7f3;hpb=9518eb262980d5048ef71e4450ef2cf78d7df6b5;p=git.git diff --git a/ls-files.c b/ls-files.c index 841c98a7..7024cf18 100644 --- a/ls-files.c +++ b/ls-files.c @@ -209,7 +209,7 @@ static int excluded(const char *pathname) struct nond_on_fs { int len; - char name[0]; + char name[FLEX_ARRAY]; /* more */ }; static struct nond_on_fs **dir; @@ -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,13 +292,13 @@ 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); + len++; + if (show_other_directories && + !dir_exists(fullname, baselen + len)) + break; read_directory(fullname, fullname, - baselen + len + 1); + baselen + len); continue; case DT_REG: case DT_LNK: @@ -476,8 +474,28 @@ static void show_files(void) const char *path = ".", *base = ""; int baselen = prefix_len; - if (baselen) + if (baselen) { path = base = prefix; + if (exclude_per_dir) { + char *p, *pp = xmalloc(baselen+1); + memcpy(pp, prefix, baselen+1); + p = pp; + while (1) { + char save = *p; + *p = 0; + push_exclude_per_directory(pp, p-pp); + *p++ = save; + if (!save) + break; + p = strchr(p, '/'); + if (p) + p++; + else + p = pp + baselen; + } + free(pp); + } + } read_directory(path, base, baselen); qsort(dir, nr_dir, sizeof(struct nond_on_fs *), cmp_name); if (show_others)