From: Nguyễn Thái Ngọc Duy Date: Thu, 07 Jan 2010 17:07:55 GMT Subject: [PATCH 2/3] ls-files: support -o --max-depth (more of a hack as fill_directory should support this) Message-ID: <1262884076-12293-3-git-send-email-pclouds@gmail.com> In-Reply-To: <1262884076-12293-1-git-send-email-pclouds@gmail.com> Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin-ls-files.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/builtin-ls-files.c b/builtin-ls-files.c index 2bb851a..e16638e 100644 --- a/builtin-ls-files.c +++ b/builtin-ls-files.c @@ -51,6 +51,17 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent) if (!match_pathspec(pathspec, ent->name, ent->len, len, ps_matched)) return; + if (max_depth) { + int slashes = 0; + const char *entry = ent->name + prefix_offset; + while ((entry = strchr(entry, '/')) != NULL) { + slashes++; + if (slashes >= max_depth) + return; + entry++; + } + } + fputs(tag, stdout); write_name_quoted(ent->name + offset, stdout, line_terminator); } -- 1.6.6.315.g1a406