X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=ls-files.c;h=7024cf18e1b739ed4944b89ddddaeff15d59f9ee;hb=3f6726e1f112d221bd2a919e9b1b2927aeef6150;hp=cc5b32e8bac12105873ecee73a9fc9036d71b61b;hpb=657907e76e298cac31845dadda2c71b431d9e712;p=git.git diff --git a/ls-files.c b/ls-files.c index cc5b32e8..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; @@ -293,11 +293,12 @@ static void read_directory(const char *path, const char *base, int baselen) /* fallthrough */ case DT_DIR: memcpy(fullname + baselen + len, "/", 2); + len++; if (show_other_directories && - !dir_exists(fullname, baselen + len + 1)) + !dir_exists(fullname, baselen + len)) break; read_directory(fullname, fullname, - baselen + len + 1); + baselen + len); continue; case DT_REG: case DT_LNK: @@ -473,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)